mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-13 23:13:46 +01: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
1
changelog.d/7704.misc
Normal file
1
changelog.d/7704.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Replace all remaining uses of `six` with native Python 3 equivalents. Contributed by @ilmari.
|
|
@ -24,8 +24,6 @@ import argparse
|
|||
from synapse.events import FrozenEvent
|
||||
from synapse.util.frozenutils import unfreeze
|
||||
|
||||
from six import string_types
|
||||
|
||||
|
||||
def make_graph(file_name, room_id, file_prefix, limit):
|
||||
print("Reading lines")
|
||||
|
@ -62,7 +60,7 @@ def make_graph(file_name, room_id, file_prefix, limit):
|
|||
for key, value in unfreeze(event.get_dict()["content"]).items():
|
||||
if value is None:
|
||||
value = "<null>"
|
||||
elif isinstance(value, string_types):
|
||||
elif isinstance(value, str):
|
||||
pass
|
||||
else:
|
||||
value = json.dumps(value)
|
||||
|
|
|
@ -21,8 +21,7 @@ import argparse
|
|||
import base64
|
||||
import json
|
||||
import sys
|
||||
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from urllib import parse as urlparse
|
||||
|
||||
import nacl.signing
|
||||
import requests
|
||||
|
|
|
@ -23,8 +23,6 @@ import sys
|
|||
import time
|
||||
import traceback
|
||||
|
||||
from six import string_types
|
||||
|
||||
import yaml
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
|
@ -635,7 +633,7 @@ class Porter(object):
|
|||
return bool(col)
|
||||
if isinstance(col, bytes):
|
||||
return bytearray(col)
|
||||
elif isinstance(col, string_types) and "\0" in col:
|
||||
elif isinstance(col, str) and "\0" in col:
|
||||
logger.warning(
|
||||
"DROPPING ROW: NUL value in table %s col %s: %r",
|
||||
table,
|
||||
|
|
|
@ -31,7 +31,7 @@ sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
|
|||
default_section=THIRDPARTY
|
||||
known_first_party = synapse
|
||||
known_tests=tests
|
||||
known_compat = mock,six
|
||||
known_compat = mock
|
||||
known_twisted=twisted,OpenSSL
|
||||
multi_line_output=3
|
||||
include_trailing_comma=true
|
||||
|
|
|
@ -23,8 +23,6 @@ import hmac
|
|||
import logging
|
||||
import sys
|
||||
|
||||
from six.moves import input
|
||||
|
||||
import requests as _requests
|
||||
import yaml
|
||||
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
"""Contains exceptions and error codes."""
|
||||
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, List
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
from twisted.web import http
|
||||
|
@ -173,7 +172,7 @@ class ConsentNotGivenError(SynapseError):
|
|||
consent_url (str): The URL where the user can give their consent
|
||||
"""
|
||||
super(ConsentNotGivenError, self).__init__(
|
||||
code=http_client.FORBIDDEN, msg=msg, errcode=Codes.CONSENT_NOT_GIVEN
|
||||
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.CONSENT_NOT_GIVEN
|
||||
)
|
||||
self._consent_uri = consent_uri
|
||||
|
||||
|
@ -193,7 +192,7 @@ class UserDeactivatedError(SynapseError):
|
|||
msg (str): The human-readable error message
|
||||
"""
|
||||
super(UserDeactivatedError, self).__init__(
|
||||
code=http_client.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED
|
||||
code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
# limitations under the License.
|
||||
from typing import List
|
||||
|
||||
from six import text_type
|
||||
|
||||
import jsonschema
|
||||
from canonicaljson import json
|
||||
from jsonschema import FormatChecker
|
||||
|
@ -313,7 +311,7 @@ class Filter(object):
|
|||
|
||||
content = event.get("content", {})
|
||||
# check if there is a string url field in the content for filtering purposes
|
||||
contains_url = isinstance(content.get("url"), text_type)
|
||||
contains_url = isinstance(content.get("url"), str)
|
||||
labels = content.get(EventContentFields.LABELS, [])
|
||||
|
||||
return self.check_fields(room_id, sender, ev_type, labels, contains_url)
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
"""Contains the URL paths to prefix various aspects of the server with. """
|
||||
import hmac
|
||||
from hashlib import sha256
|
||||
|
||||
from six.moves.urllib.parse import urlencode
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from synapse.config import ConfigError
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
from six import string_types
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import EventTypes
|
||||
|
@ -156,7 +154,7 @@ class ApplicationService(object):
|
|||
)
|
||||
|
||||
regex = regex_obj.get("regex")
|
||||
if isinstance(regex, string_types):
|
||||
if isinstance(regex, str):
|
||||
regex_obj["regex"] = re.compile(regex) # Pre-compile regex
|
||||
else:
|
||||
raise ValueError("Expected string for 'regex' in ns '%s'" % ns)
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import logging
|
||||
|
||||
from six.moves import urllib
|
||||
import urllib
|
||||
|
||||
from prometheus_client import Counter
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@ from collections import OrderedDict
|
|||
from textwrap import dedent
|
||||
from typing import Any, MutableMapping, Optional
|
||||
|
||||
from six import integer_types
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
|
@ -117,7 +115,7 @@ class Config(object):
|
|||
|
||||
@staticmethod
|
||||
def parse_size(value):
|
||||
if isinstance(value, integer_types):
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
sizes = {"K": 1024, "M": 1024 * 1024}
|
||||
size = 1
|
||||
|
@ -129,7 +127,7 @@ class Config(object):
|
|||
|
||||
@staticmethod
|
||||
def parse_duration(value):
|
||||
if isinstance(value, integer_types):
|
||||
if isinstance(value, int):
|
||||
return value
|
||||
second = 1000
|
||||
minute = 60 * second
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
|
||||
import logging
|
||||
from typing import Dict
|
||||
|
||||
from six import string_types
|
||||
from six.moves.urllib import parse as urlparse
|
||||
from urllib import parse as urlparse
|
||||
|
||||
import yaml
|
||||
from netaddr import IPSet
|
||||
|
@ -98,17 +96,14 @@ def load_appservices(hostname, config_files):
|
|||
def _load_appservice(hostname, as_info, config_filename):
|
||||
required_string_fields = ["id", "as_token", "hs_token", "sender_localpart"]
|
||||
for field in required_string_fields:
|
||||
if not isinstance(as_info.get(field), string_types):
|
||||
if not isinstance(as_info.get(field), str):
|
||||
raise KeyError(
|
||||
"Required string field: '%s' (%s)" % (field, config_filename)
|
||||
)
|
||||
|
||||
# 'url' must either be a string or explicitly null, not missing
|
||||
# to avoid accidentally turning off push for ASes.
|
||||
if (
|
||||
not isinstance(as_info.get("url"), string_types)
|
||||
and as_info.get("url", "") is not None
|
||||
):
|
||||
if not isinstance(as_info.get("url"), str) and as_info.get("url", "") is not None:
|
||||
raise KeyError(
|
||||
"Required string field or explicit null: 'url' (%s)" % (config_filename,)
|
||||
)
|
||||
|
@ -138,7 +133,7 @@ def _load_appservice(hostname, as_info, config_filename):
|
|||
ns,
|
||||
regex_obj,
|
||||
)
|
||||
if not isinstance(regex_obj.get("regex"), string_types):
|
||||
if not isinstance(regex_obj.get("regex"), str):
|
||||
raise ValueError("Missing/bad type 'regex' key in %s", regex_obj)
|
||||
if not isinstance(regex_obj.get("exclusive"), bool):
|
||||
raise ValueError(
|
||||
|
|
|
@ -20,8 +20,6 @@ from datetime import datetime
|
|||
from hashlib import sha256
|
||||
from typing import List
|
||||
|
||||
import six
|
||||
|
||||
from unpaddedbase64 import encode_base64
|
||||
|
||||
from OpenSSL import SSL, crypto
|
||||
|
@ -59,7 +57,7 @@ class TlsConfig(Config):
|
|||
logger.warning(ACME_SUPPORT_ENABLED_WARN)
|
||||
|
||||
# hyperlink complains on py2 if this is not a Unicode
|
||||
self.acme_url = six.text_type(
|
||||
self.acme_url = str(
|
||||
acme_config.get("url", "https://acme-v01.api.letsencrypt.org/directory")
|
||||
)
|
||||
self.acme_port = acme_config.get("port", 80)
|
||||
|
|
|
@ -15,11 +15,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
from collections import defaultdict
|
||||
|
||||
import six
|
||||
from six.moves import urllib
|
||||
|
||||
import attr
|
||||
from signedjson.key import (
|
||||
decode_verify_key_bytes,
|
||||
|
@ -661,7 +659,7 @@ class PerspectivesKeyFetcher(BaseV2KeyFetcher):
|
|||
for response in query_response["server_keys"]:
|
||||
# do this first, so that we can give useful errors thereafter
|
||||
server_name = response.get("server_name")
|
||||
if not isinstance(server_name, six.string_types):
|
||||
if not isinstance(server_name, str):
|
||||
raise KeyLookupError(
|
||||
"Malformed response from key notary server %s: invalid server_name"
|
||||
% (perspective_name,)
|
||||
|
|
|
@ -16,8 +16,6 @@ import collections
|
|||
import re
|
||||
from typing import Any, Mapping, Union
|
||||
|
||||
from six import string_types
|
||||
|
||||
from frozendict import frozendict
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -318,7 +316,7 @@ def serialize_event(
|
|||
|
||||
if only_event_fields:
|
||||
if not isinstance(only_event_fields, list) or not all(
|
||||
isinstance(f, string_types) for f in only_event_fields
|
||||
isinstance(f, str) for f in only_event_fields
|
||||
):
|
||||
raise TypeError("only_event_fields must be a list of strings")
|
||||
d = only_fields(d, only_event_fields)
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six import integer_types, string_types
|
||||
|
||||
from synapse.api.constants import MAX_ALIAS_LENGTH, EventTypes, Membership
|
||||
from synapse.api.errors import Codes, SynapseError
|
||||
from synapse.api.room_versions import EventFormatVersions
|
||||
|
@ -53,7 +51,7 @@ class EventValidator(object):
|
|||
event_strings = ["origin"]
|
||||
|
||||
for s in event_strings:
|
||||
if not isinstance(getattr(event, s), string_types):
|
||||
if not isinstance(getattr(event, s), str):
|
||||
raise SynapseError(400, "'%s' not a string type" % (s,))
|
||||
|
||||
# Depending on the room version, ensure the data is spec compliant JSON.
|
||||
|
@ -90,7 +88,7 @@ class EventValidator(object):
|
|||
max_lifetime = event.content.get("max_lifetime")
|
||||
|
||||
if min_lifetime is not None:
|
||||
if not isinstance(min_lifetime, integer_types):
|
||||
if not isinstance(min_lifetime, int):
|
||||
raise SynapseError(
|
||||
code=400,
|
||||
msg="'min_lifetime' must be an integer",
|
||||
|
@ -124,7 +122,7 @@ class EventValidator(object):
|
|||
)
|
||||
|
||||
if max_lifetime is not None:
|
||||
if not isinstance(max_lifetime, integer_types):
|
||||
if not isinstance(max_lifetime, int):
|
||||
raise SynapseError(
|
||||
code=400,
|
||||
msg="'max_lifetime' must be an integer",
|
||||
|
@ -183,7 +181,7 @@ class EventValidator(object):
|
|||
strings.append("state_key")
|
||||
|
||||
for s in strings:
|
||||
if not isinstance(getattr(event, s), string_types):
|
||||
if not isinstance(getattr(event, s), str):
|
||||
raise SynapseError(400, "Not '%s' a string type" % (s,))
|
||||
|
||||
RoomID.from_string(event.room_id)
|
||||
|
@ -223,7 +221,7 @@ class EventValidator(object):
|
|||
for s in keys:
|
||||
if s not in d:
|
||||
raise SynapseError(400, "'%s' not in content" % (s,))
|
||||
if not isinstance(d[s], string_types):
|
||||
if not isinstance(d[s], str):
|
||||
raise SynapseError(400, "'%s' not a string type" % (s,))
|
||||
|
||||
def _ensure_state_event(self, event):
|
||||
|
|
|
@ -17,8 +17,6 @@ import logging
|
|||
from collections import namedtuple
|
||||
from typing import Iterable, List
|
||||
|
||||
import six
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.internet.defer import Deferred, DeferredList
|
||||
from twisted.python.failure import Failure
|
||||
|
@ -294,7 +292,7 @@ def event_from_pdu_json(
|
|||
assert_params_in_dict(pdu_json, ("type", "depth"))
|
||||
|
||||
depth = pdu_json["depth"]
|
||||
if not isinstance(depth, six.integer_types):
|
||||
if not isinstance(depth, int):
|
||||
raise SynapseError(400, "Depth %r not an intger" % (depth,), Codes.BAD_JSON)
|
||||
|
||||
if depth < 0:
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
import logging
|
||||
from typing import Any, Callable, Dict, List, Match, Optional, Tuple, Union
|
||||
|
||||
import six
|
||||
|
||||
from canonicaljson import json
|
||||
from prometheus_client import Counter
|
||||
|
||||
|
@ -751,7 +749,7 @@ def server_matches_acl_event(server_name: str, acl_event: EventBase) -> bool:
|
|||
|
||||
|
||||
def _acl_entry_matches(server_name: str, acl_entry: str) -> Match:
|
||||
if not isinstance(acl_entry, six.string_types):
|
||||
if not isinstance(acl_entry, str):
|
||||
logger.warning(
|
||||
"Ignoring non-str ACL entry '%s' (is %s)", acl_entry, type(acl_entry)
|
||||
)
|
||||
|
|
|
@ -15,10 +15,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from six.moves import urllib
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import Membership
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
from six import string_types
|
||||
|
||||
from synapse.api.errors import Codes, SynapseError
|
||||
from synapse.types import GroupID, RoomID, UserID, get_domain_from_id
|
||||
from synapse.util.async_helpers import concurrently_execute
|
||||
|
@ -513,7 +511,7 @@ class GroupsServerHandler(GroupsServerWorkerHandler):
|
|||
for keyname in ("name", "avatar_url", "short_description", "long_description"):
|
||||
if keyname in content:
|
||||
value = content[keyname]
|
||||
if not isinstance(value, string_types):
|
||||
if not isinstance(value, str):
|
||||
raise SynapseError(400, "%r value is not a string" % (keyname,))
|
||||
profile[keyname] = value
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
import xml.etree.ElementTree as ET
|
||||
from typing import Dict, Optional, Tuple
|
||||
|
||||
from six.moves import urllib
|
||||
|
||||
from twisted.web.client import PartialDownloadError
|
||||
|
||||
from synapse.api.errors import Codes, LoginError
|
||||
|
|
|
@ -19,10 +19,9 @@
|
|||
|
||||
import itertools
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, Iterable, List, Optional, Sequence, Tuple
|
||||
|
||||
from six.moves import http_client, zip
|
||||
|
||||
import attr
|
||||
from signedjson.key import decode_verify_key_bytes
|
||||
from signedjson.sign import verify_signed_json
|
||||
|
@ -1194,7 +1193,7 @@ class FederationHandler(BaseHandler):
|
|||
ev.event_id,
|
||||
len(ev.prev_event_ids()),
|
||||
)
|
||||
raise SynapseError(http_client.BAD_REQUEST, "Too many prev_events")
|
||||
raise SynapseError(HTTPStatus.BAD_REQUEST, "Too many prev_events")
|
||||
|
||||
if len(ev.auth_event_ids()) > 10:
|
||||
logger.warning(
|
||||
|
@ -1202,7 +1201,7 @@ class FederationHandler(BaseHandler):
|
|||
ev.event_id,
|
||||
len(ev.auth_event_ids()),
|
||||
)
|
||||
raise SynapseError(http_client.BAD_REQUEST, "Too many auth_events")
|
||||
raise SynapseError(HTTPStatus.BAD_REQUEST, "Too many auth_events")
|
||||
|
||||
async def send_invite(self, target_host, event):
|
||||
""" Sends the invite to the remote server for signing.
|
||||
|
@ -1545,7 +1544,7 @@ class FederationHandler(BaseHandler):
|
|||
|
||||
# block any attempts to invite the server notices mxid
|
||||
if event.state_key == self._server_notices_mxid:
|
||||
raise SynapseError(http_client.FORBIDDEN, "Cannot invite this user")
|
||||
raise SynapseError(HTTPStatus.FORBIDDEN, "Cannot invite this user")
|
||||
|
||||
# keep a record of the room version, if we don't yet know it.
|
||||
# (this may get overwritten if we later get a different room version in a
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
import logging
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from six import string_types
|
||||
|
||||
from canonicaljson import encode_canonical_json, json
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -715,7 +713,7 @@ class EventCreationHandler(object):
|
|||
|
||||
spam_error = self.spam_checker.check_event_for_spam(event)
|
||||
if spam_error:
|
||||
if not isinstance(spam_error, string_types):
|
||||
if not isinstance(spam_error, str):
|
||||
spam_error = "Spam is not permitted here"
|
||||
raise SynapseError(403, spam_error, Codes.FORBIDDEN)
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
from six import raise_from
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import (
|
||||
|
@ -84,7 +82,7 @@ class BaseProfileHandler(BaseHandler):
|
|||
)
|
||||
return result
|
||||
except RequestSendFailed as e:
|
||||
raise_from(SynapseError(502, "Failed to fetch profile"), e)
|
||||
raise SynapseError(502, "Failed to fetch profile") from e
|
||||
except HttpResponseException as e:
|
||||
raise e.to_synapse_error()
|
||||
|
||||
|
@ -135,7 +133,7 @@ class BaseProfileHandler(BaseHandler):
|
|||
ignore_backoff=True,
|
||||
)
|
||||
except RequestSendFailed as e:
|
||||
raise_from(SynapseError(502, "Failed to fetch profile"), e)
|
||||
raise SynapseError(502, "Failed to fetch profile") from e
|
||||
except HttpResponseException as e:
|
||||
raise e.to_synapse_error()
|
||||
|
||||
|
@ -212,7 +210,7 @@ class BaseProfileHandler(BaseHandler):
|
|||
ignore_backoff=True,
|
||||
)
|
||||
except RequestSendFailed as e:
|
||||
raise_from(SynapseError(502, "Failed to fetch profile"), e)
|
||||
raise SynapseError(502, "Failed to fetch profile") from e
|
||||
except HttpResponseException as e:
|
||||
raise e.to_synapse_error()
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import string
|
|||
from collections import OrderedDict
|
||||
from typing import Tuple
|
||||
|
||||
from six import string_types
|
||||
|
||||
from synapse.api.constants import (
|
||||
EventTypes,
|
||||
JoinRules,
|
||||
|
@ -595,7 +593,7 @@ class RoomCreationHandler(BaseHandler):
|
|||
"room_version", self.config.default_room_version.identifier
|
||||
)
|
||||
|
||||
if not isinstance(room_version_id, string_types):
|
||||
if not isinstance(room_version_id, str):
|
||||
raise SynapseError(400, "room_version must be a string", Codes.BAD_JSON)
|
||||
|
||||
room_version = KNOWN_ROOM_VERSIONS.get(room_version_id)
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
|
||||
import abc
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
from typing import Dict, Iterable, List, Optional, Tuple
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from synapse import types
|
||||
from synapse.api.constants import EventTypes, Membership
|
||||
from synapse.api.errors import AuthError, Codes, SynapseError
|
||||
|
@ -361,7 +360,7 @@ class RoomMemberHandler(object):
|
|||
if effective_membership_state == Membership.INVITE:
|
||||
# block any attempts to invite the server notices mxid
|
||||
if target.to_string() == self._server_notices_mxid:
|
||||
raise SynapseError(http_client.FORBIDDEN, "Cannot invite this user")
|
||||
raise SynapseError(HTTPStatus.FORBIDDEN, "Cannot invite this user")
|
||||
|
||||
block_invite = False
|
||||
|
||||
|
@ -444,7 +443,7 @@ class RoomMemberHandler(object):
|
|||
is_blocked = await self._is_server_notice_room(room_id)
|
||||
if is_blocked:
|
||||
raise SynapseError(
|
||||
http_client.FORBIDDEN,
|
||||
HTTPStatus.FORBIDDEN,
|
||||
"You cannot reject this invite",
|
||||
errcode=Codes.CANNOT_LEAVE_SERVER_NOTICE_ROOM,
|
||||
)
|
||||
|
|
|
@ -15,11 +15,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
from io import BytesIO
|
||||
|
||||
from six import raise_from, text_type
|
||||
from six.moves import urllib
|
||||
|
||||
import treq
|
||||
from canonicaljson import encode_canonical_json, json
|
||||
from netaddr import IPAddress
|
||||
|
@ -577,7 +575,7 @@ class SimpleHttpClient(object):
|
|||
# This can happen e.g. because the body is too large.
|
||||
raise
|
||||
except Exception as e:
|
||||
raise_from(SynapseError(502, ("Failed to download remote body: %s" % e)), e)
|
||||
raise SynapseError(502, ("Failed to download remote body: %s" % e)) from e
|
||||
|
||||
return (
|
||||
length,
|
||||
|
@ -638,7 +636,7 @@ def encode_urlencode_args(args):
|
|||
|
||||
|
||||
def encode_urlencode_arg(arg):
|
||||
if isinstance(arg, text_type):
|
||||
if isinstance(arg, str):
|
||||
return arg.encode("utf-8")
|
||||
elif isinstance(arg, list):
|
||||
return [encode_urlencode_arg(i) for i in arg]
|
||||
|
|
|
@ -17,11 +17,9 @@ import cgi
|
|||
import logging
|
||||
import random
|
||||
import sys
|
||||
import urllib
|
||||
from io import BytesIO
|
||||
|
||||
from six import raise_from, string_types
|
||||
from six.moves import urllib
|
||||
|
||||
import attr
|
||||
import treq
|
||||
from canonicaljson import encode_canonical_json
|
||||
|
@ -432,10 +430,10 @@ class MatrixFederationHttpClient(object):
|
|||
except TimeoutError as e:
|
||||
raise RequestSendFailed(e, can_retry=True) from e
|
||||
except DNSLookupError as e:
|
||||
raise_from(RequestSendFailed(e, can_retry=retry_on_dns_fail), e)
|
||||
raise RequestSendFailed(e, can_retry=retry_on_dns_fail) from e
|
||||
except Exception as e:
|
||||
logger.info("Failed to send request: %s", e)
|
||||
raise_from(RequestSendFailed(e, can_retry=True), e)
|
||||
raise RequestSendFailed(e, can_retry=True) from e
|
||||
|
||||
incoming_responses_counter.labels(
|
||||
request.method, response.code
|
||||
|
@ -487,7 +485,7 @@ class MatrixFederationHttpClient(object):
|
|||
# Retry if the error is a 429 (Too Many Requests),
|
||||
# otherwise just raise a standard HttpResponseException
|
||||
if response.code == 429:
|
||||
raise_from(RequestSendFailed(e, can_retry=True), e)
|
||||
raise RequestSendFailed(e, can_retry=True) from e
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
@ -998,7 +996,7 @@ def encode_query_args(args):
|
|||
|
||||
encoded_args = {}
|
||||
for k, vs in args.items():
|
||||
if isinstance(vs, string_types):
|
||||
if isinstance(vs, str):
|
||||
vs = [vs]
|
||||
encoded_args[k] = [v.encode("UTF-8") for v in vs]
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
import collections
|
||||
import html
|
||||
import http.client
|
||||
import logging
|
||||
import types
|
||||
import urllib
|
||||
from http import HTTPStatus
|
||||
from io import BytesIO
|
||||
from typing import Awaitable, Callable, TypeVar, Union
|
||||
|
||||
|
@ -188,7 +188,7 @@ def return_html_error(
|
|||
exc_info=(f.type, f.value, f.getTracebackObject()),
|
||||
)
|
||||
else:
|
||||
code = http.HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
code = HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
msg = "Internal server error"
|
||||
|
||||
logger.error(
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from six import StringIO
|
||||
from io import StringIO
|
||||
|
||||
|
||||
class LogFormatter(logging.Formatter):
|
||||
|
|
|
@ -17,12 +17,11 @@ import email.mime.multipart
|
|||
import email.utils
|
||||
import logging
|
||||
import time
|
||||
import urllib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from typing import Iterable, List, TypeVar
|
||||
|
||||
from six.moves import urllib
|
||||
|
||||
import bleach
|
||||
import jinja2
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ import logging
|
|||
import re
|
||||
from typing import Pattern
|
||||
|
||||
from six import string_types
|
||||
|
||||
from synapse.events import EventBase
|
||||
from synapse.types import UserID
|
||||
from synapse.util.caches import register_cache
|
||||
|
@ -244,7 +242,7 @@ def _flatten_dict(d, prefix=[], result=None):
|
|||
if result is None:
|
||||
result = {}
|
||||
for key, value in d.items():
|
||||
if isinstance(value, string_types):
|
||||
if isinstance(value, str):
|
||||
result[".".join(prefix + [key])] = value.lower()
|
||||
elif hasattr(value, "items"):
|
||||
_flatten_dict(value, prefix=(prefix + [key]), result=result)
|
||||
|
|
|
@ -66,7 +66,6 @@ REQUIREMENTS = [
|
|||
"pymacaroons>=0.13.0",
|
||||
"msgpack>=0.5.2",
|
||||
"phonenumbers>=8.2.0",
|
||||
"six>=1.10",
|
||||
"prometheus_client>=0.0.18,<0.8.0",
|
||||
# we use attr.validators.deep_iterable, which arrived in 19.1.0
|
||||
"attrs>=19.1.0",
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
import abc
|
||||
import logging
|
||||
import re
|
||||
import urllib
|
||||
from inspect import signature
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from six import raise_from
|
||||
from six.moves import urllib
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import (
|
||||
|
@ -220,7 +218,7 @@ class ReplicationEndpoint(object):
|
|||
# importantly, not stack traces everywhere)
|
||||
raise e.to_synapse_error()
|
||||
except RequestSendFailed as e:
|
||||
raise_from(SynapseError(502, "Failed to talk to master"), e)
|
||||
raise SynapseError(502, "Failed to talk to master") from e
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# limitations under the License.
|
||||
import logging
|
||||
|
||||
from six import string_types
|
||||
|
||||
from synapse.api.errors import SynapseError
|
||||
from synapse.api.urls import ConsentURIBuilder
|
||||
from synapse.config import ConfigError
|
||||
|
@ -118,7 +116,7 @@ def copy_with_str_subst(x, substitutions):
|
|||
Returns:
|
||||
copy of x
|
||||
"""
|
||||
if isinstance(x, string_types):
|
||||
if isinstance(x, str):
|
||||
return x % substitutions
|
||||
if isinstance(x, dict):
|
||||
return {k: copy_with_str_subst(v, substitutions) for (k, v) in x.items()}
|
||||
|
|
|
@ -14,10 +14,9 @@
|
|||
# limitations under the License.
|
||||
import itertools
|
||||
import logging
|
||||
from queue import Empty, PriorityQueue
|
||||
from typing import Dict, List, Optional, Set, Tuple
|
||||
|
||||
from six.moves.queue import Empty, PriorityQueue
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import StoreError
|
||||
|
|
|
@ -21,9 +21,6 @@ from collections import OrderedDict, namedtuple
|
|||
from functools import wraps
|
||||
from typing import TYPE_CHECKING, Dict, Iterable, List, Tuple
|
||||
|
||||
from six import integer_types, text_type
|
||||
from six.moves import range
|
||||
|
||||
import attr
|
||||
from canonicaljson import json
|
||||
from prometheus_client import Counter
|
||||
|
@ -893,8 +890,7 @@ class PersistEventsStore:
|
|||
"received_ts": self._clock.time_msec(),
|
||||
"sender": event.sender,
|
||||
"contains_url": (
|
||||
"url" in event.content
|
||||
and isinstance(event.content["url"], text_type)
|
||||
"url" in event.content and isinstance(event.content["url"], str)
|
||||
),
|
||||
}
|
||||
for event, _ in events_and_contexts
|
||||
|
@ -1345,10 +1341,10 @@ class PersistEventsStore:
|
|||
):
|
||||
if (
|
||||
"min_lifetime" in event.content
|
||||
and not isinstance(event.content.get("min_lifetime"), integer_types)
|
||||
and not isinstance(event.content.get("min_lifetime"), int)
|
||||
) or (
|
||||
"max_lifetime" in event.content
|
||||
and not isinstance(event.content.get("max_lifetime"), integer_types)
|
||||
and not isinstance(event.content.get("max_lifetime"), int)
|
||||
):
|
||||
# Ignore the event if one of the value isn't an integer.
|
||||
return
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
from six import text_type
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -133,7 +131,7 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
|
|||
|
||||
contains_url = "url" in content
|
||||
if contains_url:
|
||||
contains_url &= isinstance(content["url"], text_type)
|
||||
contains_url &= isinstance(content["url"], str)
|
||||
except (KeyError, AttributeError):
|
||||
# If the event is missing a necessary field then
|
||||
# skip over it.
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# limitations under the License.
|
||||
import logging
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from synapse.config.appservice import load_appservices
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -17,8 +17,6 @@ import logging
|
|||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
from six import string_types
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
from twisted.internet import defer
|
||||
|
@ -180,7 +178,7 @@ class SearchBackgroundUpdateStore(SearchWorkerStore):
|
|||
# skip over it.
|
||||
continue
|
||||
|
||||
if not isinstance(value, string_types):
|
||||
if not isinstance(value, str):
|
||||
# If the event body, name or topic isn't a string
|
||||
# then skip over it
|
||||
continue
|
||||
|
|
|
@ -40,8 +40,6 @@ import abc
|
|||
import logging
|
||||
from collections import namedtuple
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.logging.context import make_deferred_yieldable, run_in_background
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
import logging
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from canonicaljson import json
|
||||
|
||||
from twisted.internet import defer
|
||||
|
|
|
@ -17,8 +17,6 @@ import logging
|
|||
from collections import namedtuple
|
||||
from typing import Dict, Iterable, List, Set, Tuple
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import EventTypes
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# limitations under the License.
|
||||
import logging
|
||||
import time
|
||||
from sys import intern
|
||||
from time import monotonic as monotonic_time
|
||||
from typing import (
|
||||
Any,
|
||||
|
@ -29,8 +30,6 @@ from typing import (
|
|||
TypeVar,
|
||||
)
|
||||
|
||||
from six.moves import intern, range
|
||||
|
||||
from prometheus_client import Histogram
|
||||
|
||||
from twisted.enterprise import adbapi
|
||||
|
|
|
@ -20,8 +20,6 @@ import logging
|
|||
from collections import deque, namedtuple
|
||||
from typing import Iterable, List, Optional, Set, Tuple
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from prometheus_client import Counter, Histogram
|
||||
|
||||
from twisted.internet import defer
|
||||
|
|
|
@ -19,8 +19,6 @@ import logging
|
|||
from contextlib import contextmanager
|
||||
from typing import Dict, Sequence, Set, Union
|
||||
|
||||
from six.moves import range
|
||||
|
||||
import attr
|
||||
|
||||
from twisted.internet import defer
|
||||
|
|
|
@ -17,8 +17,6 @@ import logging
|
|||
import math
|
||||
from typing import Dict, FrozenSet, List, Mapping, Optional, Set, Union
|
||||
|
||||
from six import integer_types
|
||||
|
||||
from sortedcontainers import SortedDict
|
||||
|
||||
from synapse.types import Collection
|
||||
|
@ -88,7 +86,7 @@ class StreamChangeCache:
|
|||
def has_entity_changed(self, entity: EntityType, stream_pos: int) -> bool:
|
||||
"""Returns True if the entity may have been updated since stream_pos
|
||||
"""
|
||||
assert type(stream_pos) in integer_types
|
||||
assert isinstance(stream_pos, int)
|
||||
|
||||
if stream_pos < self._earliest_known_stream_pos:
|
||||
self.metrics.inc_misses()
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves import queue
|
||||
import queue
|
||||
|
||||
from twisted.internet import threads
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six import binary_type, text_type
|
||||
|
||||
from canonicaljson import json
|
||||
from frozendict import frozendict
|
||||
|
||||
|
@ -26,7 +24,7 @@ def freeze(o):
|
|||
if isinstance(o, frozendict):
|
||||
return o
|
||||
|
||||
if isinstance(o, (binary_type, text_type)):
|
||||
if isinstance(o, (bytes, str)):
|
||||
return o
|
||||
|
||||
try:
|
||||
|
@ -41,7 +39,7 @@ def unfreeze(o):
|
|||
if isinstance(o, (dict, frozendict)):
|
||||
return dict({k: unfreeze(v) for k, v in o.items()})
|
||||
|
||||
if isinstance(o, (binary_type, text_type)):
|
||||
if isinstance(o, (bytes, str)):
|
||||
return o
|
||||
|
||||
try:
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves import range
|
||||
|
||||
|
||||
class _Entry(object):
|
||||
__slots__ = ["end_key", "queue"]
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
import logging
|
||||
import operator
|
||||
|
||||
from six.moves import map
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.constants import EventTypes, Membership
|
||||
|
|
6
synctl
6
synctl
|
@ -26,8 +26,6 @@ import subprocess
|
|||
import sys
|
||||
import time
|
||||
|
||||
from six import iteritems
|
||||
|
||||
import yaml
|
||||
|
||||
from synapse.config import find_config_files
|
||||
|
@ -251,7 +249,7 @@ def main():
|
|||
os.environ["SYNAPSE_CACHE_FACTOR"] = str(cache_factor)
|
||||
|
||||
cache_factors = config.get("synctl_cache_factors", {})
|
||||
for cache_name, factor in iteritems(cache_factors):
|
||||
for cache_name, factor in cache_factors.items():
|
||||
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)
|
||||
|
||||
worker_configfiles = []
|
||||
|
@ -362,7 +360,7 @@ def main():
|
|||
if worker.cache_factor:
|
||||
os.environ["SYNAPSE_CACHE_FACTOR"] = str(worker.cache_factor)
|
||||
|
||||
for cache_name, factor in iteritems(worker.cache_factors):
|
||||
for cache_name, factor in worker.cache_factors.items():
|
||||
os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)
|
||||
|
||||
if not start_worker(worker.app, configfile, worker.configfile):
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
"""Tests REST events for /rooms paths."""
|
||||
|
||||
import json
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from mock import Mock
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
|
||||
import itertools
|
||||
import json
|
||||
|
||||
import six
|
||||
import urllib
|
||||
|
||||
from synapse.api.constants import EventTypes, RelationTypes
|
||||
from synapse.rest import admin
|
||||
|
@ -134,7 +133,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
|||
# Make sure next_batch has something in it that looks like it could be a
|
||||
# valid token.
|
||||
self.assertIsInstance(
|
||||
channel.json_body.get("next_batch"), six.string_types, channel.json_body
|
||||
channel.json_body.get("next_batch"), str, channel.json_body
|
||||
)
|
||||
|
||||
def test_repeated_paginate_relations(self):
|
||||
|
@ -278,7 +277,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
prev_token = None
|
||||
found_event_ids = []
|
||||
encoded_key = six.moves.urllib.parse.quote_plus("👍".encode("utf-8"))
|
||||
encoded_key = urllib.parse.quote_plus("👍".encode("utf-8"))
|
||||
for _ in range(20):
|
||||
from_token = ""
|
||||
if prev_token:
|
||||
|
@ -670,7 +669,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
query = ""
|
||||
if key:
|
||||
query = "?key=" + six.moves.urllib.parse.quote_plus(key.encode("utf-8"))
|
||||
query = "?key=" + urllib.parse.quote_plus(key.encode("utf-8"))
|
||||
|
||||
original_id = parent_id if parent_id else self.parent_id
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ import tempfile
|
|||
from binascii import unhexlify
|
||||
from io import BytesIO
|
||||
from typing import Optional
|
||||
from urllib import parse
|
||||
|
||||
from mock import Mock
|
||||
from six.moves.urllib import parse
|
||||
|
||||
import attr
|
||||
import PIL.Image as Image
|
||||
|
|
|
@ -2,8 +2,6 @@ import json
|
|||
import logging
|
||||
from io import BytesIO
|
||||
|
||||
from six import text_type
|
||||
|
||||
import attr
|
||||
from zope.interface import implementer
|
||||
|
||||
|
@ -174,7 +172,7 @@ def make_request(
|
|||
if not path.startswith(b"/"):
|
||||
path = b"/" + path
|
||||
|
||||
if isinstance(content, text_type):
|
||||
if isinstance(content, str):
|
||||
content = content.encode("utf8")
|
||||
|
||||
site = FakeSite()
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
import itertools
|
||||
|
||||
from six.moves import zip
|
||||
|
||||
import attr
|
||||
|
||||
from synapse.api.constants import EventTypes, JoinRules, Membership
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from six import StringIO
|
||||
from io import StringIO
|
||||
|
||||
from twisted.internet.defer import Deferred
|
||||
from twisted.python.failure import Failure
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
import json
|
||||
|
||||
import six
|
||||
from mock import Mock
|
||||
|
||||
from twisted.test.proto_helpers import MemoryReactorClock
|
||||
|
@ -60,7 +59,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
|||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||
|
||||
self.assertTrue(channel.json_body is not None)
|
||||
self.assertIsInstance(channel.json_body["session"], six.text_type)
|
||||
self.assertIsInstance(channel.json_body["session"], str)
|
||||
|
||||
self.assertIsInstance(channel.json_body["flows"], list)
|
||||
for flow in channel.json_body["flows"]:
|
||||
|
@ -125,6 +124,6 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
|||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||
|
||||
self.assertTrue(channel.json_body is not None)
|
||||
self.assertIsInstance(channel.json_body["user_id"], six.text_type)
|
||||
self.assertIsInstance(channel.json_body["access_token"], six.text_type)
|
||||
self.assertIsInstance(channel.json_body["device_id"], six.text_type)
|
||||
self.assertIsInstance(channel.json_body["user_id"], str)
|
||||
self.assertIsInstance(channel.json_body["access_token"], str)
|
||||
self.assertIsInstance(channel.json_body["device_id"], str)
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
|
||||
import threading
|
||||
from io import StringIO
|
||||
|
||||
from mock import NonCallableMock
|
||||
from six import StringIO
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
from twisted.internet.defer import CancelledError
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import time
|
|||
import uuid
|
||||
import warnings
|
||||
from inspect import getcallargs
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from mock import Mock, patch
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
|
||||
|
|
Loading…
Reference in a new issue