Skip to content

Commit

Permalink
Merge pull request #174 from matrix-org/format-with-ruff
Browse files Browse the repository at this point in the history
chore: Format with ruff and lint
  • Loading branch information
chookity-pokk authored Oct 2, 2024
2 parents adef634 + 369f73f commit f459d58
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 108 deletions.
13 changes: 6 additions & 7 deletions pantalaimon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
from collections import defaultdict
from pprint import pformat
from typing import Any, Dict, Optional
from urllib.parse import urlparse

from aiohttp.client_exceptions import ClientConnectionError
Expand Down Expand Up @@ -709,7 +708,6 @@ async def handle_key_request_message(self, message):
for share in self.get_active_key_requests(
message.user_id, message.device_id
):

continued = True

if not self.continue_key_share(share):
Expand Down Expand Up @@ -811,8 +809,9 @@ def pan_decrypt_event(self, event_dict, room_id=None, ignore_failures=True):

if not isinstance(event, MegolmEvent):
logger.warn(
"Encrypted event is not a megolm event:"
"\n{}".format(pformat(event_dict))
"Encrypted event is not a megolm event:" "\n{}".format(
pformat(event_dict)
)
)
return False

Expand All @@ -836,9 +835,9 @@ def pan_decrypt_event(self, event_dict, room_id=None, ignore_failures=True):
decrypted_event.source["content"]["url"] = decrypted_event.url

if decrypted_event.thumbnail_url:
decrypted_event.source["content"]["info"][
"thumbnail_url"
] = decrypted_event.thumbnail_url
decrypted_event.source["content"]["info"]["thumbnail_url"] = (
decrypted_event.thumbnail_url
)

event_dict.update(decrypted_event.source)
event_dict["decrypted"] = True
Expand Down
1 change: 0 additions & 1 deletion pantalaimon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def read(self):

try:
for section_name, section in config.items():

if section_name == "Default":
continue

Expand Down
14 changes: 9 additions & 5 deletions pantalaimon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ async def _verify_device(self, message_id, client, device):

if ret:
msg = (
f"Device {device.id} of user " f"{device.user_id} successfully verified."
f"Device {device.id} of user "
f"{device.user_id} successfully verified."
)
await client.send_update_device(device)
else:
Expand Down Expand Up @@ -309,7 +310,6 @@ async def receive_message(self, message):
DeviceUnblacklistMessage,
),
):

device = client.device_store[message.user_id].get(message.device_id, None)

if not device:
Expand Down Expand Up @@ -616,7 +616,9 @@ async def start_pan_client(
await pan_client.close()
return

logger.info(f"Successfully started new background sync client for " f"{user_id}")
logger.info(
f"Successfully started new background sync client for " f"{user_id}"
)

await self.send_ui_message(
UpdateUsersMessage(self.name, user_id, pan_client.device_id)
Expand Down Expand Up @@ -733,7 +735,7 @@ async def decrypt_loop(client, body):
return decryption_method(body, ignore_failures=False)
except EncryptionError:
logger.info("Error decrypting sync, waiting for next pan " "sync")
await client.synced.wait(),
(await client.synced.wait(),)
logger.info("Pan synced, retrying decryption.")

try:
Expand Down Expand Up @@ -1273,7 +1275,9 @@ async def _load_decrypted_file(self, server_name, media_id, file_name):
client = next(iter(self.pan_clients.values()))

try:
response = await client.download(server_name=server_name, media_id=media_id, filename=file_name)
response = await client.download(
server_name=server_name, media_id=media_id, filename=file_name
)
except ClientConnectionError as e:
raise e

Expand Down
2 changes: 0 additions & 2 deletions pantalaimon/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class InvalidQueryError(Exception):
import json
import os
from functools import partial
from typing import Any, Dict, List, Optional, Tuple

import attr
import tantivy
Expand Down Expand Up @@ -230,7 +229,6 @@ def load_events(
)

for message in query:

event = message.event

event_dict = {
Expand Down
1 change: 0 additions & 1 deletion pantalaimon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import asyncio
import os
import signal
from typing import Optional

import click
import janus
Expand Down
3 changes: 1 addition & 2 deletions pantalaimon/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import os
from collections import defaultdict
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict

import attr
from nio.crypto import TrustState, GroupSessionStore
Expand Down Expand Up @@ -431,7 +431,6 @@ def load_all_devices(self):
device_store = defaultdict(dict)

for d in account.device_keys:

if d.deleted:
continue

Expand Down
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
url="https://github.com/matrix-org/pantalaimon",
author="The Matrix.org Team",
author_email="[email protected]",
description=("A Matrix proxy daemon that adds E2E encryption "
"capabilities."),
description=("A Matrix proxy daemon that adds E2E encryption " "capabilities."),
long_description=long_description,
long_description_content_type="text/markdown",
license="Apache License, Version 2.0",
Expand All @@ -29,7 +28,7 @@
"cachetools >= 3.0.0",
"prompt_toolkit > 2, < 4",
"typing;python_version<'3.5'",
"matrix-nio[e2e] >= 0.20, < 0.21"
"matrix-nio[e2e] >= 0.20, < 0.21",
],
extras_require={
"ui": [
Expand All @@ -40,8 +39,10 @@
]
},
entry_points={
"console_scripts": ["pantalaimon=pantalaimon.main:main",
"panctl=pantalaimon.panctl:main"],
"console_scripts": [
"pantalaimon=pantalaimon.main:main",
"panctl=pantalaimon.panctl:main",
],
},
zip_safe=False
zip_safe=False,
)
47 changes: 20 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ def access_token(self):
def client(self):
return ClientInfo(faker.mx_id(), faker.access_token())


def avatar_url(self):
return "mxc://{}/{}#auto".format(
faker.hostname(),
"".join(choices(ascii_letters) for i in range(24))
faker.hostname(), "".join(choices(ascii_letters) for i in range(24))
)

def olm_key_pair(self):
Expand All @@ -56,7 +54,6 @@ def olm_device(self):
)



faker.add_provider(Provider)


Expand All @@ -80,13 +77,7 @@ def tempdir():
@pytest.fixture
def panstore(tempdir):
for _ in range(10):
store = SqliteStore(
faker.mx_id(),
faker.device_id(),
tempdir,
"",
"pan.db"
)
store = SqliteStore(faker.mx_id(), faker.device_id(), tempdir, "", "pan.db")
account = OlmAccount()
store.save_account(account)

Expand Down Expand Up @@ -130,21 +121,23 @@ async def pan_proxy_server(tempdir, aiohttp_server):
recv_queue=ui_queue.async_q,
proxy=None,
ssl=False,
client_store_class=SqliteStore
client_store_class=SqliteStore,
)

app.add_routes([
web.post("/_matrix/client/r0/login", proxy.login),
web.get("/_matrix/client/r0/sync", proxy.sync),
web.get("/_matrix/client/r0/rooms/{room_id}/messages", proxy.messages),
web.put(
r"/_matrix/client/r0/rooms/{room_id}/send/{event_type}/{txnid}",
proxy.send_message
),
web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
web.post("/_matrix/client/r0/search", proxy.search),
web.options("/_matrix/client/r0/search", proxy.search_opts),
])
app.add_routes(
[
web.post("/_matrix/client/r0/login", proxy.login),
web.get("/_matrix/client/r0/sync", proxy.sync),
web.get("/_matrix/client/r0/rooms/{room_id}/messages", proxy.messages),
web.put(
r"/_matrix/client/r0/rooms/{room_id}/send/{event_type}/{txnid}",
proxy.send_message,
),
web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
web.post("/_matrix/client/r0/search", proxy.search),
web.options("/_matrix/client/r0/search", proxy.search_opts),
]
)

server = await aiohttp_server(app)

Expand All @@ -161,7 +154,7 @@ async def running_proxy(pan_proxy_server, aioresponse, aiohttp_client):
"access_token": "abc123",
"device_id": "GHTYAJCE",
"home_server": "example.org",
"user_id": "@example:example.org"
"user_id": "@example:example.org",
}

aioclient = await aiohttp_client(server)
Expand All @@ -170,7 +163,7 @@ async def running_proxy(pan_proxy_server, aioresponse, aiohttp_client):
"https://example.org/_matrix/client/r0/login",
status=200,
payload=login_response,
repeat=True
repeat=True,
)

await aioclient.post(
Expand All @@ -179,7 +172,7 @@ async def running_proxy(pan_proxy_server, aioresponse, aiohttp_client):
"type": "m.login.password",
"user": "example",
"password": "wordpass",
}
},
)

yield server, aioclient, proxy, queues
Expand Down
8 changes: 6 additions & 2 deletions tests/pan_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ async def test_history_fetching_tasks(self, client, aioresponse, loop):
)

aioresponse.get(
sync_url, status=200, payload=self.initial_sync_response,
sync_url,
status=200,
payload=self.initial_sync_response,
)

aioresponse.get(sync_url, status=200, payload=self.empty_sync, repeat=True)
Expand Down Expand Up @@ -454,7 +456,9 @@ async def test_history_fetching_resume(self, client, aioresponse, loop):
)

aioresponse.get(
sync_url, status=200, payload=self.initial_sync_response,
sync_url,
status=200,
payload=self.initial_sync_response,
)

aioresponse.get(sync_url, status=200, payload=self.empty_sync, repeat=True)
Expand Down
Loading

0 comments on commit f459d58

Please sign in to comment.