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
Python 3: port tests in cookie-store #24531
Conversation
@Hexcles : I actually have some UnicodeEncodeErrors while running in Python 3 (happening before and after code updates with review comments ). For example, running change_eventhandler_for_http_cookie_and_set_cookie_headers.tentative.https.window.html throws
and
I couldn't see anything obvious at the moment. Any suggestions? |
That's due to the change in behaviours of You'd have to do something like: if PY3:
parse_qs(..., encoding='iso-8859-1') (sigh) |
The complaints have changed to : I will try to dig a bit more on this. Meanwhile, if you see anything obvious, let me know. Thank you! |
Maybe paste the full traceback and try to print out the problematic string. |
And more here -
|
@Hexcles : Looking into python3.8/urllib/parse.py, I've updated code and decode Do let me know if I have missed anything. Thank you! |
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.
lgtm, but maybe some refactoring to pull the if PY3
logic out.
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.
Thanks for the detailed investigation. Python 3 really does not like URLs in bytes, and uses ASCII as the implicit encoding unconditionally to coerce the results: https://github.com/python/cpython/blob/b4cd77de05e5bbaa6a4be90f710b787e0790c36f/Lib/urllib/parse.py#L90-L97
@ziransun could you try keeping request.url
as text strings (use isomorphic_decode
on L45 and remove the PY3-only decode
on L49)?
In this case, in python 2 we are passing a unicode type string to quote() function. I guess it should be string type? A Python 2 run with this change threw KeyError, e.g.
|
@Hexcles Any further comments on this? |
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.
Sorry for the delay. This one slipped through...
for set_cookie in args.get('set-cookie', []): | ||
if '=' in set_cookie.split(';', 1)[0]: | ||
name, rest = set_cookie.split('=', 1) |
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.
Missing prefixes here?
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.
Prefixes were deliberately left out here. I think set_cookie
here is a native string here. Is it okay?
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.
Ahh right, because it's from parse_qs
...
Unfortunately, this will be problematic if/when we start to enforce prefixes for all string literals. I think we'd need to add some logic to both quote_str
and parse_qs_str
to always return binary strings (add isomorphic_encode
in the PY3 branch).
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.
Thank @Hexcles! Code updated. Please review.
body = '\r\n'.join(body) | ||
headers.append(('content-length', str(len(body)))) | ||
headers.append((b'content-length', len(body))) | ||
return 200, headers, body |
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.
Looks like body
is a native string.
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.
Yes.
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.
Code updated.
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.
LGTM. Thanks for bearing with me through this!
No description provided.