-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverprotocols.py
724 lines (644 loc) · 26.2 KB
/
serverprotocols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
#
# Copyright (c) 2022-2023 Geosiris.
# SPDX-License-Identifier: Apache-2.0
#
from typing import Union, AsyncGenerator, Optional
from datetime import datetime
import uuid as pyUUID
import pprint
import lxml.etree as etree
import json
from etpproto.messages import Message
from etptypes.energistics.etp.v12.datatypes.message_header import MessageHeader
from etptypes import avro_schema
from etpproto.connection import CommunicationProtocol, Protocol, ETPConnection
from etpproto.client_info import ClientInfo
from etpproto.protocols.core import CoreHandler
from etpproto.protocols.discovery import DiscoveryHandler
from etpproto.protocols.store import StoreHandler
from etpproto.protocols.data_array import DataArrayHandler
from etpproto.protocols.supported_types import SupportedTypesHandler
from etpproto.protocols.dataspace import DataspaceHandler
from etptypes.energistics.etp.v12.datatypes.data_value import DataValue
from etptypes.energistics.etp.v12.datatypes.contact import Contact
from etptypes.energistics.etp.v12.datatypes.object.data_object import (
DataObject,
)
from etptypes.energistics.etp.v12.datatypes.object.dataspace import Dataspace
from etptypes.energistics.etp.v12.datatypes.object.deleted_resource import (
DeletedResource,
)
from etptypes.energistics.etp.v12.datatypes.object.put_response import (
PutResponse,
)
from etptypes.energistics.etp.v12.datatypes.object.resource import Resource
from etptypes.energistics.etp.v12.datatypes.object.supported_type import (
SupportedType,
)
from etptypes.energistics.etp.v12.datatypes.server_capabilities import (
ServerCapabilities,
)
from etptypes.energistics.etp.v12.datatypes.supported_data_object import (
SupportedDataObject,
)
from etptypes.energistics.etp.v12.datatypes.supported_protocol import (
SupportedProtocol,
)
from etptypes.energistics.etp.v12.datatypes.uuid import Uuid
from etptypes.energistics.etp.v12.datatypes.version import *
from etptypes.energistics.etp.v12.protocol.core.close_session import (
CloseSession,
)
from etptypes.energistics.etp.v12.protocol.core.acknowledge import Acknowledge
from etptypes.energistics.etp.v12.protocol.core.open_session import OpenSession
from etptypes.energistics.etp.v12.protocol.core.ping import Ping
from etptypes.energistics.etp.v12.protocol.core.pong import Pong
from etptypes.energistics.etp.v12.protocol.core.protocol_exception import (
ProtocolException,
)
from etptypes.energistics.etp.v12.protocol.core.request_session import (
RequestSession,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_array_metadata import (
GetDataArrayMetadata,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_array_metadata_response import (
GetDataArrayMetadataResponse,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_arrays import (
GetDataArrays,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_arrays_response import (
GetDataArraysResponse,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_subarrays import (
GetDataSubarrays,
)
from etptypes.energistics.etp.v12.protocol.data_array.get_data_subarrays_response import (
GetDataSubarraysResponse,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_data_arrays import (
PutDataArrays,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_data_arrays_response import (
PutDataArraysResponse,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_data_subarrays import (
PutDataSubarrays,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_data_subarrays_response import (
PutDataSubarraysResponse,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_uninitialized_data_arrays import (
PutUninitializedDataArrays,
)
from etptypes.energistics.etp.v12.protocol.data_array.put_uninitialized_data_arrays_response import (
PutUninitializedDataArraysResponse,
)
from etptypes.energistics.etp.v12.protocol.dataspace.delete_dataspaces import (
DeleteDataspaces,
)
from etptypes.energistics.etp.v12.protocol.dataspace.delete_dataspaces_response import (
DeleteDataspacesResponse,
)
from etptypes.energistics.etp.v12.protocol.dataspace.get_dataspaces import (
GetDataspaces,
)
from etptypes.energistics.etp.v12.protocol.dataspace.get_dataspaces_response import (
GetDataspacesResponse,
)
from etptypes.energistics.etp.v12.protocol.dataspace.put_dataspaces import (
PutDataspaces,
)
from etptypes.energistics.etp.v12.protocol.dataspace.put_dataspaces_response import (
PutDataspacesResponse,
)
from etptypes.energistics.etp.v12.protocol.discovery.get_deleted_resources import (
GetDeletedResources,
)
from etptypes.energistics.etp.v12.protocol.discovery.get_deleted_resources_response import (
GetDeletedResourcesResponse,
)
from etptypes.energistics.etp.v12.protocol.discovery.get_resources import (
GetResources,
)
from etptypes.energistics.etp.v12.protocol.discovery.get_resources_response import (
GetResourcesResponse,
)
from etptypes.energistics.etp.v12.protocol.store.delete_data_objects import (
DeleteDataObjects,
)
from etptypes.energistics.etp.v12.protocol.store.get_data_objects import (
GetDataObjects,
)
from etptypes.energistics.etp.v12.protocol.store.get_data_objects_response import (
GetDataObjectsResponse,
)
from etptypes.energistics.etp.v12.protocol.store.put_data_objects import (
PutDataObjects,
)
from etptypes.energistics.etp.v12.protocol.store.put_data_objects_response import (
PutDataObjectsResponse,
)
from etptypes.energistics.etp.v12.protocol.store.delete_data_objects_response import (
DeleteDataObjectsResponse,
)
from etptypes.energistics.etp.v12.protocol.supported_types.get_supported_types import (
GetSupportedTypes,
)
from etptypes.energistics.etp.v12.protocol.supported_types.get_supported_types_response import (
GetSupportedTypesResponse,
)
# from geoetp.etp.etp_data_bridge import ETPDataBridge
# from geoetp.etp.hsds_bridge import HSDSBridge
pretty_p = pprint.PrettyPrinter(width=100, compact=True)
# etp_bridge = ETPDataBridge()
# ______ __ __
# / ____/___ ________ ____ _________ / /_____ _________ / /
# / / / __ \/ ___/ _ \ / __ \/ ___/ __ \/ __/ __ \/ ___/ __ \/ /
# / /___/ /_/ / / / __/ / /_/ / / / /_/ / /_/ /_/ / /__/ /_/ / /
# \____/\____/_/ \___/ / .___/_/ \____/\__/\____/\___/\____/_/
# /_/
def print_resource(res: Resource):
print("Resource :", res.uri)
print("\tSource count :", res.source_count)
print("\tTarget count :", res.target_count)
# print("\tLast change :", datetime.fromtimestamp(res.last_changed))
def print_dataspace(res: Dataspace):
print("Dataspace :", res.uri)
print("\tStore last write :", res.store_last_write)
print("\tStore created :", res.store_created)
print("\tPath :", res.path)
print("\ttCustom data :", res.custom_data)
# print("\tLast change :", datetime.fromtimestamp(res.last_changed))
def print_protocol_exception(pe: ProtocolException):
if pe.error is not None:
print("Error recieved : " + str(pe))
elif len(pe.errors) > 0:
print(f"Errors recieved ({pe.errors}): ")
for code, pe in pe.errors.items():
print(f"\t{code}) {str(pe)}")
@ETPConnection.on(CommunicationProtocol.CORE)
class myCoreProtocol(CoreHandler):
uuid: Uuid = pyUUID.uuid4()
async def on_open_session(
self,
msg: OpenSession,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print("OpenSession recieved")
yield
async def on_close_session(
self,
msg: CloseSession,
correlation_id: int,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_close_session")
yield
async def on_ping(
self,
msg: Ping,
correlation_id: int,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": #Core : Ping recieved")
yield Message.get_object_message(
Pong(currentDateTime=int(datetime.utcnow().timestamp())),
correlation_id=correlation_id,
)
async def on_pong(
self,
msg: Pong,
correlation_id: int,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": #Core : Pong recieved")
yield
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print_protocol_exception(msg)
yield
# ____ _ ____ __ __
# / __ \(_)_____________ _ _____ _______ __ / __ \_________ / /_____ _________ / /
# / / / / / ___/ ___/ __ \ | / / _ \/ ___/ / / / / /_/ / ___/ __ \/ __/ __ \/ ___/ __ \/ /
# / /_/ / (__ ) /__/ /_/ / |/ / __/ / / /_/ / / ____/ / / /_/ / /_/ /_/ / /__/ /_/ / /
# /_____/_/____/\___/\____/|___/\___/_/ \__, / /_/ /_/ \____/\__/\____/\___/\____/_/
# /____/
@ETPConnection.on(CommunicationProtocol.DISCOVERY)
class myDiscoveryProtocol(DiscoveryHandler):
async def on_get_resources_response(
self,
msg: GetResourcesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(
"## myDiscoveryProtocol ## on_get_resources_response : nb[",
len(msg.resources),
"]",
)
for res in msg.resources:
print_resource(res)
yield
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print_protocol_exception(msg)
yield
async def on_get_deleted_resources_response(
self,
msg: GetDeletedResourcesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
if msg is not None:
if len(msg.deleted_resources) > 0:
print(f"Deleted object list ({len(msg.deleted_resources)}) : ")
for dr in msg.deleted_resources:
print(f"\t{dr.uri} \tdeleted_time: \t{dr.deleted_time}")
else:
print("No deleted resource found for this context")
yield
async def on_acknowledge(
self,
msg: Acknowledge,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(f"Message recieved {msg}")
yield
# ____ __
# / __ \____ _/ /_____ __________ ____ _________ _____
# / / / / __ `/ __/ __ `/ ___/ __ \/ __ `/ ___/ _ \/ ___/
# / /_/ / /_/ / /_/ /_/ (__ ) /_/ / /_/ / /__/ __(__ )
# /_____/\__,_/\__/\__,_/____/ .___/\__,_/\___/\___/____/
# /_/
@ETPConnection.on(CommunicationProtocol.DATASPACE)
class myDataspaceHandler(DataspaceHandler):
async def on_delete_dataspaces(
self,
msg: DeleteDataspaces,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_delete_dataspaces")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_get_dataspaces(
self,
msg: GetDataspaces,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_dataspaces")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_put_dataspaces(
self,
msg: PutDataspaces,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_put_dataspaces")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_delete_dataspaces_response(
self,
msg: DeleteDataspacesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
pretty_p.pprint(msg)
yield
# raise NotSupportedError()
async def on_get_dataspaces_response(
self,
msg: GetDataspacesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
for dataspace in msg.dataspaces:
print_dataspace(dataspace)
yield
# raise NotSupportedError()
async def on_put_dataspaces_response(
self,
msg: PutDataspacesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
pretty_p.pprint(msg)
yield
# raise NotSupportedError()
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print_protocol_exception(msg)
yield
# _____ __ ____ __ __
# / ___// /_____ ________ / __ \_________ / /_____ _________ / /
# \__ \/ __/ __ \/ ___/ _ \ / /_/ / ___/ __ \/ __/ __ \/ ___/ __ \/ /
# ___/ / /_/ /_/ / / / __/ / ____/ / / /_/ / /_/ /_/ / /__/ /_/ / /
# /____/\__/\____/_/ \___/ /_/ /_/ \____/\__/\____/\___/\____/_/
@ETPConnection.on(CommunicationProtocol.STORE)
class myStoreProtocol(StoreHandler):
async def on_get_data_objects(
self,
msg: GetDataObjects,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_data_objects")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_put_data_objects(
self,
msg: PutDataObjects,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_put_data_objects")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_delete_data_objects(
self,
msg: DeleteDataObjects,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_delete_data_objects")
etpObj, etpErr = await etp_bridge.handle_request(msg, client_info)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_get_data_objects_response(
self,
msg: GetDataObjectsResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print("# on_get_data_objects_response")
# pretty_p.pprint(msg)
for do in msg.data_objects.values():
form = do.format_.lower()
try:
if form == "xml":
print(do.data.decode("utf-8"))
elif form == "json":
json.dumps(
json.loads(do.data.data.decode("utf-8")), indent=4
)
except Exception as e:
print("\n\n=============", e, "\n")
pretty_p.pprint(do)
yield
async def on_put_data_objects_response(
self,
msg: PutDataObjectsResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(f"Success {len(msg.success)}:")
for code, pr in msg.success.items():
print(f"\t{code}) {str(pr.created_contained_object_uris)}")
yield
async def on_delete_data_objects_response(
self,
msg: DeleteDataObjectsResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(f"Deletion success {len(msg.deleted_uris)}:")
for code, aos in msg.deleted_uris.items():
print(f"\t{code}) {str(aos)}")
yield
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print_protocol_exception(msg)
yield
# ____ __ ___ ____ __ __
# / __ \____ _/ /_____ _/ | ______________ ___ __ / __ \_________ / /_____ _________ / /
# / / / / __ `/ __/ __ `/ /| | / ___/ ___/ __ `/ / / / / /_/ / ___/ __ \/ __/ __ \/ ___/ __ \/ /
# / /_/ / /_/ / /_/ /_/ / ___ |/ / / / / /_/ / /_/ / / ____/ / / /_/ / /_/ /_/ / /__/ /_/ / /
# /_____/\__,_/\__/\__,_/_/ |_/_/ /_/ \__,_/\__, / /_/ /_/ \____/\__/\____/\___/\____/_/
# /____/
@ETPConnection.on(CommunicationProtocol.DATA_ARRAY)
class myDataArrayHandler(DataArrayHandler):
# hsdsbridge: HSDSBridge = HSDSBridge('alwyn')
async def on_get_data_array_metadata(
self,
msg: GetDataArrayMetadata,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_data_array_metadata")
etpObj, etpErr = myDataArrayHandler.hsdsbridge.handle_metadata(msg)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_get_data_array_metadata_response(
self,
msg: GetDataArrayMetadataResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(client_info.ip, msg)
yield
async def on_get_data_arrays(
self,
msg: GetDataArrays,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_data_arrays")
etpObj, etpErr = myDataArrayHandler.hsdsbridge.send_request(msg)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_get_data_subarrays(
self,
msg: GetDataSubarrays,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_data_subarrays")
etpObj, etpErr = myDataArrayHandler.hsdsbridge.send_request(msg)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_get_data_arrays_response(
self,
msg: GetDataArraysResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(client_info.ip, msg)
yield
async def on_get_data_subarrays_response(
self,
msg: GetDataSubarraysResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(client_info.ip, msg)
yield
async def on_put_data_arrays(
self,
msg: PutDataArrays,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_put_data_arrays")
etpObj, etpErr = myDataArrayHandler.hsdsbridge.send_request(msg)
yield Message.get_object_message(etpObj, correlation_id=correlation_id)
yield etpErr
async def on_put_data_arrays_response(
self,
msg: PutDataArraysResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print(client_info.ip, msg)
yield
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[Optional[Message], None]:
print_protocol_exception(msg)
yield
# _____ __ ________
# / ___/__ ______ ____ ____ _____/ /____ ____/ /_ __/_ ______ ___ _____
# \__ \/ / / / __ \/ __ \/ __ \/ ___/ __/ _ \/ __ / / / / / / / __ \/ _ \/ ___/
# ___/ / /_/ / /_/ / /_/ / /_/ / / / /_/ __/ /_/ / / / / /_/ / /_/ / __(__ )
# /____/\__,_/ .___/ .___/\____/_/ \__/\___/\__,_/ /_/ \__, / .___/\___/____/
# /_/ /_/ /____/_/
@ETPConnection.on(CommunicationProtocol.SUPPORTED_TYPES)
class mySupportedTypesProtocol(SupportedTypesHandler):
async def on_get_supported_types(
self,
msg: GetSupportedTypes,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print(client_info.ip, ": on_get_supported_types")
yield
async def on_get_supported_types_response(
self,
msg: GetSupportedTypesResponse,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
for st in msg.supported_types:
print(f"\t{st.data_object_type}\t count : {str(st.object_count)}")
yield
async def on_protocol_exception(
self,
msg: ProtocolException,
msg_header: MessageHeader,
client_info: Union[None, ClientInfo] = None,
) -> AsyncGenerator[bytes, None]:
print_protocol_exception(msg)
yield
# _____ ______
# / ___/___ ______ _____ _____ / ____/___ _____ _____
# \__ \/ _ \/ ___/ | / / _ \/ ___/ / / / __ `/ __ \/ ___/
# ___/ / __/ / | |/ / __/ / / /___/ /_/ / /_/ (__ )
# /____/\___/_/ |___/\___/_/ \____/\__,_/ .___/____/
# /_/
# ATTENTION : A FAIRE EN DERNIER ! a cause de supportedProtocolList_fun()
@ETPConnection.dec_server_capabilities()
def computeCapability(supportedProtocolList_fun) -> ServerCapabilities:
protocolDict = supportedProtocolList_fun()
# pretty_p.pprint(protocolDict)
return ServerCapabilities(
application_name="etpproto",
application_version="1.1.2",
supported_protocols=list(
map(
lambda d: SupportedProtocol(
protocol=d.protocol,
protocol_version=d.protocol_version,
role="store",
protocol_capabilities=d.protocol_capabilities,
),
protocolDict,
)
),
supported_data_objects=[
# SupportedDataObject(
# qualified_type="resqml20.*",
# data_object_capabilities={}),
# data_object_capabilities={"SupportsGet": True, "SupportsPut": True, "SupportsDelete": True}),
# SupportedDataObject(
# qualified_type="resqml22.*",
# data_object_capabilities={}),
# # data_object_capabilities={"SupportsGet": True, "SupportsPut": True, "SupportsDelete": True})
# SupportedDataObject({'dataObjectCapabilities': {'SupportsDelete': {'item': {'boolean': True}},
# 'SupportsGet': {'item': {'boolean': True}},
# 'SupportsPut': {'item': {'boolean': True}}
# )
# SupportedDataObject(
# qualified_type="eml20.*",
# data_object_capabilities={
# "SupportsDelete": DataValue(item=True),
# "SupportsPut": DataValue(item=True),
# "SupportsGet": DataValue(item=True),
# },
# ),
# SupportedDataObject(
# qualified_type="resqml20.*",
# data_object_capabilities={
# "SupportsDelete": DataValue(item=True),
# "SupportsPut": DataValue(item=True),
# "SupportsGet": DataValue(item=True),
# },
# ),
SupportedDataObject(
qualified_type="witsml20.*",
data_object_capabilities={
"SupportsDelete": DataValue(item=True),
"SupportsPut": DataValue(item=True),
"SupportsGet": DataValue(item=True),
},
),
SupportedDataObject(
qualified_type="witsml21.*",
data_object_capabilities={
"SupportsDelete": DataValue(item=True),
"SupportsPut": DataValue(item=True),
"SupportsGet": DataValue(item=True),
},
),
],
# supported_compression=["gzip"],
supported_formats=["xml"],
endpoint_capabilities={
"MaxWebSocketMessagePayloadSize": DataValue(item=4000)
},
supported_encodings=["binary"],
contact_information=Contact(
organization_name="Geosiris",
contact_name="Gauthier Valentin, Untereiner Lionel",
contact_phone="",
contact_email="valentin.gauthier@geosiris.com, lionel.untereiner@geosiris.com",
),
)