-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Port handlers/ to Python 3 #3803
Changes from 3 commits
5a06ec6
479dd91
8a0770a
c048523
bad483a
78fc477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ media_store/ | |
build/ | ||
venv/ | ||
venv*/ | ||
*venv/ | ||
|
||
localhost-800*/ | ||
static/client/register/register_config.js | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
storage/ is now ported to Python 3. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -895,22 +895,24 @@ def validate_hash(self, password, stored_hash): | |
|
||
Args: | ||
password (unicode): Password to hash. | ||
stored_hash (unicode): Expected hash value. | ||
stored_hash (bytes): Expected hash value. | ||
|
||
Returns: | ||
Deferred(bool): Whether self.hash(password) == stored_hash. | ||
""" | ||
|
||
def _do_validate_hash(): | ||
# Normalise the Unicode in the password | ||
pw = unicodedata.normalize("NFKC", password) | ||
|
||
return bcrypt.checkpw( | ||
pw.encode('utf8') + self.hs.config.password_pepper.encode("utf8"), | ||
stored_hash.encode('utf8') | ||
stored_hash | ||
) | ||
|
||
if stored_hash: | ||
if not isinstance(stored_hash, bytes): | ||
stored_hash = stored_hash.encode('ascii') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume changing from using 'utf8' to 'ascii' is fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hashes are ASCII hex, so yes. |
||
|
||
return make_deferred_yieldable( | ||
threads.deferToThreadPool( | ||
self.hs.get_reactor(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,7 +330,8 @@ def _upload_one_time_keys_for_user(self, user_id, device_id, time_now, | |
(algorithm, key_id, ex_json, key) | ||
) | ||
else: | ||
new_keys.append((algorithm, key_id, encode_canonical_json(key))) | ||
new_keys.append(( | ||
algorithm, key_id, encode_canonical_json(key).decode('ascii'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit picky, but this is quite unreadable to me at the end, can you stick the trailing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we save that for running black on things? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, so long as we do do it |
||
|
||
yield self.store.add_e2e_one_time_keys( | ||
user_id, device_id, time_now, new_keys | ||
|
@@ -358,7 +359,7 @@ def _exception_to_failure(e): | |
# Note that some Exceptions (notably twisted's ResponseFailed etc) don't | ||
# give a string for e.message, which json then fails to serialize. | ||
return { | ||
"status": 503, "message": str(e.message), | ||
"status": 503, "message": str(e.args[0]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't exceptions have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not on python 3, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just do |
||
} | ||
|
||
|
||
|
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.
handlers/
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.
whoops