Skip to content

Commit a02f3b4

Browse files
author
Sam Daniel Thangarajan
committed
moved soup_app package to soup package
1 parent e49de20 commit a02f3b4

File tree

10 files changed

+71
-72
lines changed

10 files changed

+71
-72
lines changed

src/nasdaq_protocols/itch/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import attrs
2-
from nasdaq_protocols.soup_app import SoupAppMessage
2+
from nasdaq_protocols.soup import soup_app
33
from nasdaq_protocols.common import logable
44

55

@@ -11,7 +11,7 @@
1111

1212
@attrs.define
1313
@logable
14-
class Message(SoupAppMessage, app_name=APP_NAME):
14+
class Message(soup_app.SoupAppMessage, app_name=APP_NAME):
1515

1616
def __init_subclass__(cls, **kwargs):
1717
super().__init_subclass__(**kwargs)

src/nasdaq_protocols/itch/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import attrs
44
from nasdaq_protocols import soup
5-
from nasdaq_protocols.soup_app.session import BaseClientSession, SessionId
5+
from nasdaq_protocols.soup import soup_app
66
from .core import Message
77

88
__all__ = [
@@ -17,13 +17,13 @@
1717

1818

1919
@attrs.define(auto_attribs=True)
20-
class ItchSessionId(SessionId):
20+
class ItchSessionId(soup_app.SoupAppSessionId):
2121
soup_session_id: soup.SoupSessionId = None
2222
protocol_name: str = "itch"
2323

2424

2525
@attrs.define(auto_attribs=True)
26-
class ClientSession(BaseClientSession):
26+
class ClientSession(soup_app.SoupAppClientSession):
2727
"""ITCH protocol client session implementation."""
2828

2929
def _create_session_id(self):

src/nasdaq_protocols/ouch/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import attrs
2-
from nasdaq_protocols.soup_app import SoupAppMessage
2+
from nasdaq_protocols.soup import soup_app
33
from nasdaq_protocols.common import logable
44

55

@@ -11,7 +11,7 @@
1111

1212
@attrs.define
1313
@logable
14-
class Message(SoupAppMessage, app_name=APP_NAME):
14+
class Message(soup_app.SoupAppMessage, app_name=APP_NAME):
1515

1616
def __init_subclass__(cls, **kwargs):
1717
super().__init_subclass__(**kwargs)

src/nasdaq_protocols/ouch/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import attrs
44
from nasdaq_protocols import soup
5-
from nasdaq_protocols.soup_app.session import BaseClientSession, SessionId
5+
from nasdaq_protocols.soup import soup_app
66
from .core import Message
77

88
__all__ = [
@@ -17,13 +17,13 @@
1717

1818

1919
@attrs.define(auto_attribs=True)
20-
class OuchSessionId(SessionId):
20+
class OuchSessionId(soup_app.SoupAppSessionId):
2121
soup_session_id: soup.SoupSessionId = None
2222
protocol_name: str = "ouch"
2323

2424

2525
@attrs.define(auto_attribs=True)
26-
class ClientSession(BaseClientSession):
26+
class ClientSession(soup_app.SoupAppClientSession):
2727

2828
def _create_session_id(self):
2929
return OuchSessionId(self.soup_session.session_id)

src/nasdaq_protocols/soup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
'SoupClientSessionSync',
6666
'tail_soup_app',
6767
'connect_async',
68-
'connect'
68+
'connect',
6969
]
7070

7171

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,64 @@
22
from typing import Callable, Type, Awaitable, Generic, TypeVar
33

44
import attrs
5-
from nasdaq_protocols.common import DispatchableMessageQueue, logable
5+
6+
from nasdaq_protocols.common import (
7+
Serializable,
8+
Byte,
9+
CommonMessage,
10+
logable,
11+
DispatchableMessageQueue,
12+
)
613
from nasdaq_protocols import soup
714

15+
816
M = TypeVar('M')
917

1018

11-
class SessionId:
19+
__all__ = [
20+
'SoupAppMessageId',
21+
'SoupAppMessage',
22+
'SoupAppSessionId',
23+
'SoupAppClientSession',
24+
]
25+
26+
27+
@attrs.define(auto_attribs=True, hash=True)
28+
class SoupAppMessageId(Serializable):
29+
indicator: int
30+
direction: str = 'outgoing'
31+
32+
@classmethod
33+
def from_bytes(cls, bytes_: bytes) -> tuple[int, 'SoupAppMessageId']:
34+
return 1, cls(Byte.from_bytes(bytes_)[1])
35+
36+
def to_bytes(self) -> tuple[int, bytes]:
37+
return Byte.to_bytes(self.indicator)
38+
39+
def __str__(self):
40+
return f'indicator={self.indicator}, direction={self.direction}'
41+
42+
43+
@attrs.define
44+
@logable
45+
class SoupAppMessage(CommonMessage):
46+
IncomingMsgClasses = []
47+
OutgoingMsgsClasses = []
48+
49+
def __init_subclass__(cls, *args, **kwargs):
50+
cls.log.debug('%s subclassing %s, params = %s', cls.__mro__[1].__name__, cls.__name__, str(kwargs))
51+
52+
app_name = kwargs.get('app_name')
53+
kwargs['app_name'] = app_name
54+
kwargs['msg_id_cls'] = SoupAppMessageId
55+
56+
if 'indicator' in kwargs and 'direction' in kwargs:
57+
kwargs['msg_id'] = SoupAppMessageId(kwargs['indicator'], kwargs['direction'])
58+
59+
super().__init_subclass__(**kwargs)
60+
61+
62+
class SoupAppSessionId:
1263
"""Base class for protocol-specific session IDs."""
1364
soup_session_id: soup.SoupSessionId = None
1465
protocol_name: str = "generic"
@@ -21,13 +72,13 @@ def __str__(self):
2172

2273
@attrs.define(auto_attribs=True)
2374
@logable
24-
class BaseClientSession(Generic[M]):
75+
class SoupAppClientSession(Generic[M]):
2576
"""Base client session class with common functionality for all protocol implementations."""
2677
soup_session: soup.SoupClientSession
2778
on_msg_coro: Callable[[Type[M]], Awaitable[None]] = None
2879
on_close_coro: Callable[[], Awaitable[None]] = None
2980
closed: bool = False
30-
_session_id: SessionId = None
81+
_session_id: SoupAppSessionId = None
3182
_close_event: asyncio.Event = None
3283
_message_queue: DispatchableMessageQueue = None
3384

src/nasdaq_protocols/soup_app/__init__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/nasdaq_protocols/soup_app/core.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/nasdaq_protocols/sqf/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import attrs
2-
from nasdaq_protocols.soup_app import SoupAppMessage
2+
from nasdaq_protocols.soup import soup_app
33
from nasdaq_protocols.common import logable
44

55

@@ -11,7 +11,7 @@
1111

1212
@attrs.define
1313
@logable
14-
class Message(SoupAppMessage, app_name=APP_NAME):
14+
class Message(soup_app.SoupAppMessage, app_name=APP_NAME):
1515

1616
def __init_subclass__(cls, *args, **kwargs):
1717
super().__init_subclass__(**kwargs)

src/nasdaq_protocols/sqf/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import attrs
44
from nasdaq_protocols import soup
5-
from nasdaq_protocols.soup_app.session import BaseClientSession, SessionId
5+
from nasdaq_protocols.soup import soup_app
66
from .core import Message
77

88
__all__ = [
@@ -17,13 +17,13 @@
1717

1818

1919
@attrs.define(auto_attribs=True)
20-
class SqfSessionId(SessionId):
20+
class SqfSessionId(soup_app.SoupAppSessionId):
2121
soup_session_id: soup.SoupSessionId = None
2222
protocol_name: str = "sqf"
2323

2424

2525
@attrs.define(auto_attribs=True)
26-
class ClientSession(BaseClientSession):
26+
class ClientSession(soup_app.SoupAppClientSession):
2727

2828
def _create_session_id(self):
2929
return SqfSessionId(self.soup_session.session_id)

0 commit comments

Comments
 (0)