Replace all remaining six usage with native Python 3 equivalents (#7704)

pull/7708/head
Dagfinn Ilmari Mannsåker 2020-06-16 13:51:47 +01:00 committed by GitHub
parent 98c4e35e3c
commit a3f11567d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
73 changed files with 111 additions and 237 deletions

1
changelog.d/7704.misc Normal file
View File

@ -0,0 +1 @@
Replace all remaining uses of `six` with native Python 3 equivalents. Contributed by @ilmari.

View File

@ -24,8 +24,6 @@ import argparse
from synapse.events import FrozenEvent from synapse.events import FrozenEvent
from synapse.util.frozenutils import unfreeze from synapse.util.frozenutils import unfreeze
from six import string_types
def make_graph(file_name, room_id, file_prefix, limit): def make_graph(file_name, room_id, file_prefix, limit):
print("Reading lines") 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(): for key, value in unfreeze(event.get_dict()["content"]).items():
if value is None: if value is None:
value = "<null>" value = "<null>"
elif isinstance(value, string_types): elif isinstance(value, str):
pass pass
else: else:
value = json.dumps(value) value = json.dumps(value)

View File

@ -21,8 +21,7 @@ import argparse
import base64 import base64
import json import json
import sys import sys
from urllib import parse as urlparse
from six.moves.urllib import parse as urlparse
import nacl.signing import nacl.signing
import requests import requests

View File

@ -23,8 +23,6 @@ import sys
import time import time
import traceback import traceback
from six import string_types
import yaml import yaml
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
@ -635,7 +633,7 @@ class Porter(object):
return bool(col) return bool(col)
if isinstance(col, bytes): if isinstance(col, bytes):
return bytearray(col) return bytearray(col)
elif isinstance(col, string_types) and "\0" in col: elif isinstance(col, str) and "\0" in col:
logger.warning( logger.warning(
"DROPPING ROW: NUL value in table %s col %s: %r", "DROPPING ROW: NUL value in table %s col %s: %r",
table, table,

View File

@ -31,7 +31,7 @@ sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY default_section=THIRDPARTY
known_first_party = synapse known_first_party = synapse
known_tests=tests known_tests=tests
known_compat = mock,six known_compat = mock
known_twisted=twisted,OpenSSL known_twisted=twisted,OpenSSL
multi_line_output=3 multi_line_output=3
include_trailing_comma=true include_trailing_comma=true

View File

@ -23,8 +23,6 @@ import hmac
import logging import logging
import sys import sys
from six.moves import input
import requests as _requests import requests as _requests
import yaml import yaml

View File

@ -17,10 +17,9 @@
"""Contains exceptions and error codes.""" """Contains exceptions and error codes."""
import logging import logging
from http import HTTPStatus
from typing import Dict, List from typing import Dict, List
from six.moves import http_client
from canonicaljson import json from canonicaljson import json
from twisted.web import http from twisted.web import http
@ -173,7 +172,7 @@ class ConsentNotGivenError(SynapseError):
consent_url (str): The URL where the user can give their consent consent_url (str): The URL where the user can give their consent
""" """
super(ConsentNotGivenError, self).__init__( 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 self._consent_uri = consent_uri
@ -193,7 +192,7 @@ class UserDeactivatedError(SynapseError):
msg (str): The human-readable error message msg (str): The human-readable error message
""" """
super(UserDeactivatedError, self).__init__( super(UserDeactivatedError, self).__init__(
code=http_client.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED code=HTTPStatus.FORBIDDEN, msg=msg, errcode=Codes.USER_DEACTIVATED
) )

View File

@ -17,8 +17,6 @@
# limitations under the License. # limitations under the License.
from typing import List from typing import List
from six import text_type
import jsonschema import jsonschema
from canonicaljson import json from canonicaljson import json
from jsonschema import FormatChecker from jsonschema import FormatChecker
@ -313,7 +311,7 @@ class Filter(object):
content = event.get("content", {}) content = event.get("content", {})
# check if there is a string url field in the content for filtering purposes # 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, []) labels = content.get(EventContentFields.LABELS, [])
return self.check_fields(room_id, sender, ev_type, labels, contains_url) return self.check_fields(room_id, sender, ev_type, labels, contains_url)

View File

@ -17,8 +17,7 @@
"""Contains the URL paths to prefix various aspects of the server with. """ """Contains the URL paths to prefix various aspects of the server with. """
import hmac import hmac
from hashlib import sha256 from hashlib import sha256
from urllib.parse import urlencode
from six.moves.urllib.parse import urlencode
from synapse.config import ConfigError from synapse.config import ConfigError

View File

@ -15,8 +15,6 @@
import logging import logging
import re import re
from six import string_types
from twisted.internet import defer from twisted.internet import defer
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
@ -156,7 +154,7 @@ class ApplicationService(object):
) )
regex = regex_obj.get("regex") regex = regex_obj.get("regex")
if isinstance(regex, string_types): if isinstance(regex, str):
regex_obj["regex"] = re.compile(regex) # Pre-compile regex regex_obj["regex"] = re.compile(regex) # Pre-compile regex
else: else:
raise ValueError("Expected string for 'regex' in ns '%s'" % ns) raise ValueError("Expected string for 'regex' in ns '%s'" % ns)

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
import urllib
from six.moves import urllib
from prometheus_client import Counter from prometheus_client import Counter

View File

@ -22,8 +22,6 @@ from collections import OrderedDict
from textwrap import dedent from textwrap import dedent
from typing import Any, MutableMapping, Optional from typing import Any, MutableMapping, Optional
from six import integer_types
import yaml import yaml
@ -117,7 +115,7 @@ class Config(object):
@staticmethod @staticmethod
def parse_size(value): def parse_size(value):
if isinstance(value, integer_types): if isinstance(value, int):
return value return value
sizes = {"K": 1024, "M": 1024 * 1024} sizes = {"K": 1024, "M": 1024 * 1024}
size = 1 size = 1
@ -129,7 +127,7 @@ class Config(object):
@staticmethod @staticmethod
def parse_duration(value): def parse_duration(value):
if isinstance(value, integer_types): if isinstance(value, int):
return value return value
second = 1000 second = 1000
minute = 60 * second minute = 60 * second

View File

@ -14,9 +14,7 @@
import logging import logging
from typing import Dict from typing import Dict
from urllib import parse as urlparse
from six import string_types
from six.moves.urllib import parse as urlparse
import yaml import yaml
from netaddr import IPSet from netaddr import IPSet
@ -98,17 +96,14 @@ def load_appservices(hostname, config_files):
def _load_appservice(hostname, as_info, config_filename): def _load_appservice(hostname, as_info, config_filename):
required_string_fields = ["id", "as_token", "hs_token", "sender_localpart"] required_string_fields = ["id", "as_token", "hs_token", "sender_localpart"]
for field in required_string_fields: 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( raise KeyError(
"Required string field: '%s' (%s)" % (field, config_filename) "Required string field: '%s' (%s)" % (field, config_filename)
) )
# 'url' must either be a string or explicitly null, not missing # 'url' must either be a string or explicitly null, not missing
# to avoid accidentally turning off push for ASes. # to avoid accidentally turning off push for ASes.
if ( if not isinstance(as_info.get("url"), str) and as_info.get("url", "") is not None:
not isinstance(as_info.get("url"), string_types)
and as_info.get("url", "") is not None
):
raise KeyError( raise KeyError(
"Required string field or explicit null: 'url' (%s)" % (config_filename,) "Required string field or explicit null: 'url' (%s)" % (config_filename,)
) )
@ -138,7 +133,7 @@ def _load_appservice(hostname, as_info, config_filename):
ns, ns,
regex_obj, 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) raise ValueError("Missing/bad type 'regex' key in %s", regex_obj)
if not isinstance(regex_obj.get("exclusive"), bool): if not isinstance(regex_obj.get("exclusive"), bool):
raise ValueError( raise ValueError(

View File

@ -20,8 +20,6 @@ from datetime import datetime
from hashlib import sha256 from hashlib import sha256
from typing import List from typing import List
import six
from unpaddedbase64 import encode_base64 from unpaddedbase64 import encode_base64
from OpenSSL import SSL, crypto from OpenSSL import SSL, crypto
@ -59,7 +57,7 @@ class TlsConfig(Config):
logger.warning(ACME_SUPPORT_ENABLED_WARN) logger.warning(ACME_SUPPORT_ENABLED_WARN)
# hyperlink complains on py2 if this is not a Unicode # 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") acme_config.get("url", "https://acme-v01.api.letsencrypt.org/directory")
) )
self.acme_port = acme_config.get("port", 80) self.acme_port = acme_config.get("port", 80)

View File

@ -15,11 +15,9 @@
# limitations under the License. # limitations under the License.
import logging import logging
import urllib
from collections import defaultdict from collections import defaultdict
import six
from six.moves import urllib
import attr import attr
from signedjson.key import ( from signedjson.key import (
decode_verify_key_bytes, decode_verify_key_bytes,
@ -661,7 +659,7 @@ class PerspectivesKeyFetcher(BaseV2KeyFetcher):
for response in query_response["server_keys"]: for response in query_response["server_keys"]:
# do this first, so that we can give useful errors thereafter # do this first, so that we can give useful errors thereafter
server_name = response.get("server_name") server_name = response.get("server_name")
if not isinstance(server_name, six.string_types): if not isinstance(server_name, str):
raise KeyLookupError( raise KeyLookupError(
"Malformed response from key notary server %s: invalid server_name" "Malformed response from key notary server %s: invalid server_name"
% (perspective_name,) % (perspective_name,)

View File

@ -16,8 +16,6 @@ import collections
import re import re
from typing import Any, Mapping, Union from typing import Any, Mapping, Union
from six import string_types
from frozendict import frozendict from frozendict import frozendict
from twisted.internet import defer from twisted.internet import defer
@ -318,7 +316,7 @@ def serialize_event(
if only_event_fields: if only_event_fields:
if not isinstance(only_event_fields, list) or not all( 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") raise TypeError("only_event_fields must be a list of strings")
d = only_fields(d, only_event_fields) d = only_fields(d, only_event_fields)

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six import integer_types, string_types
from synapse.api.constants import MAX_ALIAS_LENGTH, EventTypes, Membership from synapse.api.constants import MAX_ALIAS_LENGTH, EventTypes, Membership
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
from synapse.api.room_versions import EventFormatVersions from synapse.api.room_versions import EventFormatVersions
@ -53,7 +51,7 @@ class EventValidator(object):
event_strings = ["origin"] event_strings = ["origin"]
for s in event_strings: 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,)) raise SynapseError(400, "'%s' not a string type" % (s,))
# Depending on the room version, ensure the data is spec compliant JSON. # 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") max_lifetime = event.content.get("max_lifetime")
if min_lifetime is not None: if min_lifetime is not None:
if not isinstance(min_lifetime, integer_types): if not isinstance(min_lifetime, int):
raise SynapseError( raise SynapseError(
code=400, code=400,
msg="'min_lifetime' must be an integer", msg="'min_lifetime' must be an integer",
@ -124,7 +122,7 @@ class EventValidator(object):
) )
if max_lifetime is not None: if max_lifetime is not None:
if not isinstance(max_lifetime, integer_types): if not isinstance(max_lifetime, int):
raise SynapseError( raise SynapseError(
code=400, code=400,
msg="'max_lifetime' must be an integer", msg="'max_lifetime' must be an integer",
@ -183,7 +181,7 @@ class EventValidator(object):
strings.append("state_key") strings.append("state_key")
for s in strings: 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,)) raise SynapseError(400, "Not '%s' a string type" % (s,))
RoomID.from_string(event.room_id) RoomID.from_string(event.room_id)
@ -223,7 +221,7 @@ class EventValidator(object):
for s in keys: for s in keys:
if s not in d: if s not in d:
raise SynapseError(400, "'%s' not in content" % (s,)) 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,)) raise SynapseError(400, "'%s' not a string type" % (s,))
def _ensure_state_event(self, event): def _ensure_state_event(self, event):

View File

@ -17,8 +17,6 @@ import logging
from collections import namedtuple from collections import namedtuple
from typing import Iterable, List from typing import Iterable, List
import six
from twisted.internet import defer from twisted.internet import defer
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
from twisted.python.failure import Failure from twisted.python.failure import Failure
@ -294,7 +292,7 @@ def event_from_pdu_json(
assert_params_in_dict(pdu_json, ("type", "depth")) assert_params_in_dict(pdu_json, ("type", "depth"))
depth = pdu_json["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) raise SynapseError(400, "Depth %r not an intger" % (depth,), Codes.BAD_JSON)
if depth < 0: if depth < 0:

View File

@ -17,8 +17,6 @@
import logging import logging
from typing import Any, Callable, Dict, List, Match, Optional, Tuple, Union from typing import Any, Callable, Dict, List, Match, Optional, Tuple, Union
import six
from canonicaljson import json from canonicaljson import json
from prometheus_client import Counter 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: 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( logger.warning(
"Ignoring non-str ACL entry '%s' (is %s)", acl_entry, type(acl_entry) "Ignoring non-str ACL entry '%s' (is %s)", acl_entry, type(acl_entry)
) )

View File

@ -15,10 +15,9 @@
# limitations under the License. # limitations under the License.
import logging import logging
import urllib
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from six.moves import urllib
from twisted.internet import defer from twisted.internet import defer
from synapse.api.constants import Membership from synapse.api.constants import Membership

View File

@ -17,8 +17,6 @@
import logging import logging
from six import string_types
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
from synapse.types import GroupID, RoomID, UserID, get_domain_from_id from synapse.types import GroupID, RoomID, UserID, get_domain_from_id
from synapse.util.async_helpers import concurrently_execute 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"): for keyname in ("name", "avatar_url", "short_description", "long_description"):
if keyname in content: if keyname in content:
value = content[keyname] value = content[keyname]
if not isinstance(value, string_types): if not isinstance(value, str):
raise SynapseError(400, "%r value is not a string" % (keyname,)) raise SynapseError(400, "%r value is not a string" % (keyname,))
profile[keyname] = value profile[keyname] = value

View File

@ -14,11 +14,10 @@
# limitations under the License. # limitations under the License.
import logging import logging
import urllib
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from typing import Dict, Optional, Tuple from typing import Dict, Optional, Tuple
from six.moves import urllib
from twisted.web.client import PartialDownloadError from twisted.web.client import PartialDownloadError
from synapse.api.errors import Codes, LoginError from synapse.api.errors import Codes, LoginError

View File

@ -19,10 +19,9 @@
import itertools import itertools
import logging import logging
from http import HTTPStatus
from typing import Dict, Iterable, List, Optional, Sequence, Tuple from typing import Dict, Iterable, List, Optional, Sequence, Tuple
from six.moves import http_client, zip
import attr import attr
from signedjson.key import decode_verify_key_bytes from signedjson.key import decode_verify_key_bytes
from signedjson.sign import verify_signed_json from signedjson.sign import verify_signed_json
@ -1194,7 +1193,7 @@ class FederationHandler(BaseHandler):
ev.event_id, ev.event_id,
len(ev.prev_event_ids()), 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: if len(ev.auth_event_ids()) > 10:
logger.warning( logger.warning(
@ -1202,7 +1201,7 @@ class FederationHandler(BaseHandler):
ev.event_id, ev.event_id,
len(ev.auth_event_ids()), 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): async def send_invite(self, target_host, event):
""" Sends the invite to the remote server for signing. """ 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 # block any attempts to invite the server notices mxid
if event.state_key == self._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. # 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 # (this may get overwritten if we later get a different room version in a

View File

@ -17,8 +17,6 @@
import logging import logging
from typing import Optional, Tuple from typing import Optional, Tuple
from six import string_types
from canonicaljson import encode_canonical_json, json from canonicaljson import encode_canonical_json, json
from twisted.internet import defer from twisted.internet import defer
@ -715,7 +713,7 @@ class EventCreationHandler(object):
spam_error = self.spam_checker.check_event_for_spam(event) spam_error = self.spam_checker.check_event_for_spam(event)
if spam_error: if spam_error:
if not isinstance(spam_error, string_types): if not isinstance(spam_error, str):
spam_error = "Spam is not permitted here" spam_error = "Spam is not permitted here"
raise SynapseError(403, spam_error, Codes.FORBIDDEN) raise SynapseError(403, spam_error, Codes.FORBIDDEN)

View File

@ -15,8 +15,6 @@
import logging import logging
from six import raise_from
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import ( from synapse.api.errors import (
@ -84,7 +82,7 @@ class BaseProfileHandler(BaseHandler):
) )
return result return result
except RequestSendFailed as e: 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: except HttpResponseException as e:
raise e.to_synapse_error() raise e.to_synapse_error()
@ -135,7 +133,7 @@ class BaseProfileHandler(BaseHandler):
ignore_backoff=True, ignore_backoff=True,
) )
except RequestSendFailed as e: 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: except HttpResponseException as e:
raise e.to_synapse_error() raise e.to_synapse_error()
@ -212,7 +210,7 @@ class BaseProfileHandler(BaseHandler):
ignore_backoff=True, ignore_backoff=True,
) )
except RequestSendFailed as e: 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: except HttpResponseException as e:
raise e.to_synapse_error() raise e.to_synapse_error()

View File

@ -24,8 +24,6 @@ import string
from collections import OrderedDict from collections import OrderedDict
from typing import Tuple from typing import Tuple
from six import string_types
from synapse.api.constants import ( from synapse.api.constants import (
EventTypes, EventTypes,
JoinRules, JoinRules,
@ -595,7 +593,7 @@ class RoomCreationHandler(BaseHandler):
"room_version", self.config.default_room_version.identifier "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) raise SynapseError(400, "room_version must be a string", Codes.BAD_JSON)
room_version = KNOWN_ROOM_VERSIONS.get(room_version_id) room_version = KNOWN_ROOM_VERSIONS.get(room_version_id)

View File

@ -17,10 +17,9 @@
import abc import abc
import logging import logging
from http import HTTPStatus
from typing import Dict, Iterable, List, Optional, Tuple from typing import Dict, Iterable, List, Optional, Tuple
from six.moves import http_client
from synapse import types from synapse import types
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import AuthError, Codes, SynapseError from synapse.api.errors import AuthError, Codes, SynapseError
@ -361,7 +360,7 @@ class RoomMemberHandler(object):
if effective_membership_state == Membership.INVITE: if effective_membership_state == Membership.INVITE:
# block any attempts to invite the server notices mxid # block any attempts to invite the server notices mxid
if target.to_string() == self._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 block_invite = False
@ -444,7 +443,7 @@ class RoomMemberHandler(object):
is_blocked = await self._is_server_notice_room(room_id) is_blocked = await self._is_server_notice_room(room_id)
if is_blocked: if is_blocked:
raise SynapseError( raise SynapseError(
http_client.FORBIDDEN, HTTPStatus.FORBIDDEN,
"You cannot reject this invite", "You cannot reject this invite",
errcode=Codes.CANNOT_LEAVE_SERVER_NOTICE_ROOM, errcode=Codes.CANNOT_LEAVE_SERVER_NOTICE_ROOM,
) )

View File

@ -15,11 +15,9 @@
# limitations under the License. # limitations under the License.
import logging import logging
import urllib
from io import BytesIO from io import BytesIO
from six import raise_from, text_type
from six.moves import urllib
import treq import treq
from canonicaljson import encode_canonical_json, json from canonicaljson import encode_canonical_json, json
from netaddr import IPAddress from netaddr import IPAddress
@ -577,7 +575,7 @@ class SimpleHttpClient(object):
# This can happen e.g. because the body is too large. # This can happen e.g. because the body is too large.
raise raise
except Exception as e: 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 ( return (
length, length,
@ -638,7 +636,7 @@ def encode_urlencode_args(args):
def encode_urlencode_arg(arg): def encode_urlencode_arg(arg):
if isinstance(arg, text_type): if isinstance(arg, str):
return arg.encode("utf-8") return arg.encode("utf-8")
elif isinstance(arg, list): elif isinstance(arg, list):
return [encode_urlencode_arg(i) for i in arg] return [encode_urlencode_arg(i) for i in arg]

View File

@ -17,11 +17,9 @@ import cgi
import logging import logging
import random import random
import sys import sys
import urllib
from io import BytesIO from io import BytesIO
from six import raise_from, string_types
from six.moves import urllib
import attr import attr
import treq import treq
from canonicaljson import encode_canonical_json from canonicaljson import encode_canonical_json
@ -432,10 +430,10 @@ class MatrixFederationHttpClient(object):
except TimeoutError as e: except TimeoutError as e:
raise RequestSendFailed(e, can_retry=True) from e raise RequestSendFailed(e, can_retry=True) from e
except DNSLookupError as 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: except Exception as e:
logger.info("Failed to send request: %s", 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( incoming_responses_counter.labels(
request.method, response.code request.method, response.code
@ -487,7 +485,7 @@ class MatrixFederationHttpClient(object):
# Retry if the error is a 429 (Too Many Requests), # Retry if the error is a 429 (Too Many Requests),
# otherwise just raise a standard HttpResponseException # otherwise just raise a standard HttpResponseException
if response.code == 429: if response.code == 429:
raise_from(RequestSendFailed(e, can_retry=True), e) raise RequestSendFailed(e, can_retry=True) from e
else: else:
raise e raise e
@ -998,7 +996,7 @@ def encode_query_args(args):
encoded_args = {} encoded_args = {}
for k, vs in args.items(): for k, vs in args.items():
if isinstance(vs, string_types): if isinstance(vs, str):
vs = [vs] vs = [vs]
encoded_args[k] = [v.encode("UTF-8") for v in vs] encoded_args[k] = [v.encode("UTF-8") for v in vs]

View File

@ -16,10 +16,10 @@
import collections import collections
import html import html
import http.client
import logging import logging
import types import types
import urllib import urllib
from http import HTTPStatus
from io import BytesIO from io import BytesIO
from typing import Awaitable, Callable, TypeVar, Union from typing import Awaitable, Callable, TypeVar, Union
@ -188,7 +188,7 @@ def return_html_error(
exc_info=(f.type, f.value, f.getTracebackObject()), exc_info=(f.type, f.value, f.getTracebackObject()),
) )
else: else:
code = http.HTTPStatus.INTERNAL_SERVER_ERROR code = HTTPStatus.INTERNAL_SERVER_ERROR
msg = "Internal server error" msg = "Internal server error"
logger.error( logger.error(

View File

@ -16,8 +16,7 @@
import logging import logging
import traceback import traceback
from io import StringIO
from six import StringIO
class LogFormatter(logging.Formatter): class LogFormatter(logging.Formatter):

View File

@ -17,12 +17,11 @@ import email.mime.multipart
import email.utils import email.utils
import logging import logging
import time import time
import urllib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from typing import Iterable, List, TypeVar from typing import Iterable, List, TypeVar
from six.moves import urllib
import bleach import bleach
import jinja2 import jinja2

View File

@ -18,8 +18,6 @@ import logging
import re import re
from typing import Pattern from typing import Pattern
from six import string_types
from synapse.events import EventBase from synapse.events import EventBase
from synapse.types import UserID from synapse.types import UserID
from synapse.util.caches import register_cache from synapse.util.caches import register_cache
@ -244,7 +242,7 @@ def _flatten_dict(d, prefix=[], result=None):
if result is None: if result is None:
result = {} result = {}
for key, value in d.items(): for key, value in d.items():
if isinstance(value, string_types): if isinstance(value, str):
result[".".join(prefix + [key])] = value.lower() result[".".join(prefix + [key])] = value.lower()
elif hasattr(value, "items"): elif hasattr(value, "items"):
_flatten_dict(value, prefix=(prefix + [key]), result=result) _flatten_dict(value, prefix=(prefix + [key]), result=result)

View File

@ -66,7 +66,6 @@ REQUIREMENTS = [
"pymacaroons>=0.13.0", "pymacaroons>=0.13.0",
"msgpack>=0.5.2", "msgpack>=0.5.2",
"phonenumbers>=8.2.0", "phonenumbers>=8.2.0",
"six>=1.10",
"prometheus_client>=0.0.18,<0.8.0", "prometheus_client>=0.0.18,<0.8.0",
# we use attr.validators.deep_iterable, which arrived in 19.1.0 # we use attr.validators.deep_iterable, which arrived in 19.1.0
"attrs>=19.1.0", "attrs>=19.1.0",

View File

@ -16,12 +16,10 @@
import abc import abc
import logging import logging
import re import re
import urllib
from inspect import signature from inspect import signature
from typing import Dict, List, Tuple from typing import Dict, List, Tuple
from six import raise_from
from six.moves import urllib
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import ( from synapse.api.errors import (
@ -220,7 +218,7 @@ class ReplicationEndpoint(object):
# importantly, not stack traces everywhere) # importantly, not stack traces everywhere)
raise e.to_synapse_error() raise e.to_synapse_error()
except RequestSendFailed as e: 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 return result

View File

@ -16,9 +16,7 @@ import hashlib
import hmac import hmac
import logging import logging
import re import re
from http import HTTPStatus
from six import text_type
from six.moves import http_client
from synapse.api.constants import UserTypes from synapse.api.constants import UserTypes
from synapse.api.errors import Codes, NotFoundError, SynapseError 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) await self.store.set_server_admin(target_user, set_admin_to)
if "password" in body: if "password" in body:
if ( if not isinstance(body["password"], str) or len(body["password"]) > 512:
not isinstance(body["password"], text_type)
or len(body["password"]) > 512
):
raise SynapseError(400, "Invalid password") raise SynapseError(400, "Invalid password")
else: else:
new_password = body["password"] new_password = body["password"]
@ -252,7 +247,7 @@ class UserRestServletV2(RestServlet):
password = body.get("password") password = body.get("password")
password_hash = None password_hash = None
if password is not 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") raise SynapseError(400, "Invalid password")
password_hash = await self.auth_handler.hash(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 400, "username must be specified", errcode=Codes.BAD_JSON
) )
else: else:
if ( if not isinstance(body["username"], str) or len(body["username"]) > 512:
not isinstance(body["username"], text_type)
or len(body["username"]) > 512
):
raise SynapseError(400, "Invalid username") raise SynapseError(400, "Invalid username")
username = body["username"].encode("utf-8") username = body["username"].encode("utf-8")
@ -386,7 +378,7 @@ class UserRegisterServlet(RestServlet):
) )
else: else:
password = body["password"] 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") raise SynapseError(400, "Invalid password")
password_bytes = password.encode("utf-8") password_bytes = password.encode("utf-8")
@ -477,7 +469,7 @@ class DeactivateAccountRestServlet(RestServlet):
erase = body.get("erase", False) erase = body.get("erase", False)
if not isinstance(erase, bool): if not isinstance(erase, bool):
raise SynapseError( raise SynapseError(
http_client.BAD_REQUEST, HTTPStatus.BAD_REQUEST,
"Param 'erase' must be a boolean, if given", "Param 'erase' must be a boolean, if given",
Codes.BAD_JSON, Codes.BAD_JSON,
) )

View File

@ -17,8 +17,6 @@
""" """
import logging import logging
from six import string_types
from synapse.api.errors import AuthError, SynapseError from synapse.api.errors import AuthError, SynapseError
from synapse.handlers.presence import format_user_presence_state from synapse.handlers.presence import format_user_presence_state
from synapse.http.servlet import RestServlet, parse_json_object_from_request from synapse.http.servlet import RestServlet, parse_json_object_from_request
@ -73,7 +71,7 @@ class PresenceStatusRestServlet(RestServlet):
if "status_msg" in content: if "status_msg" in content:
state["status_msg"] = content.pop("status_msg") 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.") raise SynapseError(400, "status_msg must be a string.")
if content: if content:

View File

@ -18,8 +18,7 @@
import logging import logging
import re import re
from typing import List, Optional from typing import List, Optional
from urllib import parse as urlparse
from six.moves.urllib import parse as urlparse
from canonicaljson import json from canonicaljson import json

View File

@ -15,8 +15,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging import logging
from http import HTTPStatus
from six.moves import http_client
from synapse.api.constants import LoginType from synapse.api.constants import LoginType
from synapse.api.errors import Codes, SynapseError, ThreepidValidationError from synapse.api.errors import Codes, SynapseError, ThreepidValidationError
@ -321,7 +320,7 @@ class DeactivateAccountRestServlet(RestServlet):
erase = body.get("erase", False) erase = body.get("erase", False)
if not isinstance(erase, bool): if not isinstance(erase, bool):
raise SynapseError( raise SynapseError(
http_client.BAD_REQUEST, HTTPStatus.BAD_REQUEST,
"Param 'erase' must be a boolean, if given", "Param 'erase' must be a boolean, if given",
Codes.BAD_JSON, Codes.BAD_JSON,
) )

View File

@ -18,8 +18,6 @@ import hmac
import logging import logging
from typing import List, Union from typing import List, Union
from six import string_types
import synapse import synapse
import synapse.api.auth import synapse.api.auth
import synapse.types import synapse.types
@ -413,7 +411,7 @@ class RegisterRestServlet(RestServlet):
# in sessions. Pull out the username/password provided to us. # in sessions. Pull out the username/password provided to us.
if "password" in body: if "password" in body:
password = body.pop("password") 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") raise SynapseError(400, "Invalid password")
self.password_policy_handler.validate_password(password) self.password_policy_handler.validate_password(password)
@ -425,10 +423,7 @@ class RegisterRestServlet(RestServlet):
desired_username = None desired_username = None
if "username" in body: if "username" in body:
if ( if not isinstance(body["username"], str) or len(body["username"]) > 512:
not isinstance(body["username"], string_types)
or len(body["username"]) > 512
):
raise SynapseError(400, "Invalid username") raise SynapseError(400, "Invalid username")
desired_username = body["username"] desired_username = body["username"]
@ -453,7 +448,7 @@ class RegisterRestServlet(RestServlet):
access_token = self.auth.get_access_token_from_request(request) 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( result = await self._do_appservice_registration(
desired_username, access_token, body desired_username, access_token, body
) )

View File

@ -14,9 +14,7 @@
# limitations under the License. # limitations under the License.
import logging import logging
from http import HTTPStatus
from six import string_types
from six.moves import http_client
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
from synapse.http.servlet import ( from synapse.http.servlet import (
@ -47,15 +45,15 @@ class ReportEventRestServlet(RestServlet):
body = parse_json_object_from_request(request) body = parse_json_object_from_request(request)
assert_params_in_dict(body, ("reason", "score")) assert_params_in_dict(body, ("reason", "score"))
if not isinstance(body["reason"], string_types): if not isinstance(body["reason"], str):
raise SynapseError( raise SynapseError(
http_client.BAD_REQUEST, HTTPStatus.BAD_REQUEST,
"Param 'reason' must be a string", "Param 'reason' must be a string",
Codes.BAD_JSON, Codes.BAD_JSON,
) )
if not isinstance(body["score"], int): if not isinstance(body["score"], int):
raise SynapseError( raise SynapseError(
http_client.BAD_REQUEST, HTTPStatus.BAD_REQUEST,
"Param 'score' must be an integer", "Param 'score' must be an integer",
Codes.BAD_JSON, Codes.BAD_JSON,
) )

View File

@ -16,10 +16,9 @@
import hmac import hmac
import logging import logging
from hashlib import sha256 from hashlib import sha256
from http import HTTPStatus
from os import path from os import path
from six.moves import http_client
import jinja2 import jinja2
from jinja2 import TemplateNotFound from jinja2 import TemplateNotFound
@ -223,4 +222,4 @@ class ConsentResource(DirectServeResource):
) )
if not compare_digest(want_mac, userhmac): if not compare_digest(want_mac, userhmac):
raise SynapseError(http_client.FORBIDDEN, "HMAC incorrect") raise SynapseError(HTTPStatus.FORBIDDEN, "HMAC incorrect")

View File

@ -16,8 +16,7 @@
import logging import logging
import os import os
import urllib
from six.moves import urllib
from twisted.internet import defer from twisted.internet import defer
from twisted.protocols.basic import FileSender from twisted.protocols.basic import FileSender

View File

@ -17,9 +17,6 @@ import contextlib
import logging import logging
import os import os
import shutil import shutil
import sys
import six
from twisted.internet import defer from twisted.internet import defer
from twisted.protocols.basic import FileSender from twisted.protocols.basic import FileSender
@ -117,12 +114,11 @@ class MediaStorage(object):
with open(fname, "wb") as f: with open(fname, "wb") as f:
yield f, fname, finish yield f, fname, finish
except Exception: except Exception:
t, v, tb = sys.exc_info()
try: try:
os.remove(fname) os.remove(fname)
except Exception: except Exception:
pass pass
six.reraise(t, v, tb) raise
if not finished_called: if not finished_called:
raise Exception("Finished callback not called") raise Exception("Finished callback not called")

View File

@ -24,10 +24,7 @@ import shutil
import sys import sys
import traceback import traceback
from typing import Dict, Optional from typing import Dict, Optional
from urllib import parse as urlparse
import six
from six import string_types
from six.moves import urllib_parse as urlparse
from canonicaljson import json 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 # It may be stored as text in the database, not as bytes (such as
# PostgreSQL). If so, encode it back before handing it on. # PostgreSQL). If so, encode it back before handing it on.
og = cache_result["og"] og = cache_result["og"]
if isinstance(og, six.text_type): if isinstance(og, str):
og = og.encode("utf8") og = og.encode("utf8")
return og return og
@ -631,7 +628,7 @@ def _iterate_over_text(tree, *tags_to_ignore):
if el is None: if el is None:
return return
if isinstance(el, string_types): if isinstance(el, str):
yield el yield el
elif el.tag not in tags_to_ignore: elif el.tag not in tags_to_ignore:
# el.text is the text before the first child, so we can immediately # el.text is the text before the first child, so we can immediately

View File

@ -14,8 +14,6 @@
# limitations under the License. # limitations under the License.
import logging import logging
from six import string_types
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from synapse.api.urls import ConsentURIBuilder from synapse.api.urls import ConsentURIBuilder
from synapse.config import ConfigError from synapse.config import ConfigError
@ -118,7 +116,7 @@ def copy_with_str_subst(x, substitutions):
Returns: Returns:
copy of x copy of x
""" """
if isinstance(x, string_types): if isinstance(x, str):
return x % substitutions return x % substitutions
if isinstance(x, dict): if isinstance(x, dict):
return {k: copy_with_str_subst(v, substitutions) for (k, v) in x.items()} return {k: copy_with_str_subst(v, substitutions) for (k, v) in x.items()}

View File

@ -14,10 +14,9 @@
# limitations under the License. # limitations under the License.
import itertools import itertools
import logging import logging
from queue import Empty, PriorityQueue
from typing import Dict, List, Optional, Set, Tuple from typing import Dict, List, Optional, Set, Tuple
from six.moves.queue import Empty, PriorityQueue
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import StoreError from synapse.api.errors import StoreError

View File

@ -21,9 +21,6 @@ from collections import OrderedDict, namedtuple
from functools import wraps from functools import wraps
from typing import TYPE_CHECKING, Dict, Iterable, List, Tuple from typing import TYPE_CHECKING, Dict, Iterable, List, Tuple
from six import integer_types, text_type
from six.moves import range
import attr import attr
from canonicaljson import json from canonicaljson import json
from prometheus_client import Counter from prometheus_client import Counter
@ -893,8 +890,7 @@ class PersistEventsStore:
"received_ts": self._clock.time_msec(), "received_ts": self._clock.time_msec(),
"sender": event.sender, "sender": event.sender,
"contains_url": ( "contains_url": (
"url" in event.content "url" in event.content and isinstance(event.content["url"], str)
and isinstance(event.content["url"], text_type)
), ),
} }
for event, _ in events_and_contexts for event, _ in events_and_contexts
@ -1345,10 +1341,10 @@ class PersistEventsStore:
): ):
if ( if (
"min_lifetime" in event.content "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 ( ) or (
"max_lifetime" in event.content "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. # Ignore the event if one of the value isn't an integer.
return return

View File

@ -15,8 +15,6 @@
import logging import logging
from six import text_type
from canonicaljson import json from canonicaljson import json
from twisted.internet import defer from twisted.internet import defer
@ -133,7 +131,7 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
contains_url = "url" in content contains_url = "url" in content
if contains_url: if contains_url:
contains_url &= isinstance(content["url"], text_type) contains_url &= isinstance(content["url"], str)
except (KeyError, AttributeError): except (KeyError, AttributeError):
# If the event is missing a necessary field then # If the event is missing a necessary field then
# skip over it. # skip over it.

View File

@ -13,8 +13,6 @@
# limitations under the License. # limitations under the License.
import logging import logging
from six.moves import range
from synapse.config.appservice import load_appservices from synapse.config.appservice import load_appservices
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -17,8 +17,6 @@ import logging
import re import re
from collections import namedtuple from collections import namedtuple
from six import string_types
from canonicaljson import json from canonicaljson import json
from twisted.internet import defer from twisted.internet import defer
@ -180,7 +178,7 @@ class SearchBackgroundUpdateStore(SearchWorkerStore):
# skip over it. # skip over it.
continue continue
if not isinstance(value, string_types): if not isinstance(value, str):
# If the event body, name or topic isn't a string # If the event body, name or topic isn't a string
# then skip over it # then skip over it
continue continue

View File

@ -40,8 +40,6 @@ import abc
import logging import logging
from collections import namedtuple from collections import namedtuple
from six.moves import range
from twisted.internet import defer from twisted.internet import defer
from synapse.logging.context import make_deferred_yieldable, run_in_background from synapse.logging.context import make_deferred_yieldable, run_in_background

View File

@ -16,8 +16,6 @@
import logging import logging
from six.moves import range
from canonicaljson import json from canonicaljson import json
from twisted.internet import defer from twisted.internet import defer

View File

@ -17,8 +17,6 @@ import logging
from collections import namedtuple from collections import namedtuple
from typing import Dict, Iterable, List, Set, Tuple from typing import Dict, Iterable, List, Set, Tuple
from six.moves import range
from twisted.internet import defer from twisted.internet import defer
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes

View File

@ -16,6 +16,7 @@
# limitations under the License. # limitations under the License.
import logging import logging
import time import time
from sys import intern
from time import monotonic as monotonic_time from time import monotonic as monotonic_time
from typing import ( from typing import (
Any, Any,
@ -29,8 +30,6 @@ from typing import (
TypeVar, TypeVar,
) )
from six.moves import intern, range
from prometheus_client import Histogram from prometheus_client import Histogram
from twisted.enterprise import adbapi from twisted.enterprise import adbapi

View File

@ -20,8 +20,6 @@ import logging
from collections import deque, namedtuple from collections import deque, namedtuple
from typing import Iterable, List, Optional, Set, Tuple from typing import Iterable, List, Optional, Set, Tuple
from six.moves import range
from prometheus_client import Counter, Histogram from prometheus_client import Counter, Histogram
from twisted.internet import defer from twisted.internet import defer

View File

@ -19,8 +19,6 @@ import logging
from contextlib import contextmanager from contextlib import contextmanager
from typing import Dict, Sequence, Set, Union from typing import Dict, Sequence, Set, Union
from six.moves import range
import attr import attr
from twisted.internet import defer from twisted.internet import defer

View File

@ -17,8 +17,6 @@ import logging
import math import math
from typing import Dict, FrozenSet, List, Mapping, Optional, Set, Union from typing import Dict, FrozenSet, List, Mapping, Optional, Set, Union
from six import integer_types
from sortedcontainers import SortedDict from sortedcontainers import SortedDict
from synapse.types import Collection from synapse.types import Collection
@ -88,7 +86,7 @@ class StreamChangeCache:
def has_entity_changed(self, entity: EntityType, stream_pos: int) -> bool: def has_entity_changed(self, entity: EntityType, stream_pos: int) -> bool:
"""Returns True if the entity may have been updated since stream_pos """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: if stream_pos < self._earliest_known_stream_pos:
self.metrics.inc_misses() self.metrics.inc_misses()

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six.moves import queue import queue
from twisted.internet import threads from twisted.internet import threads

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six import binary_type, text_type
from canonicaljson import json from canonicaljson import json
from frozendict import frozendict from frozendict import frozendict
@ -26,7 +24,7 @@ def freeze(o):
if isinstance(o, frozendict): if isinstance(o, frozendict):
return o return o
if isinstance(o, (binary_type, text_type)): if isinstance(o, (bytes, str)):
return o return o
try: try:
@ -41,7 +39,7 @@ def unfreeze(o):
if isinstance(o, (dict, frozendict)): if isinstance(o, (dict, frozendict)):
return dict({k: unfreeze(v) for k, v in o.items()}) 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 return o
try: try:

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six.moves import range
class _Entry(object): class _Entry(object):
__slots__ = ["end_key", "queue"] __slots__ = ["end_key", "queue"]

View File

@ -16,8 +16,6 @@
import logging import logging
import operator import operator
from six.moves import map
from twisted.internet import defer from twisted.internet import defer
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership

6
synctl
View File

@ -26,8 +26,6 @@ import subprocess
import sys import sys
import time import time
from six import iteritems
import yaml import yaml
from synapse.config import find_config_files from synapse.config import find_config_files
@ -251,7 +249,7 @@ def main():
os.environ["SYNAPSE_CACHE_FACTOR"] = str(cache_factor) os.environ["SYNAPSE_CACHE_FACTOR"] = str(cache_factor)
cache_factors = config.get("synctl_cache_factors", {}) 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) os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)
worker_configfiles = [] worker_configfiles = []
@ -362,7 +360,7 @@ def main():
if worker.cache_factor: if worker.cache_factor:
os.environ["SYNAPSE_CACHE_FACTOR"] = str(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) os.environ["SYNAPSE_CACHE_FACTOR_" + cache_name.upper()] = str(factor)
if not start_worker(worker.app, configfile, worker.configfile): if not start_worker(worker.app, configfile, worker.configfile):

View File

@ -19,9 +19,9 @@
"""Tests REST events for /rooms paths.""" """Tests REST events for /rooms paths."""
import json import json
from urllib import parse as urlparse
from mock import Mock from mock import Mock
from six.moves.urllib import parse as urlparse
from twisted.internet import defer from twisted.internet import defer

View File

@ -15,8 +15,7 @@
import itertools import itertools
import json import json
import urllib
import six
from synapse.api.constants import EventTypes, RelationTypes from synapse.api.constants import EventTypes, RelationTypes
from synapse.rest import admin 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 # Make sure next_batch has something in it that looks like it could be a
# valid token. # valid token.
self.assertIsInstance( 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): def test_repeated_paginate_relations(self):
@ -278,7 +277,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
prev_token = None prev_token = None
found_event_ids = [] 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): for _ in range(20):
from_token = "" from_token = ""
if prev_token: if prev_token:
@ -670,7 +669,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
query = "" query = ""
if key: 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 original_id = parent_id if parent_id else self.parent_id

View File

@ -20,9 +20,9 @@ import tempfile
from binascii import unhexlify from binascii import unhexlify
from io import BytesIO from io import BytesIO
from typing import Optional from typing import Optional
from urllib import parse
from mock import Mock from mock import Mock
from six.moves.urllib import parse
import attr import attr
import PIL.Image as Image import PIL.Image as Image

View File

@ -2,8 +2,6 @@ import json
import logging import logging
from io import BytesIO from io import BytesIO
from six import text_type
import attr import attr
from zope.interface import implementer from zope.interface import implementer
@ -174,7 +172,7 @@ def make_request(
if not path.startswith(b"/"): if not path.startswith(b"/"):
path = b"/" + path path = b"/" + path
if isinstance(content, text_type): if isinstance(content, str):
content = content.encode("utf8") content = content.encode("utf8")
site = FakeSite() site = FakeSite()

View File

@ -15,8 +15,6 @@
import itertools import itertools
from six.moves import zip
import attr import attr
from synapse.api.constants import EventTypes, JoinRules, Membership from synapse.api.constants import EventTypes, JoinRules, Membership

View File

@ -14,8 +14,7 @@
import logging import logging
import re import re
from io import StringIO
from six import StringIO
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.python.failure import Failure from twisted.python.failure import Failure

View File

@ -14,7 +14,6 @@
import json import json
import six
from mock import Mock from mock import Mock
from twisted.test.proto_helpers import MemoryReactorClock 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.assertEquals(channel.result["code"], b"401", channel.result)
self.assertTrue(channel.json_body is not None) 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) self.assertIsInstance(channel.json_body["flows"], list)
for flow in channel.json_body["flows"]: 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.assertEquals(channel.result["code"], b"200", channel.result)
self.assertTrue(channel.json_body is not None) self.assertTrue(channel.json_body is not None)
self.assertIsInstance(channel.json_body["user_id"], six.text_type) self.assertIsInstance(channel.json_body["user_id"], str)
self.assertIsInstance(channel.json_body["access_token"], six.text_type) self.assertIsInstance(channel.json_body["access_token"], str)
self.assertIsInstance(channel.json_body["device_id"], six.text_type) self.assertIsInstance(channel.json_body["device_id"], str)

View File

@ -15,9 +15,9 @@
import threading import threading
from io import StringIO
from mock import NonCallableMock from mock import NonCallableMock
from six import StringIO
from twisted.internet import defer, reactor from twisted.internet import defer, reactor

View File

@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from six.moves import range
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.defer import CancelledError from twisted.internet.defer import CancelledError

View File

@ -21,9 +21,9 @@ import time
import uuid import uuid
import warnings import warnings
from inspect import getcallargs from inspect import getcallargs
from urllib import parse as urlparse
from mock import Mock, patch from mock import Mock, patch
from six.moves.urllib import parse as urlparse
from twisted.internet import defer, reactor from twisted.internet import defer, reactor