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

Change HomeServer definition to work with typing. #8060

Merged
merged 5 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8060.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve typing information on `HomeServer` object.
8 changes: 5 additions & 3 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
from synapse.rest.client.versions import VersionsRestServlet
from synapse.rest.health import HealthResource
from synapse.rest.key.v2 import KeyApiV2Resource
from synapse.server import HomeServer
from synapse.server import HomeServer, cache_in_self
from synapse.storage.databases.main.censor_events import CensorEventsStore
from synapse.storage.databases.main.media_repository import MediaRepositoryStore
from synapse.storage.databases.main.monthly_active_users import (
Expand Down Expand Up @@ -635,10 +635,12 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
async def remove_pusher(self, app_id, push_key, user_id):
self.get_tcp_replication().send_remove_pusher(app_id, push_key, user_id)

def build_replication_data_handler(self):
@cache_in_self
def get_replication_data_handler(self):
return GenericWorkerReplicationHandler(self)

def build_presence_handler(self):
@cache_in_self
def get_presence_handler(self):
return GenericWorkerPresence(self)


Expand Down
8 changes: 5 additions & 3 deletions synapse/handlers/oidc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
import json
import logging
from typing import Dict, Generic, List, Optional, Tuple, TypeVar
from typing import TYPE_CHECKING, Dict, Generic, List, Optional, Tuple, TypeVar
from urllib.parse import urlencode

import attr
Expand All @@ -39,9 +39,11 @@
from synapse.http.site import SynapseRequest
from synapse.logging.context import make_deferred_yieldable
from synapse.push.mailer import load_jinja2_templates
from synapse.server import HomeServer
from synapse.types import UserID, map_username_to_mxid_localpart

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)

SESSION_COOKIE_NAME = b"oidc_session"
Expand Down Expand Up @@ -91,7 +93,7 @@ class OidcHandler:
"""Handles requests related to the OpenID Connect login flow.
"""

def __init__(self, hs: HomeServer):
def __init__(self, hs: "HomeServer"):
self._callback_url = hs.config.oidc_callback_url # type: str
self._scopes = hs.config.oidc_scopes # type: List[str]
self._client_auth = ClientAuth(
Expand Down
8 changes: 6 additions & 2 deletions synapse/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
if sys.version_info[0:2] >= (3, 6):
import secrets

def Secrets():
return secrets
class Secrets:
def token_bytes(self, nbytes=32):
return secrets.token_bytes(nbytes)

def token_hex(self, nbytes=32):
return secrets.token_hex(nbytes)


else:
Expand Down
Loading