gnu: Add python-genshi.
[jackhill/guix/guix.git] / gnu / packages / patches / python-genshi-fix-tests-on-python-3.5.patch
1 From ce796ad4bae5c47011876778674ad036357febdf Mon Sep 17 00:00:00 2001
2 From: Adriano Peluso <catonano@gmail.com>
3 Date: Wed, 5 Apr 2017 15:10:06 +0200
4 Subject: [PATCH 1/2] fixing the tests on python35
5
6 ---
7 genshi/filters/i18n.py | 6 ++++--
8 genshi/template/astutil.py | 14 +++++++++++---
9 genshi/template/directives.py | 20 ++++++++++++++------
10 genshi/template/eval.py | 5 +++++
11 4 files changed, 34 insertions(+), 11 deletions(-)
12
13 diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py
14 index 526fda4..5387fcf 100644
15 --- a/genshi/filters/i18n.py
16 +++ b/genshi/filters/i18n.py
17 @@ -1194,8 +1194,10 @@ def extract_from_code(code, gettext_functions):
18 elif arg:
19 strings.append(None)
20 [_add(arg) for arg in node.args]
21 - _add(node.starargs)
22 - _add(node.kwargs)
23 + if hasattr(node, 'starargs'):
24 + _add(node.starargs)
25 + if hasattr(node, 'kwargs'):
26 + _add(node.kwargs)
27 if len(strings) == 1:
28 strings = strings[0]
29 else:
30 diff --git a/genshi/template/astutil.py b/genshi/template/astutil.py
31 index f4e1edd..e561846 100644
32 --- a/genshi/template/astutil.py
33 +++ b/genshi/template/astutil.py
34 @@ -151,6 +151,10 @@ class ASTCodeGenerator(object):
35 def visit_arg(self, node):
36 self._write(node.arg)
37
38 + def visit_Starred(self, node):
39 + self._write('*')
40 + self.visit(node.value)
41 +
42 # FunctionDef(identifier name, arguments args,
43 # stmt* body, expr* decorator_list)
44 def visit_FunctionDef(self, node):
45 @@ -664,9 +668,13 @@ class ASTCodeGenerator(object):
46 if not first:
47 self._write(', ')
48 first = False
49 - # keyword = (identifier arg, expr value)
50 - self._write(keyword.arg)
51 - self._write('=')
52 + if not keyword.arg:
53 + # Python 3.5+ star-star args
54 + self._write('**')
55 + else:
56 + # keyword = (identifier arg, expr value)
57 + self._write(keyword.arg)
58 + self._write('=')
59 self.visit(keyword.value)
60 if getattr(node, 'starargs', None):
61 if not first:
62 diff --git a/genshi/template/directives.py b/genshi/template/directives.py
63 index 7301c2d..6fd0f28 100644
64 --- a/genshi/template/directives.py
65 +++ b/genshi/template/directives.py
66 @@ -266,13 +266,21 @@ class DefDirective(Directive):
67 if isinstance(ast, _ast.Call):
68 self.name = ast.func.id
69 for arg in ast.args:
70 - # only names
71 - self.args.append(arg.id)
72 + if isinstance(arg, _ast.Starred):
73 + # Python 3.5+
74 + self.star_args = arg.value.id
75 + else:
76 + # only names
77 + self.args.append(arg.id)
78 for kwd in ast.keywords:
79 - self.args.append(kwd.arg)
80 - exp = Expression(kwd.value, template.filepath,
81 - lineno, lookup=template.lookup)
82 - self.defaults[kwd.arg] = exp
83 + if kwd.arg is None:
84 + # Python 3.5+
85 + self.dstar_args = kwd.value.id
86 + else:
87 + self.args.append(kwd.arg)
88 + exp = Expression(kwd.value, template.filepath,
89 + lineno, lookup=template.lookup)
90 + self.defaults[kwd.arg] = exp
91 if getattr(ast, 'starargs', None):
92 self.star_args = ast.starargs.id
93 if getattr(ast, 'kwargs', None):
94 diff --git a/genshi/template/eval.py b/genshi/template/eval.py
95 index d378419..81644a7 100644
96 --- a/genshi/template/eval.py
97 +++ b/genshi/template/eval.py
98 @@ -600,6 +600,11 @@ class TemplateASTTransformer(ASTTransformer):
99 finally:
100 self.locals.pop()
101
102 + # Only used in Python 3.5+
103 + def visit_Starred(self, node):
104 + node.value = self.visit(node.value)
105 + return node
106 +
107 def visit_Name(self, node):
108 # If the name refers to a local inside a lambda, list comprehension, or
109 # generator expression, leave it alone
110 --
111 2.12.0
112