summaryrefslogtreecommitdiff
path: root/dev-python/genshi/files/genshi-0.7-issue602.patch
blob: d7f0b77fa9212908d3148ecfa0d5d42857a1cf81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
From 1acbd00b4961164edc8a185458ba4a433bedbceb Mon Sep 17 00:00:00 2001
From: SVN-Git Migration <python-modules-team@lists.alioth.debian.org>
Date: Thu, 8 Oct 2015 09:13:46 -0700
Subject: Fix Python 3.5 compatibility issues.

Origin: http://genshi.edgewall.org/attachment/ticket/602/t602.diff
Bug: http://genshi.edgewall.org/ticket/602
Forwarded: not-needed

Patch-Name: issue602.patch
---
 genshi/filters/i18n.py        |  6 ++++--
 genshi/template/astutil.py    | 14 +++++++++++---
 genshi/template/directives.py | 20 ++++++++++++++------
 genshi/template/eval.py       |  5 +++++
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py
index b724956..dfb52b8 100644
--- a/genshi/filters/i18n.py
+++ b/genshi/filters/i18n.py
@@ -1187,8 +1187,10 @@ def extract_from_code(code, gettext_functions):
                 elif arg:
                     strings.append(None)
             [_add(arg) for arg in node.args]
-            _add(node.starargs)
-            _add(node.kwargs)
+            if hasattr(node, 'starargs'):
+                _add(node.starargs)
+            if hasattr(node, 'kwargs'):
+                _add(node.kwargs)
             if len(strings) == 1:
                 strings = strings[0]
             else:
diff --git a/genshi/template/astutil.py b/genshi/template/astutil.py
index a4c21c8..b24f728 100644
--- a/genshi/template/astutil.py
+++ b/genshi/template/astutil.py
@@ -135,6 +135,10 @@ class ASTCodeGenerator(object):
         def visit_arg(self, node):
             self._write(node.arg)
 
+    def visit_Starred(self, node):
+        self._write('*')
+        self.visit(node.value)
+
     # FunctionDef(identifier name, arguments args,
     #                           stmt* body, expr* decorator_list)
     def visit_FunctionDef(self, node):
@@ -648,9 +652,13 @@ class ASTCodeGenerator(object):
             if not first:
                 self._write(', ')
             first = False
-            # keyword = (identifier arg, expr value)
-            self._write(keyword.arg)
-            self._write('=')
+            if not keyword.arg:
+                # Python 3.5+ star-star args
+                self._write('**')
+            else:
+                # keyword = (identifier arg, expr value)
+                self._write(keyword.arg)
+                self._write('=')
             self.visit(keyword.value)
         if getattr(node, 'starargs', None):
             if not first:
diff --git a/genshi/template/directives.py b/genshi/template/directives.py
index 7301c2d..1f70ef6 100644
--- a/genshi/template/directives.py
+++ b/genshi/template/directives.py
@@ -266,13 +266,21 @@ class DefDirective(Directive):
         if isinstance(ast, _ast.Call):
             self.name = ast.func.id
             for arg in ast.args:
-                # only names
-                self.args.append(arg.id)
+                if hasattr(_ast, 'Starred') and isinstance(arg, _ast.Starred):
+                    # Python 3.5+
+                    self.star_args = arg.value.id
+                else:
+                    # only names
+                    self.args.append(arg.id)
             for kwd in ast.keywords:
-                self.args.append(kwd.arg)
-                exp = Expression(kwd.value, template.filepath,
-                                 lineno, lookup=template.lookup)
-                self.defaults[kwd.arg] = exp
+                if kwd.arg is None:
+                    # Python 3.5+
+                    self.dstar_args = kwd.value.id
+                else:
+                    self.args.append(kwd.arg)
+                    exp = Expression(kwd.value, template.filepath,
+                                     lineno, lookup=template.lookup)
+                    self.defaults[kwd.arg] = exp
             if getattr(ast, 'starargs', None):
                 self.star_args = ast.starargs.id
             if getattr(ast, 'kwargs', None):
diff --git a/genshi/template/eval.py b/genshi/template/eval.py
index 89aec49..c00cfcb 100644
--- a/genshi/template/eval.py
+++ b/genshi/template/eval.py
@@ -593,6 +593,11 @@ class TemplateASTTransformer(ASTTransformer):
         finally:
             self.locals.pop()
 
+    # Only used in Python 3.5+
+    def visit_Starred(self, node):
+        node.value = self.visit(node.value)
+        return node
+
     def visit_Name(self, node):
         # If the name refers to a local inside a lambda, list comprehension, or
         # generator expression, leave it alone