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

Commit

Permalink
Merge pull request #8060 from matrix-org/erikj/type_server
Browse files Browse the repository at this point in the history
Change HomeServer definition to work with typing.
  • Loading branch information
erikjohnston authored Aug 11, 2020
2 parents 04faa0b + fdb46b5 commit 6ba621d
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 403 deletions.
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

0 comments on commit 6ba621d

Please sign in to comment.