Issues

Issue #187 resolved

py3fication of babelplugin

guest
created an issue

File ".../Mako-0.6.2-py3.2.egg/mako/ext/babelplugin.py", line 115, in extract_nodes code = StringIO(code) !TypeError: initial_value must be str or None, not bytes

attached patch removes this problem.

Comments (2)

  1. Mike Bayer repo owner

    the patch as is breaks tests:

    ERROR: test_extract (test.test_babelplugin.ExtractMakoTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/classic/dev/mako/test/init.py", line 91, in maybe return fn(*args, kw) File "/Users/classic/dev/mako/test/test_babelplugin.py", line 20, in test_extract ['TRANSLATOR:'], {})) File "/Users/classic/dev/mako/mako/ext/babelplugin.py", line 31, in extract keywords, comment_tags, options): File "/Users/classic/dev/mako/mako/ext/babelplugin.py", line 116, in extract_nodes in extract_python(code, keywords, comment_tags, options): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/babel/messages/extract.py", line 348, in extract_python encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1') File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/babel/util.py", line 73, in parse_encoding has_bom = line1.startswith(codecs.BOM_UTF8) UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)

    ----------------------------------------------------------------------

    I'd like to try putting a conditional, "if util.py3k:" above it, however the tests don't run at all under py3k:

    ERROR: test_extract (test.test_babelplugin.ExtractMakoTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/classic/dev/mako3k/mako/pyparser.py", line 49, in parse return _ast_util.parse(code, '<unknown>', mode) File "/Users/classic/dev/mako3k/mako/_ast_util.py", line 84, in parse return compile(expr, filename, mode, PyCF_ONLY_AST) File "<unknown>", line 1 _(u'foo') ^ SyntaxError: invalid syntax

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/Users/classic/dev/mako3k/test/init.py", line 91, in maybe return fn(*args, kw) File "/Users/classic/dev/mako3k/test/test_babelplugin.py", line 20, in test_extract ['TRANSLATOR:'], {})) File "/Users/classic/dev/mako3k/mako/ext/babelplugin.py", line 29, in extract input_encoding=encoding).parse() File "/Users/classic/dev/mako3k/mako/lexer.py", line 210, in parse if self.match_expression(): File "/Users/classic/dev/mako3k/mako/lexer.py", line 370, in match_expression lineno=line, pos=pos) File "/Users/classic/dev/mako3k/mako/lexer.py", line 126, in append_node node = nodecls(*args, kwargs) File "/Users/classic/dev/mako3k/mako/parsetree.py", line 172, in init self.code = ast.PythonCode(text, self.exception_kwargs) File "/Users/classic/dev/mako3k/mako/ast.py", line 34, in init expr = pyparser.parse(code.lstrip(), "exec", exception_kwargs) File "/Users/classic/dev/mako3k/mako/pyparser.py", line 60, in parse ), exception_kwargs) mako.exceptions.SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 1) ("_(u'foo')") at line: 83 char: 1

    ----------------------------------------------------------------------

    so need to figure out what should be happening here.

  2. Log in to comment