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

Allow converting newbytes to python2 str #142

Open
adiroiban opened this issue Apr 26, 2015 · 2 comments
Open

Allow converting newbytes to python2 str #142

adiroiban opened this issue Apr 26, 2015 · 2 comments

Comments

@adiroiban
Copy link

I have a problem with using grp.getgrnam on Py2.7
I found out that it needs str and does not work with bytes.

Not sure where I should report this but maybe the report could help others who bump on this issue.

(Pdb) name
'str2844-cp\u021b'
(Pdb) type(name)
<class 'future.types.newstr.newstr'>

name_encoded = name.encode('utf-8')
(Pdb) type(name_encoded)
<class 'future.types.newbytes.newbytes'>
(Pdb) name_encoded
b'str2844-cp\xc8\x9b'

(Pdb) grp.getgrnam(name_encoded)
*** KeyError: "getgrnam(): name not found: b'str2844-cp\xc8\x9b'"
(Pdb) grp.getgrnam('str2844-cp\xc8\x9b')
grp.struct_group(gr_name='str2844-cp\xc8\x9b', gr_passwd='x', gr_gid=2948, gr_mem=[])

As I workaround I went for

import codecs
name_encoded = codecs.encode(name, 'utf-8')

Thanks!

@QuLogic
Copy link
Contributor

QuLogic commented Apr 26, 2015

I think the workaround should be:

from future.utils import native_str
grp.getgrname(native_str('str2844-cp\u021b'))

@adiroiban
Copy link
Author

Thanks for your comment. Please note that I need native_str from name variable / backward ported Unicode.... I don't think that native_str will help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants