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
[Py3] WSGI part 2 #427
[Py3] WSGI part 2 #427
Conversation
ipaserver/plugins/baseldap.py
Outdated
| delval = unicode(base64.b64encode(delval)) | ||
| raise errors.AttrValueNotFound(attr=attr, value=delval) | ||
| delval = base64.b64encode(delval).decode('ascii') | ||
| raise errors.AttrValueNotFound(attr=attr, value=delval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you indent the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea
ipaserver/plugins/baseldap.py
Outdated
| @@ -255,7 +255,8 @@ def entry_to_dict(entry, **options): | |||
| value = list(entry.raw[attr]) | |||
| for (i, v) in enumerate(value): | |||
| try: | |||
| value[i] = v.decode('utf-8') | |||
| if isinstance(v, bytes): | |||
| value[i] = v.decode('utf-8') | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entry.raw[] should always return a list of bytes. Why the if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be fixed in ipaldap
ipalib/rpc.py
Outdated
| @@ -308,7 +308,7 @@ def json_encode_binary(val, version): | |||
| encoded = encoded.decode('ascii') | |||
| return {'__base64__': encoded} | |||
| elif isinstance(val, Decimal): | |||
| return {'__base64__': base64.b64encode(str(val))} | |||
| return {'__base64__': base64.b64encode(str(val).encode('ascii'))} | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value must be text, but base64.b64encode() returns binary data, so you should also decode its result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
ipalib/rpc.py
Outdated
| @@ -308,7 +308,8 @@ def json_encode_binary(val, version): | |||
| encoded = encoded.decode('ascii') | |||
| return {'__base64__': encoded} | |||
| elif isinstance(val, Decimal): | |||
| return {'__base64__': base64.b64encode(str(val))} | |||
| return {'__base64__': base64.b64encode( | |||
| str(val).encode('ascii')).decode('ascii')} | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please get rid of this non-sense and return unicode(val)? (It is a backward compatible change.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you wish
Using unicode(bytes) call causes undesired side effect that is inserting `b` character to result. This obviously causes issues with binary base64 data https://fedorahosted.org/freeipa/ticket/4985
Do not encode attribute names https://fedorahosted.org/freeipa/ticket/4985
DNS labels are bytes so bytes must be used for comparison https://fedorahosted.org/freeipa/ticket/4985
In py3 keys() doesn't return list but iterator so it must be transformed to tuple otherwise iterator will be broken. https://fedorahosted.org/freeipa/ticket/4985
ToASCII() returns bytes, it must be decoded to unicode https://fedorahosted.org/freeipa/ticket/4985
The encode method of LDAPClient didn't return DNSName as bytes but string in py3. In py2 it returns non-unicode string so it can be encoded safely by ascii as to_text() method returns only ascii characters. https://fedorahosted.org/freeipa/ticket/4985
for Decimal only from client to server direction uses __base64__
notation. Server replies with pure string for Decimal data, and also
server is able to parse string and create decimal values where needed.
without this we need ugly py3 code:
- return {'__base64__': base64.b64encode(str(val))}
+ return {'__base64__': base64.b64encode(
+ str(val).encode('ascii')).decode('ascii')}
https://fedorahosted.org/freeipa/ticket/4985
with this PR: