diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-11-11 14:38:56 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-11-11 14:38:56 -0500 |
commit | 1eb56ef02a7fa825be99ddfb95f217a07dab1cdf (patch) | |
tree | bf0857b7f42dec7db03910799eed7e5dda5e7c2b /mako/pyparser.py | |
parent | 4ab9664a515c265238d420b0373f7225fe2e53c7 (diff) | |
download | external_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.tar.gz external_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.tar.bz2 external_python_mako-1eb56ef02a7fa825be99ddfb95f217a07dab1cdf.zip |
- first pass at running a py3k compatible base in py2k as well.
having some weird unicode issues I can't debug; the meaning of
str.encode() seems to be changing globally somehow
Diffstat (limited to 'mako/pyparser.py')
-rw-r--r-- | mako/pyparser.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/mako/pyparser.py b/mako/pyparser.py index 984c0d2..7dde1f9 100644 --- a/mako/pyparser.py +++ b/mako/pyparser.py @@ -10,11 +10,11 @@ Parsing to AST is done via _ast on Python > 2.5, otherwise the compiler module is used. """ -from StringIO import StringIO -from mako import exceptions, util +from mako import exceptions, util, compat +from mako.compat import StringIO import operator -if util.py3k: +if compat.py3k: # words that cannot be assigned to (notably # smaller than the total keys in __builtins__) reserved = set(['True', 'False', 'None', 'print']) @@ -33,7 +33,7 @@ else: try: import _ast util.restore__ast(_ast) - import _ast_util + from . import _ast_util except ImportError: _ast = None from compiler import parse as compiler_parse @@ -48,10 +48,10 @@ def parse(code, mode='exec', **exception_kwargs): if _ast: return _ast_util.parse(code, '<unknown>', mode) else: - if isinstance(code, unicode): + if isinstance(code, compat.text_types): code = code.encode('ascii', 'backslashreplace') return compiler_parse(code, mode) - except Exception, e: + except Exception as e: raise exceptions.SyntaxException( "(%s) %s (%r)" % ( e.__class__.__name__, @@ -92,7 +92,7 @@ if _ast: self.visit(n) self.in_assign_targets = in_a - if util.py3k: + if compat.py3k: # ExceptHandler is in Python 2, but this block only works in # Python 3 (and is required there) @@ -544,7 +544,7 @@ else: class walker(visitor.ASTVisitor): def dispatch(self, node, *args): - print 'Node:', str(node) + print('Node:', str(node)) # print "dir:", dir(node) |