mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-06 11:14:09 -04:00
Replace all remaining six usage with native Python 3 equivalents (#7704)
This commit is contained in:
parent
98c4e35e3c
commit
a3f11567d9
73 changed files with 111 additions and 237 deletions
|
@ -16,9 +16,7 @@ import hashlib
|
|||
import hmac
|
||||
import logging
|
||||
import re
|
||||
|
||||
from six import text_type
|
||||
from six.moves import http_client
|
||||
from http import HTTPStatus
|
||||
|
||||
from synapse.api.constants import UserTypes
|
||||
from synapse.api.errors import Codes, NotFoundError, SynapseError
|
||||
|
@ -215,10 +213,7 @@ class UserRestServletV2(RestServlet):
|
|||
await self.store.set_server_admin(target_user, set_admin_to)
|
||||
|
||||
if "password" in body:
|
||||
if (
|
||||
not isinstance(body["password"], text_type)
|
||||
or len(body["password"]) > 512
|
||||
):
|
||||
if not isinstance(body["password"], str) or len(body["password"]) > 512:
|
||||
raise SynapseError(400, "Invalid password")
|
||||
else:
|
||||
new_password = body["password"]
|
||||
|
@ -252,7 +247,7 @@ class UserRestServletV2(RestServlet):
|
|||
password = body.get("password")
|
||||
password_hash = None
|
||||
if password is not None:
|
||||
if not isinstance(password, text_type) or len(password) > 512:
|
||||
if not isinstance(password, str) or len(password) > 512:
|
||||
raise SynapseError(400, "Invalid password")
|
||||
password_hash = await self.auth_handler.hash(password)
|
||||
|
||||
|
@ -370,10 +365,7 @@ class UserRegisterServlet(RestServlet):
|
|||
400, "username must be specified", errcode=Codes.BAD_JSON
|
||||
)
|
||||
else:
|
||||
if (
|
||||
not isinstance(body["username"], text_type)
|
||||
or len(body["username"]) > 512
|
||||
):
|
||||
if not isinstance(body["username"], str) or len(body["username"]) > 512:
|
||||
raise SynapseError(400, "Invalid username")
|
||||
|
||||
username = body["username"].encode("utf-8")
|
||||
|
@ -386,7 +378,7 @@ class UserRegisterServlet(RestServlet):
|
|||
)
|
||||
else:
|
||||
password = body["password"]
|
||||
if not isinstance(password, text_type) or len(password) > 512:
|
||||
if not isinstance(password, str) or len(password) > 512:
|
||||
raise SynapseError(400, "Invalid password")
|
||||
|
||||
password_bytes = password.encode("utf-8")
|
||||
|
@ -477,7 +469,7 @@ class DeactivateAccountRestServlet(RestServlet):
|
|||
erase = body.get("erase", False)
|
||||
if not isinstance(erase, bool):
|
||||
raise SynapseError(
|
||||
http_client.BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Param 'erase' must be a boolean, if given",
|
||||
Codes.BAD_JSON,
|
||||
)
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
"""
|
||||
import logging
|
||||
|
||||
from six import string_types
|
||||
|
||||
from synapse.api.errors import AuthError, SynapseError
|
||||
from synapse.handlers.presence import format_user_presence_state
|
||||
from synapse.http.servlet import RestServlet, parse_json_object_from_request
|
||||
|
@ -73,7 +71,7 @@ class PresenceStatusRestServlet(RestServlet):
|
|||
|
||||
if "status_msg" in content:
|
||||
state["status_msg"] = content.pop("status_msg")
|
||||
if not isinstance(state["status_msg"], string_types):
|
||||
if not isinstance(state["status_msg"], str):
|
||||
raise SynapseError(400, "status_msg must be a string.")
|
||||
|
||||
if content:
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
import logging
|
||||
import re
|
||||
from typing import List, Optional
|
||||
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import logging
|
||||
|
||||
from six.moves import http_client
|
||||
from http import HTTPStatus
|
||||
|
||||
from synapse.api.constants import LoginType
|
||||
from synapse.api.errors import Codes, SynapseError, ThreepidValidationError
|
||||
|
@ -321,7 +320,7 @@ class DeactivateAccountRestServlet(RestServlet):
|
|||
erase = body.get("erase", False)
|
||||
if not isinstance(erase, bool):
|
||||
raise SynapseError(
|
||||
http_client.BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Param 'erase' must be a boolean, if given",
|
||||
Codes.BAD_JSON,
|
||||
)
|
||||
|
|
|
@ -18,8 +18,6 @@ import hmac
|
|||
import logging
|
||||
from typing import List, Union
|
||||
|
||||
from six import string_types
|
||||
|
||||
import synapse
|
||||
import synapse.api.auth
|
||||
import synapse.types
|
||||
|
@ -413,7 +411,7 @@ class RegisterRestServlet(RestServlet):
|
|||
# in sessions. Pull out the username/password provided to us.
|
||||
if "password" in body:
|
||||
password = body.pop("password")
|
||||
if not isinstance(password, string_types) or len(password) > 512:
|
||||
if not isinstance(password, str) or len(password) > 512:
|
||||
raise SynapseError(400, "Invalid password")
|
||||
self.password_policy_handler.validate_password(password)
|
||||
|
||||
|
@ -425,10 +423,7 @@ class RegisterRestServlet(RestServlet):
|
|||
|
||||
desired_username = None
|
||||
if "username" in body:
|
||||
if (
|
||||
not isinstance(body["username"], string_types)
|
||||
or len(body["username"]) > 512
|
||||
):
|
||||
if not isinstance(body["username"], str) or len(body["username"]) > 512:
|
||||
raise SynapseError(400, "Invalid username")
|
||||
desired_username = body["username"]
|
||||
|
||||
|
@ -453,7 +448,7 @@ class RegisterRestServlet(RestServlet):
|
|||
|
||||
access_token = self.auth.get_access_token_from_request(request)
|
||||
|
||||
if isinstance(desired_username, string_types):
|
||||
if isinstance(desired_username, str):
|
||||
result = await self._do_appservice_registration(
|
||||
desired_username, access_token, body
|
||||
)
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from six import string_types
|
||||
from six.moves import http_client
|
||||
from http import HTTPStatus
|
||||
|
||||
from synapse.api.errors import Codes, SynapseError
|
||||
from synapse.http.servlet import (
|
||||
|
@ -47,15 +45,15 @@ class ReportEventRestServlet(RestServlet):
|
|||
body = parse_json_object_from_request(request)
|
||||
assert_params_in_dict(body, ("reason", "score"))
|
||||
|
||||
if not isinstance(body["reason"], string_types):
|
||||
if not isinstance(body["reason"], str):
|
||||
raise SynapseError(
|
||||
http_client.BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Param 'reason' must be a string",
|
||||
Codes.BAD_JSON,
|
||||
)
|
||||
if not isinstance(body["score"], int):
|
||||
raise SynapseError(
|
||||
http_client.BAD_REQUEST,
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
"Param 'score' must be an integer",
|
||||
Codes.BAD_JSON,
|
||||
)
|
||||
|
|
|
@ -16,10 +16,9 @@
|
|||
import hmac
|
||||
import logging
|
||||
from hashlib import sha256
|
||||
from http import HTTPStatus
|
||||
from os import path
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
import jinja2
|
||||
from jinja2 import TemplateNotFound
|
||||
|
||||
|
@ -223,4 +222,4 @@ class ConsentResource(DirectServeResource):
|
|||
)
|
||||
|
||||
if not compare_digest(want_mac, userhmac):
|
||||
raise SynapseError(http_client.FORBIDDEN, "HMAC incorrect")
|
||||
raise SynapseError(HTTPStatus.FORBIDDEN, "HMAC incorrect")
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from six.moves import urllib
|
||||
import urllib
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.protocols.basic import FileSender
|
||||
|
|
|
@ -17,9 +17,6 @@ import contextlib
|
|||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.protocols.basic import FileSender
|
||||
|
@ -117,12 +114,11 @@ class MediaStorage(object):
|
|||
with open(fname, "wb") as f:
|
||||
yield f, fname, finish
|
||||
except Exception:
|
||||
t, v, tb = sys.exc_info()
|
||||
try:
|
||||
os.remove(fname)
|
||||
except Exception:
|
||||
pass
|
||||
six.reraise(t, v, tb)
|
||||
raise
|
||||
|
||||
if not finished_called:
|
||||
raise Exception("Finished callback not called")
|
||||
|
|
|
@ -24,10 +24,7 @@ import shutil
|
|||
import sys
|
||||
import traceback
|
||||
from typing import Dict, Optional
|
||||
|
||||
import six
|
||||
from six import string_types
|
||||
from six.moves import urllib_parse as urlparse
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
|
@ -188,7 +185,7 @@ class PreviewUrlResource(DirectServeResource):
|
|||
# It may be stored as text in the database, not as bytes (such as
|
||||
# PostgreSQL). If so, encode it back before handing it on.
|
||||
og = cache_result["og"]
|
||||
if isinstance(og, six.text_type):
|
||||
if isinstance(og, str):
|
||||
og = og.encode("utf8")
|
||||
return og
|
||||
|
||||
|
@ -631,7 +628,7 @@ def _iterate_over_text(tree, *tags_to_ignore):
|
|||
if el is None:
|
||||
return
|
||||
|
||||
if isinstance(el, string_types):
|
||||
if isinstance(el, str):
|
||||
yield el
|
||||
elif el.tag not in tags_to_ignore:
|
||||
# el.text is the text before the first child, so we can immediately
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue