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

AttributeError in 'decode' function with python3 #2706

Closed
Idrek opened this issue Apr 5, 2014 · 1 comment
Closed

AttributeError in 'decode' function with python3 #2706

Idrek opened this issue Apr 5, 2014 · 1 comment

Comments

@Idrek
Copy link

@Idrek Idrek commented Apr 5, 2014

I've found following error trying to execute the snippets from the docs (Python3.4 in Linux):

AttributeError: 'str' object has no attribute 'decode'

in uppercase_escape() function of the utils.py module.

Looking for a solution I found this post:

http://stackoverflow.com/questions/9327993/python3-unicode-escape-doesnt-work-with-non-ascii-bytes/12888081#12888081

So I changed the original function to:

def uppercase_escape(s):
    try: 
        return re.sub(
            r'\\U[0-9a-fA-F]{8}',
            lambda m: m.group(0).decode('unicode-escape'), s)
    except AttributeError as e:
        import codecs
        return re.sub(
            r'\\U[0-9a-fA-F]{8}',
            lambda m: codecs.getdecoder('unicode_escape')(m.group(0))[0], s)

I'm not proficient in Unicode so I don't know if this workaround is correct but now in my test it doesn't break.

@jaimeMF
Copy link
Collaborator

@jaimeMF jaimeMF commented Apr 5, 2014

This should be fixed since version 2014.04.04.7 (see #2695 and 676eb3f).
Thanks for the report, for future reports please post the command you are using and the output you get when adding the --verbose option, otherwise reproducing the problem is really hard.

@jaimeMF jaimeMF closed this Apr 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.