Skip to content

Commit

Permalink
fix conflicts and merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Nov 12, 2021
2 parents 0a704dd + 59df2b7 commit 0c63cd8
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions changelog.d/265.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use absolute imports for consistency.
1 change: 1 addition & 0 deletions changelog.d/266.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove explicit inheritance from `object` that was left over from Python 2.
1 change: 1 addition & 0 deletions changelog.d/267.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use Python 3-style super calls.
6 changes: 3 additions & 3 deletions sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent
from sygnal.utils import NotificationLoggerAdapter, json_decoder, twisted_sleep

from .exceptions import PushkinSetupException
from .notifications import (
from sygnal.exceptions import PushkinSetupException
from sygnal.notifications import (
ConcurrencyLimitedPushkin,
Device,
Notification,
Expand Down Expand Up @@ -109,7 +109,7 @@ class GcmPushkin(ConcurrencyLimitedPushkin):
} | ConcurrencyLimitedPushkin.UNDERSTOOD_CONFIG_FIELDS

def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]) -> None:
super(GcmPushkin, self).__init__(name, sygnal, config)
super().__init__(name, sygnal, config)

nonunderstood = set(self.cfg.keys()).difference(self.UNDERSTOOD_CONFIG_FIELDS)
if len(nonunderstood) > 0:
Expand Down
6 changes: 3 additions & 3 deletions sygnal/helper/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@implementer(IPolicyForHTTPS)
class ClientTLSOptionsFactory(object):
class ClientTLSOptionsFactory:
"""Factory for Twisted SSLClientConnectionCreators that are used to make connections
to remote servers for federation.
Uses one of two OpenSSL context objects for all connections, depending on whether
Expand Down Expand Up @@ -91,7 +91,7 @@ def creatorForNetloc(self, hostname, port):


@implementer(IOpenSSLClientConnectionCreator)
class SSLClientConnectionCreator(object):
class SSLClientConnectionCreator:
"""Creates openssl connection objects for client connections.
Replaces twisted.internet.ssl.ClientTLSOptions
Expand All @@ -116,7 +116,7 @@ def clientConnectionForTLS(self, tls_protocol):
return connection


class ConnectionVerifier(object):
class ConnectionVerifier:
"""Set the SNI, and do cert verification
This is a thing which is attached to the TLSMemoryBIOProtocol, and is called by
Expand Down
2 changes: 1 addition & 1 deletion sygnal/helper/proxy/connectproxyclient_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


@implementer(IStreamClientEndpoint)
class HTTPConnectProxyEndpoint(object):
class HTTPConnectProxyEndpoint:
"""An Endpoint implementation which will send a CONNECT request to an http proxy
Wraps an existing HostnameEndpoint for the proxy.
Expand Down
11 changes: 6 additions & 5 deletions sygnal/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET

from sygnal.notifications import NotificationContext
from sygnal.exceptions import (
InvalidNotificationException,
NotificationDispatchException,
)
from sygnal.notifications import Notification, NotificationContext
from sygnal.utils import NotificationLoggerAdapter, json_decoder

from .exceptions import InvalidNotificationException, NotificationDispatchException
from .notifications import Notification

logger = logging.getLogger(__name__)

NOTIFS_RECEIVED_COUNTER = Counter(
Expand Down Expand Up @@ -344,7 +345,7 @@ def log(self, request):
self.logger.info("Handled request: %s", line)


class PushGatewayApiServer(object):
class PushGatewayApiServer:
def __init__(self, sygnal):
"""
Initialises the /_matrix/push/* (Push Gateway API) server.
Expand Down
8 changes: 3 additions & 5 deletions sygnal/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

from opentracing import Span
from prometheus_client import Counter
from typing_extensions import Type

from .exceptions import (
from typing_extensions import TYPE_CHECKING, Type
from sygnal.exceptions import (
InvalidNotificationException,
NotificationDispatchException,
PushkinSetupException,
Expand Down Expand Up @@ -109,7 +108,6 @@ def __init__(self, notif):

self.devices = [Device(d) for d in notif["devices"]]


class Pushkin(abc.ABC):
def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]):
self.name = name
Expand Down Expand Up @@ -184,7 +182,7 @@ class ConcurrencyLimitedPushkin(Pushkin):
)

def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]):
super(ConcurrencyLimitedPushkin, self).__init__(name, sygnal, config)
super().__init__(name, sygnal, config)
self._concurrent_limit = config.get(
"inflight_request_limit",
ConcurrencyLimitedPushkin.DEFAULT_CONCURRENCY_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion sygnal/sygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}


class Sygnal(object):
class Sygnal:
def __init__(self, config, custom_reactor, tracer=opentracing.tracer):
"""
Object that holds state for the entirety of a Sygnal instance.
Expand Down
9 changes: 4 additions & 5 deletions sygnal/webpushpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
from twisted.web.client import FileBodyProducer, HTTPConnectionPool, readBody
from twisted.web.http_headers import Headers

from sygnal.exceptions import PushkinSetupException
from sygnal.helper.context_factory import ClientTLSOptionsFactory
from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent

from .exceptions import PushkinSetupException
from .notifications import ConcurrencyLimitedPushkin
from .utils import glob_to_regex
from sygnal.notifications import ConcurrencyLimitedPushkin
from sygnal.utils import glob_to_regex

QUEUE_TIME_HISTOGRAM = Histogram(
"sygnal_webpush_queue_time",
Expand Down Expand Up @@ -77,7 +76,7 @@ class WebpushPushkin(ConcurrencyLimitedPushkin):
} | ConcurrencyLimitedPushkin.UNDERSTOOD_CONFIG_FIELDS

def __init__(self, name, sygnal, config):
super(WebpushPushkin, self).__init__(name, sygnal, config)
super().__init__(name, sygnal, config)

nonunderstood = self.cfg.keys() - self.UNDERSTOOD_CONFIG_FIELDS
if nonunderstood:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def setUp(self):
patch("sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration").start()
self.addCleanup(patch.stopall)

super(ApnsTestCase, self).setUp()
super().setUp()

self.apns_pushkin_snotif = MagicMock()
self.sygnal.pushkins[PUSHKIN_ID]._send_notification = self.apns_pushkin_snotif

def config_setup(self, config):
super(ApnsTestCase, self).config_setup(config)
super().config_setup(config)
config["apps"][PUSHKIN_ID] = {"type": "apns", "certfile": TEST_CERTFILE_PATH}

def test_payload_truncation(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_concurrency_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def _dispatch_notification_unlimited(self, n, device, context):

class ConcurrencyLimitTestCase(TestCase):
def config_setup(self, config):
super(ConcurrencyLimitTestCase, self).config_setup(config)
super().config_setup(config)
config["apps"]["com.example.gcm"] = {
"type": "tests.test_concurrency_limit.SlowConcurrencyLimitedDummyPushkin",
"inflight_request_limit": 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def setUp(self):
patch("sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration").start()
self.addCleanup(patch.stopall)

super(HttpTestCase, self).setUp()
super().setUp()

self.apns_pushkin_snotif = MagicMock()
for key, value in self.sygnal.pushkins.items():
value._send_notification = self.apns_pushkin_snotif

def config_setup(self, config):
super(HttpTestCase, self).config_setup(config)
super().config_setup(config)
config["apps"][PUSHKIN_ID_1] = {"type": "apns", "certfile": TEST_CERTFILE_PATH}
config["apps"][PUSHKIN_ID_2] = {"type": "apns", "certfile": TEST_CERTFILE_PATH}
config["apps"][PUSHKIN_ID_3] = {"type": "apns", "certfile": TEST_CERTFILE_PATH}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_httpproxy_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class SygnalTwistedProxyTests(TestCase):
def config_setup(self, config):
super(SygnalTwistedProxyTests, self).config_setup(config)
super().config_setup(config)
config["apps"]["com.example.gcm"] = {
"type": "tests.test_gcm.TestGcmPushkin",
"api_key": "kii",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pushgateway_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def config_setup(self, config):
"""
Set up a TestPushkin for the test.
"""
super(PushGatewayApiV1TestCase, self).config_setup(config)
super().config_setup(config)
config["apps"]["com.example.spqr"] = {
"type": "tests.test_pushgateway_api_v1.TestPushkin"
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def __init__(self):
self.lookups: Dict[str, str] = {}

@implementer(IResolverSimple)
class FakeResolver(object):
class FakeResolver:
@staticmethod
def getHostByName(name, timeout=None):
if name not in self.lookups:
Expand Down Expand Up @@ -269,7 +269,7 @@ def wait_for_work(self, early_stop=lambda: False):
self.work_notifier.release()


class DummyResponse(object):
class DummyResponse:
def __init__(self, code):
self.code = code

Expand All @@ -292,7 +292,7 @@ class HTTPResult:


@attr.s
class FakeChannel(object):
class FakeChannel:
"""
A fake Twisted Web Channel (the part that interfaces with the
wire).
Expand Down
4 changes: 2 additions & 2 deletions tests/twisted_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@attr.s(cmp=False)
class FakeTransport(object):
class FakeTransport:
"""
A twisted.internet.interfaces.ITransport implementation which sends all its data
straight into an IProtocol object: it exists to connect two IProtocols together.
Expand Down Expand Up @@ -274,7 +274,7 @@ def create_test_cert_file(sanlist):


@implementer(IOpenSSLServerConnectionCreator)
class TestServerTLSConnectionFactory(object):
class TestServerTLSConnectionFactory:
"""An SSL connection creator which returns connections which present a certificate
signed by our test CA."""

Expand Down

0 comments on commit 0c63cd8

Please sign in to comment.