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

Commit

Permalink
Merge commit '9d1e4942a' into anoa/dinsic_release_1_21_x
Browse files Browse the repository at this point in the history
* commit '9d1e4942a':
  Fix typing for notifier (#8064)
  Add comment explaining cast
  Handle optional dependencies for Oidc and Saml
  Newsfile
  Change HomeServer definition to work with typing.
  • Loading branch information
anoadragon453 committed Oct 19, 2020
2 parents 13c1c20 + 9d1e494 commit db233aa
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 423 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.
1 change: 1 addition & 0 deletions changelog.d/8064.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type hints to `Notifier`.
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
7 changes: 5 additions & 2 deletions synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING, List, Tuple

from canonicaljson import json

Expand Down Expand Up @@ -54,7 +54,10 @@ def __init__(self, hs: "synapse.server.HomeServer"):

@measure_func("_send_new_transaction")
async def send_new_transaction(
self, destination: str, pending_pdus: List[EventBase], pending_edus: List[Edu]
self,
destination: str,
pending_pdus: List[Tuple[EventBase, int]],
pending_edus: List[Edu],
):

# Make a transaction-sending opentracing span. This span follows on from
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
12 changes: 8 additions & 4 deletions synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Set,
Tuple,
TypeVar,
Union,
)

from prometheus_client import Counter
Expand Down Expand Up @@ -186,7 +187,7 @@ def __init__(self, hs: "synapse.server.HomeServer"):
self.store = hs.get_datastore()
self.pending_new_room_events = (
[]
) # type: List[Tuple[int, EventBase, Collection[str]]]
) # type: List[Tuple[int, EventBase, Collection[Union[str, UserID]]]]

# Called when there are new things to stream over replication
self.replication_callbacks = [] # type: List[Callable[[], None]]
Expand Down Expand Up @@ -246,7 +247,7 @@ def on_new_room_event(
event: EventBase,
room_stream_id: int,
max_room_stream_id: int,
extra_users: Collection[str] = [],
extra_users: Collection[Union[str, UserID]] = [],
):
""" Used by handlers to inform the notifier something has happened
in the room, room event wise.
Expand Down Expand Up @@ -282,7 +283,10 @@ def _notify_pending_new_room_events(self, max_room_stream_id: int):
self._on_new_room_event(event, room_stream_id, extra_users)

def _on_new_room_event(
self, event: EventBase, room_stream_id: int, extra_users: Collection[str] = []
self,
event: EventBase,
room_stream_id: int,
extra_users: Collection[Union[str, UserID]] = [],
):
"""Notify any user streams that are interested in this room event"""
# poke any interested application service.
Expand Down Expand Up @@ -310,7 +314,7 @@ def on_new_event(
self,
stream_key: str,
new_token: int,
users: Collection[str] = [],
users: Collection[Union[str, UserID]] = [],
rooms: Collection[str] = [],
):
""" Used to inform listeners that something has happened event wise.
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 db233aa

Please sign in to comment.