Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
update hints and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Aug 16, 2021
1 parent 8232835 commit 0c3d2c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
15 changes: 11 additions & 4 deletions synapse/http/additional_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from twisted.web.server import Request

from synapse.http.server import DirectServeJsonResource

if TYPE_CHECKING:
from synapse.server import HomeServer


class AdditionalResource(DirectServeJsonResource):
"""Resource wrapper for additional_resources
Expand All @@ -25,22 +32,22 @@ class AdditionalResource(DirectServeJsonResource):
and exception handling.
"""

def __init__(self, hs, handler):
def __init__(self, hs: "HomeServer", handler: Request):
"""Initialise AdditionalResource
The ``handler`` should return a deferred which completes when it has
done handling the request. It should write a response with
``request.write()``, and call ``request.finish()``.
Args:
hs (synapse.server.HomeServer): homeserver
handler ((twisted.web.server.Request) -> twisted.internet.defer.Deferred):
hs: homeserver
handler (twisted.internet.defer.Deferred):
function to be called to handle the request.
"""
super().__init__()
self._handler = handler

def _async_render(self, request):
def _async_render(self, request: Request):
# Cheekily pass the result straight through, so we don't need to worry
# if its an awaitable or not.
return self._handler(request)
18 changes: 9 additions & 9 deletions synapse/http/federation/srv_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

logger = logging.getLogger(__name__)

SERVER_CACHE: Dict = {}
SERVER_CACHE: Dict[bytes, List[Server]] = {}


@attr.s(slots=True, frozen=True)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class Server:
"""
Our record of an individual server which can be tried to reach a destination.
Expand All @@ -45,11 +45,11 @@ class Server:
the epoch
"""

host: bytes = attr.ib()
port: int = attr.ib()
priority: int = attr.ib(default=0)
weight: int = attr.ib(default=0)
expires: int = attr.ib(default=0)
host: bytes
port: int
priority: int = 0
weight: int = 0
expires: int = 0


def _sort_server_list(server_list):
Expand Down Expand Up @@ -110,8 +110,8 @@ class SrvResolver:
def __init__(
self,
dns_client=client,
cache: Dict = SERVER_CACHE,
get_time: Callable = time.time,
cache: Dict[bytes, List[Server]] = SERVER_CACHE,
get_time: Callable[[], float] = time.time,
):
self._dns_client = dns_client
self._cache = cache
Expand Down
3 changes: 1 addition & 2 deletions synapse/http/proxyagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def request(
self.http_proxy_creds.as_proxy_authorization_value(),
)
# Cache *all* connections under the same key, since we are only
# connecting to a single destination, the proxy
# The URL of proxy is not important for the key
# connecting to a single destination, the proxy:
pool_key = "http-proxy"
endpoint = self.http_proxy_endpoint
request_path = uri
Expand Down

0 comments on commit 0c3d2c0

Please sign in to comment.