mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-12 04:52:26 +01:00
remove miscellaneous PY2 code
This commit is contained in:
parent
e6027562e2
commit
d4676910c9
6 changed files with 24 additions and 67 deletions
|
@ -19,7 +19,7 @@ import random
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from six import PY3, raise_from, string_types
|
from six import raise_from, string_types
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
@ -70,11 +70,7 @@ incoming_responses_counter = Counter(
|
||||||
|
|
||||||
MAX_LONG_RETRIES = 10
|
MAX_LONG_RETRIES = 10
|
||||||
MAX_SHORT_RETRIES = 3
|
MAX_SHORT_RETRIES = 3
|
||||||
|
|
||||||
if PY3:
|
|
||||||
MAXINT = sys.maxsize
|
MAXINT = sys.maxsize
|
||||||
else:
|
|
||||||
MAXINT = sys.maxint
|
|
||||||
|
|
||||||
|
|
||||||
_next_id = 1
|
_next_id = 1
|
||||||
|
|
|
@ -20,8 +20,6 @@ import time
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from inspect import getcallargs
|
from inspect import getcallargs
|
||||||
|
|
||||||
from six import PY3
|
|
||||||
|
|
||||||
_TIME_FUNC_ID = 0
|
_TIME_FUNC_ID = 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,12 +28,8 @@ def _log_debug_as_f(f, msg, msg_args):
|
||||||
logger = logging.getLogger(name)
|
logger = logging.getLogger(name)
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
if PY3:
|
|
||||||
lineno = f.__code__.co_firstlineno
|
lineno = f.__code__.co_firstlineno
|
||||||
pathname = f.__code__.co_filename
|
pathname = f.__code__.co_filename
|
||||||
else:
|
|
||||||
lineno = f.func_code.co_firstlineno
|
|
||||||
pathname = f.func_code.co_filename
|
|
||||||
|
|
||||||
record = logging.LogRecord(
|
record = logging.LogRecord(
|
||||||
name=name,
|
name=name,
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from prometheus_client import Counter
|
from prometheus_client import Counter
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
@ -28,9 +26,6 @@ from synapse.push import PusherConfigException
|
||||||
|
|
||||||
from . import push_rule_evaluator, push_tools
|
from . import push_rule_evaluator, push_tools
|
||||||
|
|
||||||
if six.PY3:
|
|
||||||
long = int
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
http_push_processed_counter = Counter(
|
http_push_processed_counter = Counter(
|
||||||
|
@ -318,7 +313,7 @@ class HttpPusher(object):
|
||||||
{
|
{
|
||||||
"app_id": self.app_id,
|
"app_id": self.app_id,
|
||||||
"pushkey": self.pushkey,
|
"pushkey": self.pushkey,
|
||||||
"pushkey_ts": long(self.pushkey_ts / 1000),
|
"pushkey_ts": int(self.pushkey_ts / 1000),
|
||||||
"data": self.data_minus_url,
|
"data": self.data_minus_url,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -347,7 +342,7 @@ class HttpPusher(object):
|
||||||
{
|
{
|
||||||
"app_id": self.app_id,
|
"app_id": self.app_id,
|
||||||
"pushkey": self.pushkey,
|
"pushkey": self.pushkey,
|
||||||
"pushkey_ts": long(self.pushkey_ts / 1000),
|
"pushkey_ts": int(self.pushkey_ts / 1000),
|
||||||
"data": self.data_minus_url,
|
"data": self.data_minus_url,
|
||||||
"tweaks": tweaks,
|
"tweaks": tweaks,
|
||||||
}
|
}
|
||||||
|
@ -409,7 +404,7 @@ class HttpPusher(object):
|
||||||
{
|
{
|
||||||
"app_id": self.app_id,
|
"app_id": self.app_id,
|
||||||
"pushkey": self.pushkey,
|
"pushkey": self.pushkey,
|
||||||
"pushkey_ts": long(self.pushkey_ts / 1000),
|
"pushkey_ts": int(self.pushkey_ts / 1000),
|
||||||
"data": self.data_minus_url,
|
"data": self.data_minus_url,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from six import PY3
|
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
@ -324,7 +323,6 @@ def get_filename_from_headers(headers):
|
||||||
upload_name_utf8 = upload_name_utf8[7:]
|
upload_name_utf8 = upload_name_utf8[7:]
|
||||||
# We have a filename*= section. This MUST be ASCII, and any UTF-8
|
# We have a filename*= section. This MUST be ASCII, and any UTF-8
|
||||||
# bytes are %-quoted.
|
# bytes are %-quoted.
|
||||||
if PY3:
|
|
||||||
try:
|
try:
|
||||||
# Once it is decoded, we can then unquote the %-encoded
|
# Once it is decoded, we can then unquote the %-encoded
|
||||||
# parts strictly into a unicode string.
|
# parts strictly into a unicode string.
|
||||||
|
@ -334,13 +332,6 @@ def get_filename_from_headers(headers):
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# Incorrect UTF-8.
|
# Incorrect UTF-8.
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
# On Python 2, we first unquote the %-encoded parts and then
|
|
||||||
# decode it strictly using UTF-8.
|
|
||||||
try:
|
|
||||||
upload_name = urllib.parse.unquote(upload_name_utf8).decode("utf8")
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# If there isn't check for an ascii name.
|
# If there isn't check for an ascii name.
|
||||||
if not upload_name:
|
if not upload_name:
|
||||||
|
|
|
@ -15,11 +15,9 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from sys import intern
|
||||||
from typing import Callable, Dict, Optional
|
from typing import Callable, Dict, Optional
|
||||||
|
|
||||||
import six
|
|
||||||
from six.moves import intern
|
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
from prometheus_client.core import Gauge
|
from prometheus_client.core import Gauge
|
||||||
|
|
||||||
|
@ -154,9 +152,6 @@ def intern_string(string):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if six.PY2:
|
|
||||||
string = string.encode("ascii")
|
|
||||||
|
|
||||||
return intern(string)
|
return intern(string)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
return string
|
return string
|
||||||
|
|
|
@ -19,9 +19,6 @@ import re
|
||||||
import string
|
import string
|
||||||
from collections import Iterable
|
from collections import Iterable
|
||||||
|
|
||||||
from six import PY3
|
|
||||||
from six.moves import range
|
|
||||||
|
|
||||||
from synapse.api.errors import Codes, SynapseError
|
from synapse.api.errors import Codes, SynapseError
|
||||||
|
|
||||||
_string_with_symbols = string.digits + string.ascii_letters + ".,;:^&*-_+=#~@"
|
_string_with_symbols = string.digits + string.ascii_letters + ".,;:^&*-_+=#~@"
|
||||||
|
@ -46,8 +43,6 @@ def random_string_with_symbols(length):
|
||||||
|
|
||||||
|
|
||||||
def is_ascii(s):
|
def is_ascii(s):
|
||||||
|
|
||||||
if PY3:
|
|
||||||
if isinstance(s, bytes):
|
if isinstance(s, bytes):
|
||||||
try:
|
try:
|
||||||
s.decode("ascii").encode("ascii")
|
s.decode("ascii").encode("ascii")
|
||||||
|
@ -57,15 +52,6 @@ def is_ascii(s):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
|
||||||
s.encode("ascii")
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
return False
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def assert_valid_client_secret(client_secret):
|
def assert_valid_client_secret(client_secret):
|
||||||
"""Validate that a given string matches the client_secret regex defined by the spec"""
|
"""Validate that a given string matches the client_secret regex defined by the spec"""
|
||||||
|
|
Loading…
Reference in a new issue