Skip to content

Commit ffdbedf

Browse files
committed
Merge branch 'master' into stable/0.7.x
2 parents 0abf0bf + b437968 commit ffdbedf

7 files changed

Lines changed: 39 additions & 13 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ matrix:
99
- { python: "3.5" }
1010
- { python: "3.6" }
1111
- { python: "3.7", dist: xenial, sudo: true } # Python 3.7+ requires Xenial
12+
- { python: "3.8-dev", dist: xenial, sudo: true }
1213
- { python: "pypy" }
1314
- { python: "pypy3" }
1415
allow_failures:

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 0.7.2
2+
https://github.com/edgewall/genshi/releases/tag/0.7.2
3+
(Apr 27 2019, from branches/stable/0.7.x)
4+
5+
* Add support for Python 3.8.
6+
7+
18
Version 0.7.1
29
https://github.com/edgewall/genshi/releases/tag/0.7.1
310
(Sep 1 2018, from branches/stable/0.7.x)

genshi/compat.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
"""Various Python version compatibility classes and functions."""
1515

16+
import _ast
1617
import sys
1718
from types import CodeType
1819

@@ -96,6 +97,18 @@ def build_code_chunk(code, filename, name, lineno):
9697
code.co_varnames, filename, name, lineno,
9798
code.co_lnotab, (), ())
9899

100+
101+
# In Python 3.8, Str and Ellipsis was replaced by Constant
102+
103+
try:
104+
_ast_Ellipsis = _ast.Ellipsis
105+
_ast_Str = _ast.Str
106+
_ast_Str_value = lambda obj: obj.s
107+
except AttributeError:
108+
_ast_Ellipsis = _ast_Str = _ast.Constant
109+
_ast_Str_value = lambda obj: obj.value
110+
111+
99112
# Compatibility fallback implementations for Python < 2.6
100113

101114
try:

genshi/filters/i18n.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from genshi.template.base import DirectiveFactory, EXPR, SUB, _apply_directives
3434
from genshi.template.directives import Directive, StripDirective
3535
from genshi.template.markup import MarkupTemplate, EXEC
36-
from genshi.compat import IS_PYTHON2
36+
from genshi.compat import IS_PYTHON2, _ast_Str, _ast_Str_value
3737

3838
__all__ = ['Translator', 'extract']
3939
__docformat__ = 'restructuredtext en'
@@ -1187,10 +1187,11 @@ def _walk(node):
11871187
and node.func.id in gettext_functions:
11881188
strings = []
11891189
def _add(arg):
1190-
if isinstance(arg, _ast.Str) and isinstance(arg.s, unicode):
1191-
strings.append(arg.s)
1192-
elif isinstance(arg, _ast.Str):
1193-
strings.append(unicode(arg.s, 'utf-8'))
1190+
if isinstance(arg, _ast_Str) \
1191+
and isinstance(_ast_Str_value(arg), unicode):
1192+
strings.append(_ast_Str_value(arg))
1193+
elif isinstance(arg, _ast_Str):
1194+
strings.append(unicode(_ast_Str_value(arg), 'utf-8'))
11941195
elif arg:
11951196
strings.append(None)
11961197
[_add(arg) for arg in node.args]

genshi/template/astutil.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def parse(source, mode):
2222
return compile(source, '', mode, _ast.PyCF_ONLY_AST)
2323

24-
from genshi.compat import IS_PYTHON2, isstring
24+
from genshi.compat import IS_PYTHON2, isstring, _ast_Ellipsis
2525

2626
__docformat__ = 'restructuredtext en'
2727

@@ -705,6 +705,10 @@ def visit_Num(self, node):
705705
def visit_Str(self, node):
706706
self._write(repr(node.s))
707707

708+
# Constant(object value)
709+
def visit_Constant(self, node):
710+
self._write(repr(node.value))
711+
708712
if not IS_PYTHON2:
709713
# Bytes(bytes s)
710714
def visit_Bytes(self, node):
@@ -721,7 +725,7 @@ def visit_Subscript(self, node):
721725
self.visit(node.value)
722726
self._write('[')
723727
def _process_slice(node):
724-
if isinstance(node, _ast.Ellipsis):
728+
if isinstance(node, _ast_Ellipsis):
725729
self._write('...')
726730
elif isinstance(node, _ast.Slice):
727731
if getattr(node, 'lower', 'None'):

genshi/template/eval.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from genshi.util import flatten
2626

2727
from genshi.compat import get_code_params, build_code_chunk, isstring, \
28-
IS_PYTHON2
28+
IS_PYTHON2, _ast_Str
2929

3030
__all__ = ['Code', 'Expression', 'Suite', 'LenientLookup', 'StrictLookup',
3131
'Undefined', 'UndefinedError']
@@ -531,7 +531,7 @@ def visit_Str(self, node):
531531
try: # If the string is ASCII, return a `str` object
532532
node.s.decode('ascii')
533533
except ValueError: # Otherwise return a `unicode` object
534-
return _new(_ast.Str, node.s.decode('utf-8'))
534+
return _new(_ast_Str, node.s.decode('utf-8'))
535535
return node
536536

537537
def visit_ClassDef(self, node):
@@ -556,7 +556,7 @@ def visit_ImportFrom(self, node):
556556
node = _new(_ast.Expr, _new(_ast.Call,
557557
_new(_ast.Name, '_star_import_patch'), [
558558
_new(_ast.Name, '__data__'),
559-
_new(_ast.Str, node.module)
559+
_new(_ast_Str, node.module)
560560
], (), ()))
561561
return node
562562
if len(self.locals) > 1:
@@ -613,7 +613,7 @@ def visit_Name(self, node):
613613
# Otherwise, translate the name ref into a context lookup
614614
name = _new(_ast.Name, '_lookup_name', _ast.Load())
615615
namearg = _new(_ast.Name, '__data__', _ast.Load())
616-
strarg = _new(_ast.Str, node.id)
616+
strarg = _new(_ast_Str, node.id)
617617
node = _new(_ast.Call, name, [namearg, strarg], [])
618618
elif isinstance(node.ctx, _ast.Store):
619619
if len(self.locals) > 1:
@@ -632,7 +632,7 @@ def visit_Attribute(self, node):
632632
return ASTTransformer.visit_Attribute(self, node)
633633

634634
func = _new(_ast.Name, '_lookup_attr', _ast.Load())
635-
args = [self.visit(node.value), _new(_ast.Str, node.attr)]
635+
args = [self.visit(node.value), _new(_ast_Str, node.attr)]
636636
return _new(_ast.Call, func, args, [])
637637

638638
def visit_Subscript(self, node):

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py25,py26,py27,py32,py33,py34,pypy
2+
envlist = py25,py26,py27,py32,py33,py34,py35,py36,py37,py38,pypy
33
[testenv]
44
deps=
55
setenv=

0 commit comments

Comments
 (0)