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

Explodes on python 3 #12

Open
fake-name opened this issue Jul 20, 2017 · 2 comments
Open

Explodes on python 3 #12

fake-name opened this issue Jul 20, 2017 · 2 comments

Comments

@fake-name
Copy link

fake-name commented Jul 20, 2017

durr@rwpscrape:/media/Storage/Scripts/crabbit/cheaders⟫ autopxd amqp.h
Traceback (most recent call last):
  File "/usr/local/bin/autopxd", line 11, in <module>
    load_entry_point('autopxd==1.1.2', 'console_scripts', 'autopxd')()
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/autopxd/__init__.py", line 358, in cli
    outfile.write(translate(infile.read(), infile.name))
  File "/usr/local/lib/python3.5/dist-packages/autopxd/__init__.py", line 348, in translate
    p.visit(parse(code, extra_cpp_args=extra_cpp_args, whitelist=whitelist))
  File "/usr/local/lib/python3.5/dist-packages/autopxd/__init__.py", line 323, in parse
    preprocessed = preprocess(code, extra_cpp_args=extra_cpp_args)
  File "/usr/local/lib/python3.5/dist-packages/autopxd/__init__.py", line 314, in preprocess
    result.append(proc.communicate(input=code.encode('utf-8'))[0])
AttributeError: 'bytes' object has no attribute 'encode'

Basically the normal python2 encoding things.

Basically, it's the issue fixed by #3

@fake-name
Copy link
Author

As an alternative to that PR, you can fix it easily by opening the files in ASCII mode:

@click.command()
@click.argument('infile', type=click.File('r'), default=sys.stdin)
@click.argument('outfile', type=click.File('w'), default=sys.stdout)
def cli(infile, outfile):
    outfile.write(translate(infile.read(), infile.name))

instead of


@click.command()
@click.argument('infile', type=click.File('rb'), default=sys.stdin)
@click.argument('outfile', type=click.File('wb'), default=sys.stdout)
def cli(infile, outfile):
    outfile.write(translate(infile.read(), infile.name))

@tarruda
Copy link
Owner

tarruda commented Jul 21, 2017

Hi

I haven't merged #3 yet because it doesn't pass 3.4 test. Perhaps you want to send another PR that fixes the problem for you?

anthrotype added a commit to anthrotype/python-autopxd that referenced this issue Mar 24, 2018
python-autopxd already requires six, but the new `ensure_binary`
function is only in the git repo and hasn't been released to PyPI yet,
so I temporarily copied it here.

The source comes from:
benjaminp/six#204

It's a trivial function (every py2.py3 project has its own way to do
the same thing).

Fixes tarruda#12
Supersedes tarruda#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants