Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py3fication of babelplugin #187

Closed
sqlalchemy-bot opened this issue Mar 14, 2012 · 3 comments
Closed

py3fication of babelplugin #187

sqlalchemy-bot opened this issue Mar 14, 2012 · 3 comments
Labels
bug Something isn't working low priority runtime

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Anonymous

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.


Attachments: makobabel.patch

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

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.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

adad0a0

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority runtime
Projects
None yet
Development

No branches or pull requests

1 participant