mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-21 21:01:00 -05:00
pantalaimon: Isort the tree.
This commit is contained in:
parent
22fcbff44b
commit
e9d0f52a5c
@ -3,22 +3,17 @@ from pprint import pformat
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientConnectionError
|
from aiohttp.client_exceptions import ClientConnectionError
|
||||||
from nio import (AsyncClient, ClientConfig, EncryptionError,
|
from nio import (AsyncClient, ClientConfig, EncryptionError, KeysQueryResponse,
|
||||||
KeysQueryResponse, MegolmEvent,
|
KeyVerificationEvent, KeyVerificationKey, KeyVerificationMac,
|
||||||
RoomEncryptedEvent, SyncResponse,
|
KeyVerificationStart, LocalProtocolError, MegolmEvent,
|
||||||
KeyVerificationEvent, LocalProtocolError,
|
RoomEncryptedEvent, SyncResponse)
|
||||||
KeyVerificationStart, KeyVerificationKey, KeyVerificationMac)
|
|
||||||
from nio.store import SqliteStore
|
|
||||||
from nio.crypto import Sas
|
from nio.crypto import Sas
|
||||||
|
from nio.store import SqliteStore
|
||||||
|
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
from pantalaimon.thread_messages import (
|
from pantalaimon.thread_messages import (DaemonResponse, DevicesMessage,
|
||||||
DevicesMessage,
|
InviteSasSignal, SasDoneSignal,
|
||||||
InviteSasSignal,
|
ShowSasSignal)
|
||||||
ShowSasSignal,
|
|
||||||
SasDoneSignal,
|
|
||||||
DaemonResponse
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PanClient(AsyncClient):
|
class PanClient(AsyncClient):
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
from ipaddress import IPv4Address, IPv6Address, ip_address
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
from urllib.parse import ParseResult, urlparse
|
||||||
|
|
||||||
from ipaddress import ip_address, IPv4Address, IPv6Address
|
|
||||||
from urllib.parse import urlparse, ParseResult
|
|
||||||
|
|
||||||
import logbook
|
|
||||||
import attr
|
import attr
|
||||||
|
import logbook
|
||||||
|
|
||||||
|
|
||||||
class PanConfigParser(configparser.ConfigParser):
|
class PanConfigParser(configparser.ConfigParser):
|
||||||
|
@ -10,24 +10,19 @@ import aiohttp
|
|||||||
import attr
|
import attr
|
||||||
import keyring
|
import keyring
|
||||||
from aiohttp import ClientSession, web
|
from aiohttp import ClientSession, web
|
||||||
from aiohttp.client_exceptions import (ContentTypeError,
|
from aiohttp.client_exceptions import ClientConnectionError, ContentTypeError
|
||||||
ClientConnectionError)
|
|
||||||
from multidict import CIMultiDict
|
from multidict import CIMultiDict
|
||||||
from nio import (EncryptionError, LoginResponse, SendRetryError)
|
from nio import EncryptionError, LoginResponse, SendRetryError
|
||||||
|
|
||||||
from pantalaimon.client import PanClient
|
from pantalaimon.client import PanClient
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
from pantalaimon.store import ClientInfo, PanStore
|
from pantalaimon.store import ClientInfo, PanStore
|
||||||
from pantalaimon.thread_messages import (
|
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
||||||
DeviceVerifyMessage,
|
DeviceConfirmSasMessage,
|
||||||
DeviceUnverifyMessage,
|
DeviceUnverifyMessage,
|
||||||
ExportKeysMessage,
|
DeviceVerifyMessage,
|
||||||
ImportKeysMessage,
|
ExportKeysMessage, ImportKeysMessage,
|
||||||
DeviceConfirmSasMessage,
|
SasMessage)
|
||||||
SasMessage,
|
|
||||||
AcceptSasMessage,
|
|
||||||
DaemonResponse,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import janus
|
import janus
|
||||||
|
from aiohttp import web
|
||||||
from typing import Optional
|
from appdirs import user_config_dir, user_data_dir
|
||||||
|
|
||||||
from appdirs import user_data_dir, user_config_dir
|
|
||||||
from logbook import StderrHandler
|
from logbook import StderrHandler
|
||||||
|
|
||||||
from aiohttp import web
|
|
||||||
|
|
||||||
from pantalaimon.ui import GlibT
|
|
||||||
from pantalaimon.thread_messages import DaemonResponse
|
|
||||||
from pantalaimon.daemon import ProxyDaemon
|
|
||||||
from pantalaimon.config import PanConfig, PanConfigError, parse_log_level
|
from pantalaimon.config import PanConfig, PanConfigError, parse_log_level
|
||||||
|
from pantalaimon.daemon import ProxyDaemon
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
|
from pantalaimon.thread_messages import DaemonResponse
|
||||||
|
from pantalaimon.ui import GlibT
|
||||||
|
|
||||||
|
|
||||||
def create_dirs(data_dir, conf_dir):
|
def create_dirs(data_dir, conf_dir):
|
||||||
|
@ -1,22 +1,19 @@
|
|||||||
"""Cli utility to control pantalaimon."""
|
"""Cli utility to control pantalaimon."""
|
||||||
|
|
||||||
import attr
|
|
||||||
import asyncio
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from typing import List
|
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from prompt_toolkit import PromptSession
|
import attr
|
||||||
from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop
|
from gi.repository import GLib
|
||||||
from prompt_toolkit.patch_stdout import patch_stdout
|
from prompt_toolkit import HTML, PromptSession, print_formatted_text
|
||||||
from prompt_toolkit.completion import Completer, Completion, PathCompleter
|
from prompt_toolkit.completion import Completer, Completion, PathCompleter
|
||||||
from prompt_toolkit.document import Document
|
from prompt_toolkit.document import Document
|
||||||
from prompt_toolkit import print_formatted_text, HTML
|
from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop
|
||||||
|
from prompt_toolkit.patch_stdout import patch_stdout
|
||||||
from pydbus import SessionBus
|
from pydbus import SessionBus
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
use_asyncio_event_loop()
|
use_asyncio_event_loop()
|
||||||
|
|
||||||
|
@ -1,27 +1,20 @@
|
|||||||
import attr
|
from queue import Empty
|
||||||
|
|
||||||
|
import attr
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
from nio.store import TrustState
|
||||||
from pydbus import SessionBus
|
from pydbus import SessionBus
|
||||||
from pydbus.generic import signal
|
from pydbus.generic import signal
|
||||||
|
|
||||||
from queue import Empty
|
|
||||||
from nio.store import TrustState
|
|
||||||
|
|
||||||
from pantalaimon.store import PanStore
|
|
||||||
from pantalaimon.thread_messages import (
|
|
||||||
DeviceVerifyMessage,
|
|
||||||
DeviceUnverifyMessage,
|
|
||||||
DevicesMessage,
|
|
||||||
AcceptSasMessage,
|
|
||||||
DeviceConfirmSasMessage,
|
|
||||||
ImportKeysMessage,
|
|
||||||
ExportKeysMessage,
|
|
||||||
ShowSasSignal,
|
|
||||||
InviteSasSignal,
|
|
||||||
SasDoneSignal,
|
|
||||||
DaemonResponse
|
|
||||||
)
|
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
|
from pantalaimon.store import PanStore
|
||||||
|
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
||||||
|
DeviceConfirmSasMessage,
|
||||||
|
DevicesMessage, DeviceUnverifyMessage,
|
||||||
|
DeviceVerifyMessage,
|
||||||
|
ExportKeysMessage, ImportKeysMessage,
|
||||||
|
InviteSasSignal, SasDoneSignal,
|
||||||
|
ShowSasSignal)
|
||||||
|
|
||||||
|
|
||||||
class IdCounter:
|
class IdCounter:
|
||||||
|
65
tests/conftest.py
Normal file
65
tests/conftest.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
from random import choices
|
||||||
|
from string import ascii_letters, ascii_uppercase, digits
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from faker import Faker
|
||||||
|
from faker.providers import BaseProvider
|
||||||
|
from nio.crypto import OlmAccount
|
||||||
|
from nio.store import SqliteStore
|
||||||
|
|
||||||
|
from pantalaimon.store import ClientInfo, PanStore
|
||||||
|
|
||||||
|
faker = Faker()
|
||||||
|
|
||||||
|
|
||||||
|
class Provider(BaseProvider):
|
||||||
|
def mx_id(self):
|
||||||
|
return "@{}:{}".format(faker.user_name(), faker.hostname())
|
||||||
|
|
||||||
|
def device_id(self):
|
||||||
|
return "".join(choices(ascii_uppercase, k=10))
|
||||||
|
|
||||||
|
def access_token(self):
|
||||||
|
return "MDA" + "".join(choices(digits + ascii_letters, k=272))
|
||||||
|
|
||||||
|
def client(self):
|
||||||
|
return ClientInfo(faker.mx_id(), faker.access_token())
|
||||||
|
|
||||||
|
|
||||||
|
faker.add_provider(Provider)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def access_token():
|
||||||
|
return faker.access_token()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
return faker.client()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tempdir():
|
||||||
|
newpath = tempfile.mkdtemp()
|
||||||
|
yield newpath
|
||||||
|
shutil.rmtree(newpath)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def panstore(tempdir):
|
||||||
|
for _ in range(10):
|
||||||
|
store = SqliteStore(
|
||||||
|
faker.mx_id(),
|
||||||
|
faker.device_id(),
|
||||||
|
tempdir,
|
||||||
|
"",
|
||||||
|
"pan.db"
|
||||||
|
)
|
||||||
|
account = OlmAccount()
|
||||||
|
store.save_account(account)
|
||||||
|
|
||||||
|
store = PanStore(tempdir, "pan.db")
|
||||||
|
return store
|
@ -1,69 +1,6 @@
|
|||||||
import pdb
|
import pdb
|
||||||
import shutil
|
|
||||||
import tempfile
|
|
||||||
from random import choices
|
|
||||||
from string import ascii_letters, ascii_uppercase, digits
|
|
||||||
|
|
||||||
import pytest
|
from conftest import faker
|
||||||
from faker import Faker
|
|
||||||
from faker.providers import BaseProvider
|
|
||||||
from nio.crypto import OlmAccount
|
|
||||||
from nio.store import SqliteStore
|
|
||||||
|
|
||||||
from pantalaimon.store import ClientInfo, PanStore
|
|
||||||
|
|
||||||
faker = Faker()
|
|
||||||
|
|
||||||
|
|
||||||
class Provider(BaseProvider):
|
|
||||||
def mx_id(self):
|
|
||||||
return "@{}:{}".format(faker.user_name(), faker.hostname())
|
|
||||||
|
|
||||||
def device_id(self):
|
|
||||||
return "".join(choices(ascii_uppercase, k=10))
|
|
||||||
|
|
||||||
def access_token(self):
|
|
||||||
return "MDA" + "".join(choices(digits + ascii_letters, k=272))
|
|
||||||
|
|
||||||
def client(self):
|
|
||||||
return ClientInfo(faker.mx_id(), faker.access_token())
|
|
||||||
|
|
||||||
|
|
||||||
faker.add_provider(Provider)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def access_token():
|
|
||||||
return faker.access_token()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
return faker.client()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tempdir():
|
|
||||||
newpath = tempfile.mkdtemp()
|
|
||||||
yield newpath
|
|
||||||
shutil.rmtree(newpath)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def panstore(tempdir):
|
|
||||||
for _ in range(10):
|
|
||||||
store = SqliteStore(
|
|
||||||
faker.mx_id(),
|
|
||||||
faker.device_id(),
|
|
||||||
tempdir,
|
|
||||||
"",
|
|
||||||
"pan.db"
|
|
||||||
)
|
|
||||||
account = OlmAccount()
|
|
||||||
store.save_account(account)
|
|
||||||
|
|
||||||
store = PanStore(tempdir, "pan.db")
|
|
||||||
return store
|
|
||||||
|
|
||||||
|
|
||||||
class TestClass(object):
|
class TestClass(object):
|
||||||
|
Loading…
Reference in New Issue
Block a user