mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 02:44:53 -04:00
Python 3: Convert some unicode/bytes uses (#3569)
This commit is contained in:
parent
c4842e16cb
commit
da7785147d
17 changed files with 122 additions and 67 deletions
|
@ -18,6 +18,7 @@ import hashlib
|
|||
import hmac
|
||||
import logging
|
||||
|
||||
from six import text_type
|
||||
from six.moves import http_client
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -131,7 +132,10 @@ class UserRegisterServlet(ClientV1RestServlet):
|
|||
400, "username must be specified", errcode=Codes.BAD_JSON,
|
||||
)
|
||||
else:
|
||||
if (not isinstance(body['username'], str) or len(body['username']) > 512):
|
||||
if (
|
||||
not isinstance(body['username'], text_type)
|
||||
or len(body['username']) > 512
|
||||
):
|
||||
raise SynapseError(400, "Invalid username")
|
||||
|
||||
username = body["username"].encode("utf-8")
|
||||
|
@ -143,7 +147,10 @@ class UserRegisterServlet(ClientV1RestServlet):
|
|||
400, "password must be specified", errcode=Codes.BAD_JSON,
|
||||
)
|
||||
else:
|
||||
if (not isinstance(body['password'], str) or len(body['password']) > 512):
|
||||
if (
|
||||
not isinstance(body['password'], text_type)
|
||||
or len(body['password']) > 512
|
||||
):
|
||||
raise SynapseError(400, "Invalid password")
|
||||
|
||||
password = body["password"].encode("utf-8")
|
||||
|
@ -166,17 +173,18 @@ class UserRegisterServlet(ClientV1RestServlet):
|
|||
want_mac.update(b"admin" if admin else b"notadmin")
|
||||
want_mac = want_mac.hexdigest()
|
||||
|
||||
if not hmac.compare_digest(want_mac, got_mac):
|
||||
raise SynapseError(
|
||||
403, "HMAC incorrect",
|
||||
)
|
||||
if not hmac.compare_digest(want_mac, got_mac.encode('ascii')):
|
||||
raise SynapseError(403, "HMAC incorrect")
|
||||
|
||||
# Reuse the parts of RegisterRestServlet to reduce code duplication
|
||||
from synapse.rest.client.v2_alpha.register import RegisterRestServlet
|
||||
|
||||
register = RegisterRestServlet(self.hs)
|
||||
|
||||
(user_id, _) = yield register.registration_handler.register(
|
||||
localpart=username.lower(), password=password, admin=bool(admin),
|
||||
localpart=body['username'].lower(),
|
||||
password=body["password"],
|
||||
admin=bool(admin),
|
||||
generate_token=False,
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue