maxml 1.0.0__tar.gz → 1.0.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxml
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: A streamlined pure Python XML serializer.
5
5
  Author: Daniel Sissman
6
6
  License-Expression: MIT
@@ -139,14 +139,40 @@ class Element(object):
139
139
 
140
140
  self._namespaces: set[Namespace] = set()
141
141
 
142
+ for key in list(attributes.keys()):
143
+ if key.startswith("xmlns:") and (xmlns := key.replace("xmlns:", "")):
144
+ for namespace in self.__class__._namespaces:
145
+ if namespace.prefix == xmlns:
146
+ break
147
+ else:
148
+ namespace = Namespace(prefix=xmlns, uri=attributes[key])
149
+
150
+ self.__class__._namespaces.add(namespace)
151
+
152
+ self._namespaces.add(namespace)
153
+
154
+ del attributes[key]
155
+
142
156
  if namespace is None:
143
157
  for namespace in self.__class__._namespaces:
144
158
  if namespace.prefix == prefix:
145
159
  break
146
160
  else:
147
- raise ValueError(
148
- f"No namespace has been registered for the '{prefix}' prefix associated with the '{name}' element!"
149
- )
161
+ for key in list(attributes.keys()):
162
+ if key.startswith("xmlns:") and key.endswith(prefix):
163
+ namespace = Namespace(prefix=prefix, uri=attributes[key])
164
+
165
+ self.__class__._namespaces.add(namespace)
166
+
167
+ self._namespaces.add(namespace)
168
+
169
+ del attributes[key]
170
+
171
+ break
172
+ else:
173
+ raise ValueError(
174
+ f"No namespace has been registered for the '{prefix}' prefix associated with the '{name}' element!"
175
+ )
150
176
 
151
177
  self._namespaces.add(namespace.copy().promote())
152
178
  elif isinstance(uri := namespace, str):
@@ -350,7 +376,10 @@ class Element(object):
350
376
  "The 'value' argument must have a value that can be cast to a string!"
351
377
  )
352
378
 
353
- self._attributes[name] = value
379
+ if name.startswith("xmlns:"):
380
+ self.register_namespace(prefix=name.replace("xmlns:", ""), uri=value)
381
+ else:
382
+ self._attributes[name] = value
354
383
 
355
384
  return self
356
385
 
@@ -588,6 +617,9 @@ class Element(object):
588
617
  # Add any attributes
589
618
  count = len(element.attributes)
590
619
  for index, (key, value) in enumerate(element.attributes.items(), start=1):
620
+ if key.startswith("xmlns:"):
621
+ continue
622
+
591
623
  if pretty and count > 1 and index >= 1 and index <= count:
592
624
  string += f"\n{indent * (depth + 2)}"
593
625
  newline = True
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxml
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: A streamlined pure Python XML serializer.
5
5
  Author: Daniel Sissman
6
6
  License-Expression: MIT
@@ -1 +0,0 @@
1
- 1.0.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes