py-serializable 1.0.2__tar.gz → 1.0.3__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.
Files changed (51) hide show
  1. {py_serializable-1.0.2 → py_serializable-1.0.3}/CHANGELOG.md +59 -0
  2. {py_serializable-1.0.2 → py_serializable-1.0.3}/PKG-INFO +1 -1
  3. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/conf.py +1 -1
  4. {py_serializable-1.0.2 → py_serializable-1.0.3}/pyproject.toml +5 -5
  5. {py_serializable-1.0.2 → py_serializable-1.0.3}/serializable/__init__.py +9 -1
  6. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-1-v4.xml +3 -1
  7. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-v4.json +5 -1
  8. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-defaultNS-isset-v4.xml +3 -1
  9. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-defaultNS-mixed-v4.xml +3 -1
  10. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-defaultNS-unset-v4.xml +3 -1
  11. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/model.py +60 -2
  12. {py_serializable-1.0.2 → py_serializable-1.0.3}/LICENSE +0 -0
  13. {py_serializable-1.0.2 → py_serializable-1.0.3}/README.md +0 -0
  14. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/Makefile +0 -0
  15. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/changelog.rst +0 -0
  16. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/customising-structure.rst +0 -0
  17. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/examples.rst +0 -0
  18. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/formatters.rst +0 -0
  19. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/getting-started.rst +0 -0
  20. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/index.rst +0 -0
  21. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/make.bat +0 -0
  22. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/requirements.txt +0 -0
  23. {py_serializable-1.0.2 → py_serializable-1.0.3}/docs/support.rst +0 -0
  24. {py_serializable-1.0.2 → py_serializable-1.0.3}/serializable/formatters.py +0 -0
  25. {py_serializable-1.0.2 → py_serializable-1.0.3}/serializable/helpers.py +0 -0
  26. {py_serializable-1.0.2 → py_serializable-1.0.3}/serializable/py.typed +0 -0
  27. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/__init__.py +0 -0
  28. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/base.py +0 -0
  29. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-1-v1.xml +0 -0
  30. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-1-v2.xml +0 -0
  31. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-1-v3.xml +0 -0
  32. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-1.xml +0 -0
  33. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-references.json +0 -0
  34. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-v2.json +0 -0
  35. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-v3.json +0 -0
  36. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-with-ignored.json +0 -0
  37. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case-with-ignored.xml +0 -0
  38. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-camel-case.json +0 -0
  39. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-defaultNS-isset.SNAPSHOT.xml +0 -0
  40. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-defaultNS-unset.SNAPSHOT.xml +0 -0
  41. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-kebab-case-1-v2.xml +0 -0
  42. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-kebab-case-1.xml +0 -0
  43. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-kebab-case.json +0 -0
  44. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-snake-case-1.xml +0 -0
  45. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/fixtures/the-phoenix-project-snake-case.json +0 -0
  46. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_formatters.py +0 -0
  47. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_helpers.py +0 -0
  48. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_json.py +0 -0
  49. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_oml.py +0 -0
  50. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_oml_serializable_property.py +0 -0
  51. {py_serializable-1.0.2 → py_serializable-1.0.3}/tests/test_xml.py +0 -0
@@ -2,6 +2,65 @@
2
2
 
3
3
 
4
4
 
5
+ ## v1.0.2 (2024-03-01)
6
+
7
+ ### Build
8
+
9
+ * build: use poetry v1.8.1 (#81)
10
+
11
+ Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com> ([`46a8d9e`](https://github.com/madpah/serializable/commit/46a8d9e629ac502864a99acaa9418d1c5cd32388))
12
+
13
+ ### Chore
14
+
15
+ * chore(deps-dev): update coverage requirement from 7.4.1 to 7.4.3 (#79)
16
+
17
+ Updates the requirements on [coverage](https://github.com/nedbat/coveragepy) to permit the latest version.
18
+ - [Release notes](https://github.com/nedbat/coveragepy/releases)
19
+ - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
20
+ - [Commits](https://github.com/nedbat/coveragepy/compare/7.4.1...7.4.3)
21
+
22
+ ---
23
+ updated-dependencies:
24
+ - dependency-name: coverage
25
+ dependency-type: direct:development
26
+ ...
27
+
28
+ Signed-off-by: dependabot[bot] <support@github.com>
29
+ Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> ([`fbf9b06`](https://github.com/madpah/serializable/commit/fbf9b0609227ebb31ee3f652358f3e18e5ef71b8))
30
+
31
+ * chore(deps): bump Gr1N/setup-poetry from 8 to 9 (#80)
32
+
33
+ Bumps [Gr1N/setup-poetry](https://github.com/gr1n/setup-poetry) from 8 to 9.
34
+ - [Release notes](https://github.com/gr1n/setup-poetry/releases)
35
+ - [Commits](https://github.com/gr1n/setup-poetry/compare/v8...v9)
36
+
37
+ ---
38
+ updated-dependencies:
39
+ - dependency-name: Gr1N/setup-poetry
40
+ dependency-type: direct:production
41
+ update-type: version-update:semver-major
42
+ ...
43
+
44
+ Signed-off-by: dependabot[bot] <support@github.com>
45
+ Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> ([`3264bc6`](https://github.com/madpah/serializable/commit/3264bc6cf7ff7473968d506ea85ebc04ced0ea79))
46
+
47
+ * chore(deps-dev): update flake8-quotes requirement from 3.3.2 to 3.4.0 (#77)
48
+
49
+ Updates the requirements on [flake8-quotes](https://github.com/zheller/flake8-quotes) to permit the latest version.
50
+ - [Commits](https://github.com/zheller/flake8-quotes/compare/3.3.2...3.4.0)
51
+
52
+ ---
53
+ updated-dependencies:
54
+ - dependency-name: flake8-quotes
55
+ dependency-type: direct:development
56
+ ...
57
+
58
+ Signed-off-by: dependabot[bot] <support@github.com>
59
+ Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> ([`8a5460a`](https://github.com/madpah/serializable/commit/8a5460a453eaad49faf0245e435147bac727eb9e))
60
+
61
+ * chore: typo in SECURITY.md ([`06f557d`](https://github.com/madpah/serializable/commit/06f557db1200f019029ed5646274862f3be62643))
62
+
63
+
5
64
  ## v1.0.1 (2024-02-13)
6
65
 
7
66
  ### Chore
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-serializable
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Library for serializing and deserializing Python Objects to and from JSON and XML.
5
5
  Home-page: https://github.com/madpah/serializable#readme
6
6
  License: Apache-2.0
@@ -24,7 +24,7 @@ author = 'Paul Horton'
24
24
 
25
25
  # The full version, including alpha/beta/rc tags
26
26
  # !! version is managed by semantic_release
27
- release = "1.0.2"
27
+ release = "1.0.3"
28
28
 
29
29
  # -- General configuration ---------------------------------------------------
30
30
 
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
5
5
 
6
6
  [tool.poetry]
7
7
  name = "py-serializable"
8
- version = "1.0.2"
8
+ version = "1.0.3"
9
9
  description = "Library for serializing and deserializing Python Objects to and from JSON and XML."
10
10
  authors = ["Paul Horton <paul.horton@owasp.org>"]
11
11
  maintainers = [
@@ -59,10 +59,10 @@ defusedxml = "^0.7.1"
59
59
 
60
60
  [tool.poetry.dev-dependencies]
61
61
  tox = "4.11.4"
62
- coverage = "7.4.3"
62
+ coverage = "7.4.4"
63
63
  xmldiff = "2.6.3"
64
- mypy = "1.8.0"
65
- autopep8 = "2.0.4"
64
+ mypy = "1.9.0"
65
+ autopep8 = "2.1.0"
66
66
  isort = "5.13.2"
67
67
  flake8 = { version="7.0.0", python=">=3.8.1" }
68
68
  flake8-annotations = { version="3.0.1", python=">=3.8.1" }
@@ -70,7 +70,7 @@ flake8-bugbear = { version="24.2.6", python=">=3.8.1" }
70
70
  flake8-isort = "6.1.1"
71
71
  flake8-quotes = "3.4.0"
72
72
  flake8-use-fstring = "1.4"
73
- flake8-logging = "1.5.0"
73
+ flake8-logging = "1.6.0"
74
74
 
75
75
 
76
76
 
@@ -59,7 +59,7 @@ import typing # noqa: F401 # isort: skip
59
59
 
60
60
  # !! version is managed by semantic_release
61
61
  # do not use typing here, or else `semantic_release` might have issues finding the variable
62
- __version__ = '1.0.2'
62
+ __version__ = '1.0.3'
63
63
 
64
64
  _logger = getLogger(__name__)
65
65
  _logger.addHandler(NullHandler())
@@ -557,6 +557,14 @@ class _XmlSerializable(Protocol):
557
557
  # Handle Sub-Elements
558
558
  for child_e in data:
559
559
  decoded_k = CurrentFormatter.formatter.decode(strip_default_namespace(child_e.tag))
560
+
561
+ if decoded_k not in klass_properties:
562
+ for p, pi in klass_properties.items():
563
+ if pi.xml_array_config:
564
+ array_type, nested_name = pi.xml_array_config
565
+ if nested_name == strip_default_namespace(child_e.tag):
566
+ decoded_k = p
567
+
560
568
  if decoded_k in klass.ignore_during_deserialization:
561
569
  _logger.debug('Ignoring %s when deserializing %s.%s', decoded_k, cls.__module__, cls.__qualname__)
562
570
  continue
@@ -41,4 +41,6 @@
41
41
  <reference ref="my-ref-1" />
42
42
  </references>
43
43
  <rating>9.8</rating>
44
- </book>
44
+ <stockId>stock-id-1</stockId>
45
+ <stockId>stock-id-2</stockId>
46
+ </book>
@@ -7,6 +7,10 @@
7
7
  "number": 5,
8
8
  "name": "5th Anniversary Limited Edition"
9
9
  },
10
+ "stockIds": [
11
+ "stock-id-1",
12
+ "stock-id-2"
13
+ ],
10
14
  "publishDate": "2018-04-16",
11
15
  "type": "fiction",
12
16
  "authors": [
@@ -53,4 +57,4 @@
53
57
  "reference": "my-ref-1"
54
58
  }
55
59
  ]
56
- }
60
+ }
@@ -41,4 +41,6 @@
41
41
  </chapter>
42
42
  </chapters>
43
43
  <rating>9.8</rating>
44
- </book>
44
+ <stockId>stock-id-1</stockId>
45
+ <stockId>stock-id-2</stockId>
46
+ </book>
@@ -42,4 +42,6 @@
42
42
  </my:chapter>
43
43
  </my:chapters>
44
44
  <my:rating>9.8</my:rating>
45
- </my:book>
45
+ <my:stockId>stock-id-1</my:stockId>
46
+ <my:stockId>stock-id-2</my:stockId>
47
+ </my:book>
@@ -41,4 +41,6 @@
41
41
  </my:chapter>
42
42
  </my:chapters>
43
43
  <my:rating>9.8</my:rating>
44
- </my:book>
44
+ <my:stockId>stock-id-1</my:stockId>
45
+ <my:stockId>stock-id-2</my:stockId>
46
+ </my:book>
@@ -226,6 +226,54 @@ class BookReference:
226
226
  return f'<BookReference ref={self.ref}, targets={len(self.references)}>'
227
227
 
228
228
 
229
+ @serializable.serializable_class
230
+ class StockId(serializable.helpers.BaseHelper):
231
+
232
+ def __init__(self, id: str) -> None:
233
+ self._id = id
234
+
235
+ @property
236
+ @serializable.json_name('.')
237
+ @serializable.xml_name('.')
238
+ def id(self) -> str:
239
+ return self._id
240
+
241
+ @classmethod
242
+ def serialize(cls, o: Any) -> str:
243
+ if isinstance(o, StockId):
244
+ return str(o)
245
+ raise Exception(
246
+ f'Attempt to serialize a non-StockId: {o!r}')
247
+
248
+ @classmethod
249
+ def deserialize(cls, o: Any) -> 'StockId':
250
+ try:
251
+ return StockId(id=str(o))
252
+ except ValueError as err:
253
+ raise Exception(
254
+ f'StockId string supplied does not parse: {o!r}'
255
+ ) from err
256
+
257
+ def __eq__(self, other: Any) -> bool:
258
+ if isinstance(other, StockId):
259
+ return hash(other) == hash(self)
260
+ return False
261
+
262
+ def __lt__(self, other: Any) -> bool:
263
+ if isinstance(other, StockId):
264
+ return self._id < other._id
265
+ return NotImplemented
266
+
267
+ def __hash__(self) -> int:
268
+ return hash(self._id)
269
+
270
+ def __repr__(self) -> str:
271
+ return f'<StockId {self._id}>'
272
+
273
+ def __str__(self) -> str:
274
+ return self._id
275
+
276
+
229
277
  @serializable.serializable_class(name='bigbook',
230
278
  ignore_during_deserialization=['something_to_be_ignored', 'ignore_me', 'ignored'])
231
279
  class Book:
@@ -234,7 +282,7 @@ class Book:
234
282
  publisher: Optional[Publisher] = None, chapters: Optional[Iterable[Chapter]] = None,
235
283
  edition: Optional[BookEdition] = None, type: BookType = BookType.FICTION,
236
284
  id: Optional[UUID] = None, references: Optional[Iterable[BookReference]] = None,
237
- rating: Optional[Decimal] = None) -> None:
285
+ rating: Optional[Decimal] = None, stock_ids: Optional[Iterable[StockId]] = None) -> None:
238
286
  self._id = id or uuid4()
239
287
  self._title = title
240
288
  self._isbn = isbn
@@ -246,6 +294,7 @@ class Book:
246
294
  self._type = type
247
295
  self.references = set(references or [])
248
296
  self.rating = Decimal('NaN') if rating is None else rating
297
+ self._stock_ids = set(stock_ids or [])
249
298
 
250
299
  @property
251
300
  @serializable.xml_sequence(1)
@@ -322,6 +371,13 @@ class Book:
322
371
  def rating(self, rating: Decimal) -> None:
323
372
  self._rating = rating
324
373
 
374
+ @property
375
+ @serializable.view(SchemaVersion4)
376
+ @serializable.xml_array(XmlArraySerializationType.FLAT, 'stockId')
377
+ @serializable.xml_sequence(21)
378
+ def stock_ids(self) -> Set[StockId]:
379
+ return self._stock_ids
380
+
325
381
 
326
382
  ThePhoenixProject_v1 = Book(
327
383
  title='The Phoenix Project', isbn='978-1942788294', publish_date=date(year=2018, month=4, day=16),
@@ -343,7 +399,8 @@ ThePhoenixProject_v2 = Book(
343
399
  publisher=Publisher(name='IT Revolution Press LLC', address='10 Downing Street'),
344
400
  edition=BookEdition(number=5, name='5th Anniversary Limited Edition'),
345
401
  id=UUID('f3758bf0-0ff7-4366-a5e5-c209d4352b2d'),
346
- rating=Decimal('9.8')
402
+ rating=Decimal('9.8'),
403
+ stock_ids=[StockId('stock-id-1'), StockId('stock-id-2')]
347
404
  )
348
405
 
349
406
  ThePhoenixProject_v2.chapters.append(Chapter(number=1, title='Tuesday, September 2'))
@@ -370,6 +427,7 @@ if __name__ == '__main__':
370
427
 
371
428
  import io
372
429
  import json
430
+
373
431
  tpp_from_xml = ThePhoenixProject.from_xml( # type:ignore[attr-defined]
374
432
  io.StringIO(tpp_as_xml))
375
433
  tpp_from_json = ThePhoenixProject.from_json( # type:ignore[attr-defined]
File without changes