Skip to content

Commit bad1a26

Browse files
author
Lionel Untereiner
committed
reformat code with black
1 parent 1d5f112 commit bad1a26

11 files changed

Lines changed: 920 additions & 374 deletions

etpclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#https://florimond.dev/blog/articles/2020/05/structuring-starlette-projects/
1+
# https://florimond.dev/blog/articles/2020/05/structuring-starlette-projects/

etpclient/etp/connection_register.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def get_ws_n_con(cls, client_info: ClientInfo) -> WebSocket:
2828
print(client_info.ip, ": #ConnectionRegister.get_ws_n_con")
2929
if client_info in cls.map_connection:
3030
return cls.map_connection[client_info]
31-
return None
31+
return None

etpclient/etp/etp_data_bridge.py

Lines changed: 342 additions & 133 deletions
Large diffs are not rendered by default.

etpclient/etp/etp_notifyer.py

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
from etpproto.messages import Message
88

99
from etptypes.helpers import AvroModel
10-
from etptypes.energistics.etp.v12.protocol.store_notification import UnsolicitedStoreNotifications
11-
from etptypes.energistics.etp.v12.datatypes.object.subscription_info import SubscriptionInfo
12-
from etptypes.energistics.etp.v12.datatypes.object.context_info import ContextInfo
13-
from etptypes.energistics.etp.v12.datatypes.object.relationship_kind import RelationshipKind
14-
from etptypes.energistics.etp.v12.datatypes.object.context_scope_kind import ContextScopeKind
10+
from etptypes.energistics.etp.v12.protocol.store_notification import (
11+
UnsolicitedStoreNotifications,
12+
)
13+
from etptypes.energistics.etp.v12.datatypes.object.subscription_info import (
14+
SubscriptionInfo,
15+
)
16+
from etptypes.energistics.etp.v12.datatypes.object.context_info import (
17+
ContextInfo,
18+
)
19+
from etptypes.energistics.etp.v12.datatypes.object.relationship_kind import (
20+
RelationshipKind,
21+
)
22+
from etptypes.energistics.etp.v12.datatypes.object.context_scope_kind import (
23+
ContextScopeKind,
24+
)
1525

1626
from gabbro.etp.connection_register import ConnectionRegister
1727

@@ -20,12 +30,16 @@
2030
class ETPNotifyer:
2131

2232
# For each ETPConnection, store a list of notifications subscription
23-
map_client_to_subscribtion: ClassVar[Mapping[ClientInfo, list[AvroModel]]] = {}
33+
map_client_to_subscribtion: ClassVar[
34+
Mapping[ClientInfo, list[AvroModel]]
35+
] = {}
2436

2537
unsolicited_notification: ClassVar[list[AvroModel]] = []
2638

2739
@classmethod
28-
async def subscribe(cls, client_info: ClientInfo, subscription: Any) -> None:
40+
async def subscribe(
41+
cls, client_info: ClientInfo, subscription: Any
42+
) -> None:
2943
print(client_info.ip, ": #ETPNotiyer.subscribe")
3044

3145
if client_info not in cls.map_client_to_subscribtion:
@@ -34,7 +48,9 @@ async def subscribe(cls, client_info: ClientInfo, subscription: Any) -> None:
3448
cls.map_client_to_subscribtion[client_info].append(subscription)
3549

3650
@classmethod
37-
async def unsubscribe(cls, client_info: ClientInfo, subscription: Any) -> None:
51+
async def unsubscribe(
52+
cls, client_info: ClientInfo, subscription: Any
53+
) -> None:
3854
print(client_info.ip, ": #ETPNotiyer.unsubscribe")
3955
cls.map_client_to_subscribtion.pop(client_info, None)
4056

@@ -48,22 +64,36 @@ async def trigger(cls, notif_content: Any):
4864
async def _notify(cls, client_info: ClientInfo, msg: bytes):
4965
print(client_info.ip, ": #ETPNotiyer._notify")
5066
websocket, connection = ConnectionRegister.get_ws_n_con(client_info)
51-
67+
5268
if websocket:
5369
await websocket.send_bytes(msg)
5470
else:
55-
print(client_info.ip, ": #ETPNotiyer._notify => websocket not found")
71+
print(
72+
client_info.ip, ": #ETPNotiyer._notify => websocket not found"
73+
)
5674

5775
@classmethod
5876
async def send_unsolicited_notification(cls, client_info: ClientInfo):
59-
print(client_info.ip, ": #ETPNotiyer.send_unsolicited_notification : <", len(cls.unsolicited_notification), ">")
77+
print(
78+
client_info.ip,
79+
": #ETPNotiyer.send_unsolicited_notification : <",
80+
len(cls.unsolicited_notification),
81+
">",
82+
)
6083
websocket, connection = ConnectionRegister.get_ws_n_con(client_info)
6184

6285
for msg in cls.unsolicited_notification:
6386
m = Message.get_object_message(etp_object=msg)
64-
print(client_info.ip, ": sending unsolicited_notification ", m, "\n\n")
87+
print(
88+
client_info.ip,
89+
": sending unsolicited_notification ",
90+
m,
91+
"\n\n",
92+
)
6593

66-
async for msg_part in connection.send_msg_and_error_generator(m, None):
94+
async for msg_part in connection.send_msg_and_error_generator(
95+
m, None
96+
):
6797
await websocket.send_bytes(msg_part)
6898

6999
@classmethod
@@ -72,13 +102,16 @@ def add_unsolicited_notification(cls, msg: AvroModel):
72102

73103

74104
u_store_notif = UnsolicitedStoreNotifications(
75-
subscriptions=[
76-
SubscriptionInfo( context=ContextInfo(uri="eml:///", depth=3, navigable_edges=RelationshipKind.BOTH),
77-
scope=ContextScopeKind.SOURCES,
78-
request_uuid=pyUUID.uuid4().bytes,
79-
start_time=0,
80-
include_object_data=False,
81-
)
82-
]
83-
)
105+
subscriptions=[
106+
SubscriptionInfo(
107+
context=ContextInfo(
108+
uri="eml:///", depth=3, navigable_edges=RelationshipKind.BOTH
109+
),
110+
scope=ContextScopeKind.SOURCES,
111+
request_uuid=pyUUID.uuid4().bytes,
112+
start_time=0,
113+
include_object_data=False,
114+
)
115+
]
116+
)
84117
ETPNotifyer.add_unsolicited_notification(msg=u_store_notif)

etpclient/etp/h5_handler.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
11
import h5py
22

33
from etpclient.utils import (
4-
search_all_element_value,
5-
get_xml_dict_from_path,
6-
get_xml_dict_from_string,
7-
xml_dict_get_uri
4+
search_all_element_value,
5+
get_xml_dict_from_path,
6+
get_xml_dict_from_string,
7+
xml_dict_get_uri,
88
)
99

1010
from etptypes.energistics.etp.v12.protocol.data_array.put_data_arrays import (
1111
PutDataArrays,
1212
)
1313

14-
def descend_obj(obj,sep='\t'):
14+
15+
def descend_obj(obj, sep="\t"):
1516
"""
1617
Iterate through groups in a HDF5 file and prints the groups and datasets names and datasets attributes
1718
"""
18-
if type(obj) in [h5py._hl.group.Group,h5py._hl.files.File]:
19+
if type(obj) in [h5py._hl.group.Group, h5py._hl.files.File]:
1920
for key in obj.keys():
20-
print(sep,'-',key,':',obj[key])
21-
descend_obj(obj[key],sep=sep+'\t')
21+
print(sep, "-", key, ":", obj[key])
22+
descend_obj(obj[key], sep=sep + "\t")
2223
elif type(obj) == h5py._hl.dataset.Dataset:
2324
print("-------------------")
2425
for key in obj.attrs.keys():
25-
print(sep+'\t','-',key,':',obj.attrs[key])
26+
print(sep + "\t", "-", key, ":", obj.attrs[key])
2627
print(obj[...])
2728

2829

29-
def h5dump(path,group='/'):
30+
def h5dump(path, group="/"):
3031
"""
3132
print HDF5 file metadata
3233
3334
group: you can give a specific group, defaults to the root group
3435
"""
35-
with h5py.File(path,'r') as f:
36-
descend_obj(f[group])
36+
with h5py.File(path, "r") as f:
37+
descend_obj(f[group])
38+
3739

3840
def h5_search_dataset(h5_file_path, path_in_hdf):
39-
with h5py.File(h5_file_path,'r') as f:
41+
with h5py.File(h5_file_path, "r") as f:
4042
# _h5_search_dataset_in_obj(f[group])
4143
dataset = f[path_in_hdf]
4244
if dataset is not None:
4345
return dataset[...], dataset.shape, dataset.dtype
4446
print("Dataset", path_in_hdf, "not found in", h5_file_path)
4547
return None
4648

47-
def generate_put_data_arrays(xml_obj: str, h5_file_path: str, dataspace: str=None):
49+
50+
def generate_put_data_arrays(
51+
xml_obj: str, h5_file_path: str, dataspace: str = None
52+
):
4853
res = []
49-
54+
5055
obj_dict = get_xml_dict_from_string(xml_obj)
51-
for path_in_hdf in search_all_element_value(obj_dict, "PathInExternalFile") + search_all_element_value(obj_dict, "PathInHdfFile"):
56+
for path_in_hdf in search_all_element_value(
57+
obj_dict, "PathInExternalFile"
58+
) + search_all_element_value(obj_dict, "PathInHdfFile"):
5259
data, shape, dtype = h5_search_dataset(h5_file_path, path_in_hdf)
5360
pda_dict = {
5461
"dataArrays": {
@@ -59,11 +66,7 @@ def generate_put_data_arrays(xml_obj: str, h5_file_path: str, dataspace: str=Non
5966
},
6067
"array": {
6168
"dimensions": list(shape),
62-
"data": {
63-
"item": {
64-
"values": data.flatten().tolist()
65-
}
66-
},
69+
"data": {"item": {"values": data.flatten().tolist()}},
6770
},
6871
"customData": {},
6972
}
@@ -72,4 +75,4 @@ def generate_put_data_arrays(xml_obj: str, h5_file_path: str, dataspace: str=Non
7275
res.append(PutDataArrays.parse_obj(pda_dict))
7376
# res.append(h5_search_dataset(h5_file_path, path_in_hdf))
7477

75-
return res
78+
return res

0 commit comments

Comments
 (0)