mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
python: Reformat with Black, except quotes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
5028c081cb
commit
11741543da
@@ -36,10 +36,16 @@ class TornadoAdapter(HTTPAdapter):
|
||||
# requests to external hosts.
|
||||
proxies = {}
|
||||
try:
|
||||
resp = super().send(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
|
||||
resp = super().send(
|
||||
request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies
|
||||
)
|
||||
except ConnectionError:
|
||||
parsed_url = urlparse(request.url)
|
||||
logfile = f"tornado-{parsed_url.port}.log" if settings.TORNADO_PROCESSES > 1 else "tornado.log"
|
||||
logfile = (
|
||||
f"tornado-{parsed_url.port}.log"
|
||||
if settings.TORNADO_PROCESSES > 1
|
||||
else "tornado.log"
|
||||
)
|
||||
raise ConnectionError(
|
||||
f"Django cannot connect to Tornado server ({request.url}); "
|
||||
f"check {settings.ERROR_FILE_LOG_PATH} and {logfile}"
|
||||
@@ -47,6 +53,7 @@ class TornadoAdapter(HTTPAdapter):
|
||||
resp.raise_for_status()
|
||||
return resp
|
||||
|
||||
|
||||
@lru_cache(None)
|
||||
def requests_client() -> requests.Session:
|
||||
c = requests.Session()
|
||||
@@ -55,40 +62,49 @@ def requests_client() -> requests.Session:
|
||||
c.mount(scheme, adapter)
|
||||
return c
|
||||
|
||||
def request_event_queue(user_profile: UserProfile, user_client: Client, apply_markdown: bool,
|
||||
client_gravatar: bool, slim_presence: bool, queue_lifespan_secs: int,
|
||||
event_types: Optional[Iterable[str]]=None,
|
||||
all_public_streams: bool=False,
|
||||
narrow: Iterable[Sequence[str]]=[],
|
||||
bulk_message_deletion: bool=False) -> Optional[str]:
|
||||
|
||||
def request_event_queue(
|
||||
user_profile: UserProfile,
|
||||
user_client: Client,
|
||||
apply_markdown: bool,
|
||||
client_gravatar: bool,
|
||||
slim_presence: bool,
|
||||
queue_lifespan_secs: int,
|
||||
event_types: Optional[Iterable[str]] = None,
|
||||
all_public_streams: bool = False,
|
||||
narrow: Iterable[Sequence[str]] = [],
|
||||
bulk_message_deletion: bool = False,
|
||||
) -> Optional[str]:
|
||||
|
||||
if not settings.USING_TORNADO:
|
||||
return None
|
||||
|
||||
tornado_uri = get_tornado_uri(user_profile.realm)
|
||||
req = {'dont_block': 'true',
|
||||
'apply_markdown': orjson.dumps(apply_markdown),
|
||||
'client_gravatar': orjson.dumps(client_gravatar),
|
||||
'slim_presence': orjson.dumps(slim_presence),
|
||||
'all_public_streams': orjson.dumps(all_public_streams),
|
||||
'client': 'internal',
|
||||
'user_profile_id': user_profile.id,
|
||||
'user_client': user_client.name,
|
||||
'narrow': orjson.dumps(narrow),
|
||||
'secret': settings.SHARED_SECRET,
|
||||
'lifespan_secs': queue_lifespan_secs,
|
||||
'bulk_message_deletion': orjson.dumps(bulk_message_deletion)}
|
||||
req = {
|
||||
'dont_block': 'true',
|
||||
'apply_markdown': orjson.dumps(apply_markdown),
|
||||
'client_gravatar': orjson.dumps(client_gravatar),
|
||||
'slim_presence': orjson.dumps(slim_presence),
|
||||
'all_public_streams': orjson.dumps(all_public_streams),
|
||||
'client': 'internal',
|
||||
'user_profile_id': user_profile.id,
|
||||
'user_client': user_client.name,
|
||||
'narrow': orjson.dumps(narrow),
|
||||
'secret': settings.SHARED_SECRET,
|
||||
'lifespan_secs': queue_lifespan_secs,
|
||||
'bulk_message_deletion': orjson.dumps(bulk_message_deletion),
|
||||
}
|
||||
|
||||
if event_types is not None:
|
||||
req['event_types'] = orjson.dumps(event_types)
|
||||
|
||||
resp = requests_client().post(
|
||||
tornado_uri + '/api/v1/events/internal',
|
||||
data=req
|
||||
)
|
||||
resp = requests_client().post(tornado_uri + '/api/v1/events/internal', data=req)
|
||||
return resp.json()['queue_id']
|
||||
|
||||
def get_user_events(user_profile: UserProfile, queue_id: str, last_event_id: int) -> List[Dict[str, Any]]:
|
||||
|
||||
def get_user_events(
|
||||
user_profile: UserProfile, queue_id: str, last_event_id: int
|
||||
) -> List[Dict[str, Any]]:
|
||||
if not settings.USING_TORNADO:
|
||||
return []
|
||||
|
||||
@@ -101,12 +117,10 @@ def get_user_events(user_profile: UserProfile, queue_id: str, last_event_id: int
|
||||
'secret': settings.SHARED_SECRET,
|
||||
'client': 'internal',
|
||||
}
|
||||
resp = requests_client().post(
|
||||
tornado_uri + '/api/v1/events/internal',
|
||||
data=post_data
|
||||
)
|
||||
resp = requests_client().post(tornado_uri + '/api/v1/events/internal', data=post_data)
|
||||
return resp.json()['events']
|
||||
|
||||
|
||||
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
|
||||
if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
|
||||
process_notification(data)
|
||||
@@ -117,6 +131,7 @@ def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
|
||||
data=dict(data=orjson.dumps(data), secret=settings.SHARED_SECRET),
|
||||
)
|
||||
|
||||
|
||||
# The core function for sending an event from Django to Tornado (which
|
||||
# will then push it to web and mobile clients for the target users).
|
||||
# By convention, send_event should only be called from
|
||||
@@ -127,12 +142,15 @@ def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
|
||||
# with the schema verified in `zerver/lib/event_schema.py`.
|
||||
#
|
||||
# See https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
|
||||
def send_event(realm: Realm, event: Mapping[str, Any],
|
||||
users: Union[Iterable[int], Iterable[Mapping[str, Any]]]) -> None:
|
||||
def send_event(
|
||||
realm: Realm, event: Mapping[str, Any], users: Union[Iterable[int], Iterable[Mapping[str, Any]]]
|
||||
) -> None:
|
||||
"""`users` is a list of user IDs, or in the case of `message` type
|
||||
events, a list of dicts describing the users and metadata about
|
||||
the user/message pair."""
|
||||
port = get_tornado_port(realm)
|
||||
queue_json_publish(notify_tornado_queue_name(port),
|
||||
dict(event=event, users=list(users)),
|
||||
lambda *args, **kwargs: send_notification_http(realm, *args, **kwargs))
|
||||
queue_json_publish(
|
||||
notify_tornado_queue_name(port),
|
||||
dict(event=event, users=list(users)),
|
||||
lambda *args, **kwargs: send_notification_http(realm, *args, **kwargs),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user