pyRegRep 5__py3-none-any.whl

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.
@@ -0,0 +1,135 @@
1
+ import logging
2
+
3
+ from lxml import etree
4
+
5
+ _logger = logging.getLogger(__name__)
6
+
7
+
8
+ class Parsing:
9
+ def __init__(self, doc: bytes):
10
+ self.xml = doc.decode("utf-8")
11
+ parser = etree.XMLParser(remove_comments=True)
12
+ self.doc = etree.fromstring(doc, parser)
13
+ self._ns = {}
14
+ for perfix, uri in self.doc.nsmap.items():
15
+ if perfix is None:
16
+ perfix = "default"
17
+ self._ns.update({perfix: uri})
18
+ self.query = self.doc.find(".//query:Query", namespaces=self._ns)
19
+ self.exception = self.doc.find(".//rs:Exception", namespaces=self._ns)
20
+ self.objects = self.doc.findall(".//rim:RegistryObject", namespaces=self._ns)
21
+ self.slots = self.__list_slots()
22
+
23
+ def __tname(self, ns: str, tag: str) -> str:
24
+ if not ns:
25
+ return tag
26
+ return f"{{{self._ns[ns]}}}{tag}"
27
+
28
+ def __slot(self, name: str) -> etree._Element | None:
29
+ slot = self.doc.find(f".//rim:Slot[@name='{name}']", namespaces=self._ns)
30
+ if slot is None:
31
+ return None
32
+ return slot
33
+
34
+ def __value(self, slot: etree._Element):
35
+ slot = slot[0]
36
+ type_ = slot.get(self.__tname("xsi", "type"), '').split(":")[1].strip() #
37
+
38
+ if "AnyValueType" in type_:
39
+ return type_, slot[0]
40
+
41
+ elif "InternationalStringValueType" in type_:
42
+ values = []
43
+ for i, item in enumerate(list(slot[0])):
44
+ value = {
45
+ "lang": item.get(self.__tname("xsi", "lang")),
46
+ "value": item.get("value"),
47
+ }
48
+ values.append(value)
49
+ return type_, values
50
+
51
+ elif "CollectionValueType" in type_:
52
+ values = []
53
+ for i, item in enumerate(list(slot)):
54
+ wrapper = etree.Element("wrapper")
55
+ wrapper.append(item)
56
+ values.append(self.__value(wrapper))
57
+ return type_, values
58
+ else:
59
+ return type_, slot[0].text
60
+
61
+ def __list_slots(self) -> dict[str, tuple[str, str]]:
62
+ edm: dict = {"doc": {}, "query": {}, "exception": {}, "object": {}}
63
+ for slot in list(self.doc):
64
+ if slot.tag == self.__tname("rim", "Slot"):
65
+ name = slot.get("name")
66
+ edm["doc"].update({name: (self.__value(slot))})
67
+ continue
68
+ elif slot.tag == self.__tname("query", "Query"):
69
+ for query in list(slot):
70
+ name = query.get("name")
71
+ edm["query"].update({name: (self.__value(query))})
72
+ continue
73
+ elif slot.tag == self.__tname("rs", "Exception"):
74
+ for exception in list(slot):
75
+ name = exception.get("name")
76
+ edm["exception"].update({name: (self.__value(exception))})
77
+ continue
78
+ elif slot.tag == self.__tname("rim", "RegistryObjectList"):
79
+ for registryObject in list(slot):
80
+ ev = {}
81
+ for evidense in list(registryObject):
82
+ if evidense.tag == self.__tname("rim", "Slot"):
83
+ ev.update({evidense.get("name"): self.__value(evidense)})
84
+ if evidense.tag == self.__tname("rim", "RepositoryItemRef"):
85
+ ev.update(
86
+ {
87
+ "RepositoryItemRef": {
88
+ "xlink": evidense.get(
89
+ self.__tname("xlink", "href")
90
+ ),
91
+ "title": evidense.get(
92
+ self.__tname("xlink", "title")
93
+ ),
94
+ }
95
+ }
96
+ )
97
+ edm["object"].update(ev)
98
+ continue
99
+ else:
100
+ continue
101
+
102
+ return edm
103
+
104
+ def serialize(self):
105
+ def transform_data(data):
106
+ if isinstance(data, list):
107
+ return [transform_data(item) for item in data]
108
+
109
+ elif isinstance(data, dict):
110
+ return {k: transform_data(v) for k, v in data.items()}
111
+
112
+ elif isinstance(data, tuple) and len(data) == 2:
113
+ data_type, value = data
114
+
115
+ if data_type == 'BooleanValueType':
116
+ return value.lower() == 'true'
117
+
118
+ elif data_type == 'StringValueType':
119
+ return value.strip()
120
+
121
+ elif data_type == 'CollectionValueType':
122
+ return transform_data(value)
123
+
124
+ elif data_type == 'AnyValueType':
125
+ return value
126
+
127
+ elif data_type == 'InternationalStringValueType':
128
+ return transform_data(value)
129
+
130
+ # Якщо тип не підпав під умови, повертаємо значення як є
131
+ return transform_data(value) if isinstance(value, (list, dict)) else value
132
+
133
+ return data
134
+
135
+ return transform_data(self.slots)
pyRegRep4/__init__.py ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyRegRep
3
+ Version: 5
4
+ Author: Andrii Shapovalov
5
+ Author-email: mt.andrey@gmail.com
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Dynamic: author
9
+ Dynamic: author-email
10
+ Dynamic: license
11
+ Dynamic: license-file
@@ -0,0 +1,7 @@
1
+ pyRegRep4/RIMParsing.py,sha256=gOvnnl0Egb2OuGDxJBnxSRqsmkBNnfPx20RZTAovNOQ,5208
2
+ pyRegRep4/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pyregrep-5.dist-info/licenses/LICENSE,sha256=cvlq-Cgdbj7JhKDAE6dHqXQ4bUVxPGurui4Sw7J5vJI,1074
4
+ pyregrep-5.dist-info/METADATA,sha256=PFf33Fye6YWD27QeeBsbdI0Usy8pqhSlHXM3lVbpSfs,220
5
+ pyregrep-5.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
6
+ pyregrep-5.dist-info/top_level.txt,sha256=Ohkj-k67v8v13HzhVbDK61Z3mQo5H85IsWEs2-STq2Y,10
7
+ pyregrep-5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shapovalov Andrey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pyRegRep4