pyAS4 8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyas4-8/PKG-INFO ADDED
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyAS4
3
+ Version: 8
4
+ Summary: Your package description
5
+ Author: Andrey Shapovalov
6
+ Author-email: mt.andrey@gmail.com
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Dynamic: author-email
File without changes
@@ -0,0 +1,214 @@
1
+ import uuid
2
+
3
+ from lxml import etree
4
+
5
+ _NS = {
6
+ "query": "urn:oasis:names:tc:ebxml-regrep:xsd:query:4.0",
7
+ "rs": "urn:oasis:names:tc:ebxml-regrep:xsd:rs:4.0",
8
+ "rim": "urn:oasis:names:tc:ebxml-regrep:xsd:rim:4.0",
9
+ "xsi": "http://www.w3.org/2001/XMLSchema-instance",
10
+ "sdg": "http://data.europa.eu/sdg#",
11
+ "s12": "http://www.w3.org/2003/05/soap-envelope",
12
+ "eu": "http://eu.domibus.wsplugin/",
13
+ "eb3": "http://docs.oasis-open.org/ebxml-msg/ebms/v3.0/ns/core/200704/",
14
+ }
15
+
16
+
17
+ def _nsmap(ns: str, tag: str) -> str:
18
+ return f"{{{_NS[ns]}}}{tag}"
19
+
20
+
21
+ class Header:
22
+ """
23
+ Represents an ebXML-compatible messaging header, allowing for configuration of
24
+ various party identifiers, service/action details, and payload-related data.
25
+
26
+ This class is designed to facilitate the construction and management of an
27
+ ebXML AS4-compliant messaging XML, including functionality to dynamically
28
+ append payload information. The primary purpose of this class is to support
29
+ eDelivery-compliant systems by structuring the metadata and delivering
30
+ message-based document exchange.
31
+
32
+ :ivar c1_party_id: Identifier for Party 1 involved in the message exchange.
33
+ :ivar c1_party_id_type: The type of the identifier used for Party 1.
34
+ :ivar c2_party_id: Identifier for Party 2 involved in the message exchange.
35
+ :ivar c2_party_id_type: The type of the identifier used for Party 2.
36
+ :ivar c3_party_id: Identifier for Party 3 involved in the message exchange.
37
+ :ivar c3_party_id_type: The type of the identifier used for Party 3.
38
+ :ivar c4_party_id: Identifier for Party 4 involved in the message exchange.
39
+ :ivar c4_party_id_type: The type of the identifier used for Party 4.
40
+ :ivar conversationid: Unique identifier for the conversation thread.
41
+ :ivar service: Service URL to describe the functionality invoked.
42
+ :ivar service_type: Specific type of the service provided.
43
+ :ivar action: Action URL defining the invoked operation.
44
+ :ivar role: Role URL describing the role of the communicating party.
45
+ """
46
+
47
+ def __init__(self,
48
+ c1_party_id: str,
49
+ c1_party_id_type: str,
50
+ c2_party_id: str,
51
+ c2_party_id_type: str,
52
+ c3_party_id: str,
53
+ c3_party_id_type: str,
54
+ c4_party_id: str,
55
+ c4_party_id_type: str,
56
+ conversationid: str = str(uuid.uuid4()),
57
+ service: str = "http://docs.oasis-open.org/ebxml-msg/as4/200902/service",
58
+ service_type: str = "urn:oasis:names:tc:ebcore:ebrs:ebms:binding:1.0",
59
+ action: str = "http://docs.oasis-open.org/ebxml-msg/as4/200902/action",
60
+ role: str = "http://sdg.europa.eu/edelivery/gateway"
61
+ ):
62
+ """
63
+ Initializes an instance of the class with required and optional attributes to configure
64
+ a messaging context as per the specified standards. It validates non-None constraints
65
+ for mandatory parameters.
66
+
67
+ :param c1_party_id: Identifier for Party 1 involved in the message exchange.
68
+ :param c1_party_id_type: The type of the identifier used for Party 1.
69
+ :param c2_party_id: Identifier for Party 2 involved in the message exchange.
70
+ :param c2_party_id_type: The type of the identifier used for Party 2.
71
+ :param c3_party_id: Identifier for Party 3 involved in the message exchange.
72
+ :param c3_party_id_type: The type of the identifier used for Party 3.
73
+ :param c4_party_id: Identifier for Party 4 involved in the message exchange.
74
+ :param c4_party_id_type: The type of the identifier used for Party 4.
75
+ :param conversationid: (Optional) Unique identifier for the conversation thread.
76
+ Defaults to a random UUID.
77
+ :param service: (Optional) Service URL to describe the functionality invoked.
78
+ Defaults to "http://docs.oasis-open.org/ebxml-msg/as4/200902/service".
79
+ :param service_type: (Optional) Specific type of the service provided.
80
+ Defaults to "urn:oasis:names:tc:ebcore:ebrs:ebms:binding:1.0".
81
+ :param action: (Optional) Action URL defining the invoked operation.
82
+ Defaults to "http://docs.oasis-open.org/ebxml-msg/as4/200902/action".
83
+ :param role: (Optional) Role URL describing the role of the communicating party.
84
+ Defaults to "http://sdg.europa.eu/edelivery/gateway".
85
+ :raises ValueError: If any of the mandatory `c1_party_id`, `c2_party_id`,
86
+ `c3_party_id`, or `c4_party_id` parameters are None.
87
+ """
88
+ if None in (c1_party_id, c2_party_id, c3_party_id, c4_party_id):
89
+ raise ValueError("Parameters must not be None")
90
+
91
+ self._xml = etree.Element(_nsmap('eb3', 'Messaging'), nsmap=_NS)
92
+
93
+ self.c1_party_id = c1_party_id
94
+ self.c1_party_id_type = c1_party_id_type
95
+ self.c2_party_id = c2_party_id
96
+ self.c2_party_id_type = c2_party_id_type
97
+ self.c3_party_id = c3_party_id
98
+ self.c3_party_id_type = c3_party_id_type
99
+ self.c4_party_id = c4_party_id
100
+ self.c4_party_id_type = c4_party_id_type
101
+ self.service = service
102
+ self.service_type = service_type
103
+ self.action = action
104
+ self.conversationid = conversationid
105
+ self.role = role
106
+ self.pay_load_info = self.__toxml()
107
+
108
+ def __toxml(self) -> etree._Element:
109
+ """
110
+ Generates and returns an XML element representing a `PayloadInfo` node with nested
111
+ structure for UserMessage, PartyInfo, CollaborationInfo, and MessageProperties
112
+ based on the provided instance attributes.
113
+
114
+ This method uses the lxml.etree library to structure an XML tree,
115
+ populating the sub-elements with instance-specific data.
116
+
117
+ :return: An XML element 'PayloadInfo' with the nested structure.
118
+ :rtype: etree._Element
119
+ """
120
+
121
+ user_message = etree.SubElement(self._xml, _nsmap('eb3', 'UserMessage'))
122
+
123
+ party_info = etree.SubElement(user_message, _nsmap('eb3', 'PartyInfo'))
124
+ froms = etree.SubElement(party_info, _nsmap('eb3', 'From'))
125
+ etree.SubElement(froms, _nsmap('eb3', 'PartyId'),
126
+ attrib={'type': self.c2_party_id_type},
127
+ ).text=self.c2_party_id
128
+ etree.SubElement(froms, _nsmap('eb3', 'Role'),
129
+ ).text=self.role
130
+
131
+ to = etree.SubElement(party_info, _nsmap('eb3', 'To'))
132
+ etree.SubElement(to, _nsmap('eb3', 'PartyId'),
133
+ attrib={'type': self.c3_party_id_type},
134
+ ).text=self.c3_party_id
135
+ etree.SubElement(to, _nsmap('eb3', 'Role'),
136
+ ).text=self.role
137
+
138
+ collaboration_info = etree.SubElement(user_message, _nsmap('eb3', 'CollaborationInfo'))
139
+ etree.SubElement(collaboration_info, _nsmap('eb3', 'Service'),
140
+ type="urn:oasis:names:tc:ebcore:ebrs:ebms:binding:1.0",
141
+ ).text=self.service
142
+ etree.SubElement(collaboration_info, _nsmap('eb3', 'Action'),
143
+ ).text=self.action
144
+ etree.SubElement(collaboration_info, _nsmap('eb3', 'ConversationId'),
145
+ ).text=self.conversationid
146
+
147
+ message_proportis = etree.SubElement(user_message, _nsmap('eb3', 'MessageProperties'))
148
+ etree.SubElement(message_proportis, _nsmap('eb3', 'Property'),
149
+ attrib={
150
+ 'name': 'originalSender',
151
+ 'type': self.c1_party_id_type},
152
+ ).text=self.c1_party_id
153
+ etree.SubElement(message_proportis, _nsmap('eb3', 'Property'),
154
+ attrib={
155
+ 'name': 'finalRecipient',
156
+ 'type': self.c4_party_id_type},
157
+ ).text=self.c4_party_id
158
+
159
+ pay_load_info = etree.SubElement(user_message, _nsmap('eb3', 'PayloadInfo'))
160
+
161
+ return pay_load_info
162
+
163
+ def payload_append(self, payloads: list[dict[str, str]]):
164
+ """
165
+ Appends payload information to the internal XML structure.
166
+
167
+ This method processes a list of payload dictionaries and appends their
168
+ information into an internal XML structure represented by `self.pay_load_info`.
169
+ Each dictionary in the input list contains details about a single payload, such
170
+ as its `href`, `mimetype`, and optionally its `CompressionType`.
171
+
172
+ :param payloads: List of dictionaries, where each dictionary represents a
173
+ payload with at least the keys `href` (str) and `mimetype` (str). The key
174
+ `CompressionType` (str) is optional.
175
+ :return: None
176
+ """
177
+ for payload in payloads:
178
+ pl = etree.SubElement(self.pay_load_info, _nsmap('eb3', 'PartInfo'),
179
+ attrib={'href': payload['href']})
180
+ pp = etree.SubElement(pl, _nsmap('eb3', 'PartProperties'),)
181
+ etree.SubElement(pp, _nsmap('eb3', 'Property'),
182
+ attrib={'name': "MimeType"},
183
+ ).text=payload['mimetype']
184
+ if payload.get('CompressionType', None):
185
+ etree.SubElement(pp, _nsmap('eb3', 'Property'),
186
+ attrib={'name': "CompressionType"},
187
+ ).text=payload['CompressionType']
188
+
189
+ @property
190
+ def element(self) -> etree._Element:
191
+ """
192
+ Returns the underlying XML element associated with this object.
193
+
194
+ This property provides access to the root XML element, enabling direct
195
+ manipulation or query of the XML structure represented by it.
196
+
197
+ :return: The root XML element of the object.
198
+ :rtype: etree._Element
199
+ """
200
+ return self._xml
201
+
202
+ @property
203
+ def xml(self) -> bytes:
204
+ """
205
+ Provides a property to retrieve the XML representation of an element.
206
+
207
+ This property generates and returns the XML content of the associated
208
+ element in a byte string format with pretty-print formatting applied.
209
+
210
+ :return: A byte string containing the XML representation of the element
211
+ with pretty-print formatting.
212
+ :rtype: Bytes
213
+ """
214
+ return etree.tostring(self.element, pretty_print=True)
pyas4-8/pyAS4/py.typed ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyAS4
3
+ Version: 8
4
+ Summary: Your package description
5
+ Author: Andrey Shapovalov
6
+ Author-email: mt.andrey@gmail.com
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ Dynamic: author-email
@@ -0,0 +1,10 @@
1
+ pyproject.toml
2
+ setup.py
3
+ pyAS4/__init__.py
4
+ pyAS4/header.py
5
+ pyAS4/py.typed
6
+ pyAS4.egg-info/PKG-INFO
7
+ pyAS4.egg-info/SOURCES.txt
8
+ pyAS4.egg-info/dependency_links.txt
9
+ pyAS4.egg-info/not-zip-safe
10
+ pyAS4.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ pyAS4
pyas4-8/pyproject.toml ADDED
@@ -0,0 +1,12 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pyAS4"
7
+ version = "8"
8
+ description = "Your package description"
9
+ authors = [{ name="Andrey Shapovalov" }]
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ dependencies = []
pyas4-8/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
pyas4-8/setup.py ADDED
@@ -0,0 +1,13 @@
1
+ from setuptools import setup
2
+
3
+ setup(
4
+ name='pyAS4',
5
+ version='8',
6
+ license='MIT',
7
+ author='Andrii Shapovalov',
8
+ author_email='mt.andrey@gmail.com',
9
+ description='',
10
+ packages=['pyAS4'],
11
+ package_data={'pyAS4': ['py.typed']},
12
+ zip_safe=False
13
+ )