From f581929f93ffa8a9742ed3f9641f5344f7a364f9 Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Sun, 7 Jan 2024 08:54:58 +0100 Subject: [PATCH] Update version 3.0 info and docs - Relax memory tests with lazy option to avoid some extemporary failures - Remove xmlns_processing_default='none' if XML data source is None (None can be a valid decoded value with the default converter, in any case this is irrelevant for the result) --- CHANGELOG.rst | 7 ++++--- LICENSE | 2 +- doc/features.rst | 32 ++++++++++++++++++++------------ publiccode.yml | 4 ++-- tests/test_memory.py | 6 +++--- xmlschema/__init__.py | 2 +- xmlschema/converters/default.py | 2 -- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40f07c6e..8608fd18 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,10 +2,10 @@ CHANGELOG ********* -`v3.0.0`_ (2023-XX-XX) +`v3.0.0`_ (2024-01-07) ====================== -* XML declaration processing options -* Decode/validate with dynamic schema load +* XML declaration processing option *xmlns_processing* for converters +* Decode/validate from XML document with dynamic schema load * XMLResource enhancement for a better XML resources processing * Improve lazy resources iteration removing preceding elements (*thin_mode* option) * Drop support for Python 3.7 @@ -654,3 +654,4 @@ v0.9.6 (2017-05-05) .. _v2.4.0: https://github.com/brunato/xmlschema/compare/v2.3.1...v2.4.0 .. _v2.5.0: https://github.com/brunato/xmlschema/compare/v2.4.0...v2.5.0 .. _v2.5.1: https://github.com/brunato/xmlschema/compare/v2.5.0...v2.5.1 +.. _v3.0.0: https://github.com/brunato/xmlschema/compare/v2.5.1...v3.0.0 diff --git a/LICENSE b/LICENSE index c5eed424..cd55dd36 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c), 2016-2022, SISSA (Scuola Internazionale Superiore di Studi Avanzati) +Copyright (c), 2016-2024, SISSA (Scuola Internazionale Superiore di Studi Avanzati) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/doc/features.rst b/doc/features.rst index bfcf50f2..f9e7cf5d 100644 --- a/doc/features.rst +++ b/doc/features.rst @@ -79,28 +79,36 @@ With version 3.0 the processing of namespace information of the XML document has been improved, with the default of maintaining an exact namespace mapping between the XML source and the decoded data. -For the decoding API the argument *xmlns_usage* has been added, in order to change -the usage mode of the XML namespace declarations of the document. +The feature is available both with the decoding and encoding API with the new converter +option *xmlns_processing*, that permits to change the processing mode of the namespace +declarations of the XML document. -The default of this option is *'exact'* which means that the loaded namespace declarations -always match the ones defined in the XML document. In this case the namespace map is -updated dynamically, adding and removing the XML declarations found in internal elements. -This choice provide the most accurate mapping of the namespace information of the XML -document. +The preferred mode is *'stacked'*, the mode that maintains a stack of namespace mapping +contexts, with the active context that always match the namespace declarations defined +in the XML document. In this case the namespace map is updated dynamically, adding and +removing the XML declarations found in internal elements. This choice provide the most +accurate mapping of the namespace information of the XML document. -Use the option value *'collapsed'* for loading all namespace declarations of the XML -source before decoding. In this case The declarations are merged into a static namespace -map, using alternative prefixes in case of collision. This is the legacy behaviour of -versions prior to 3 of the library. +Use the option value *'collapsed'* for loading all namespace declarations in a single +map. In this case the declarations are merged into the namespace map of the converter, +using alternative prefixes in case of collision. +This is the legacy behaviour of versions prior to 3 of the library. With *'root-only'* only the namespace declarations of the XML document root are loaded. -In this case you are expected to provided the internal namespace information with +In this case you are expected to provide the internal namespace information with *namespaces* argument. Use *'none'* to not load any namespace declaration of the XML document. Use this option if you don't want to map namespaces to prefixes or you want to provide a fully custom namespace mapping. +For default *xmlns_processing* option is set automatically depending by the converter +class capability and the XML data source. The option is available also for +encoding with updated converter classes that can retrieve xmlns declarations from +decoded data (e.g. :class:`xmlschema.JsonMLConverter` or the default converter). +For decoding the default is set to *'stacked'* or *'collapsed'*, for encoding the +default can be also *'none'* if no namespace declaration can be retrieved from XML +data (e.g. :class:`xmlschema.ParkerConverter`). Lazy validation =============== diff --git a/publiccode.yml b/publiccode.yml index 3a75d344..c344e14b 100644 --- a/publiccode.yml +++ b/publiccode.yml @@ -6,8 +6,8 @@ publiccodeYmlVersion: '0.2' name: xmlschema url: 'https://github.com/sissaschool/xmlschema' landingURL: 'https://github.com/sissaschool/xmlschema' -releaseDate: '2023-12-19' -softwareVersion: v2.5.1 +releaseDate: '2024-01-07' +softwareVersion: v3.0.0 developmentStatus: stable platforms: - linux diff --git a/tests/test_memory.py b/tests/test_memory.py index b2b84653..c782e510 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -27,7 +27,7 @@ class TestMemoryUsage(unittest.TestCase): @staticmethod def check_memory_profile(output): - """Check the output of a memory memory profile run on a function.""" + """Check the output of a memory profile run on a function.""" mem_usage = [] func_num = 0 for line in output.split('\n'): @@ -99,7 +99,7 @@ def test_decode_memory_usage(self): lazy_decode_mem = self.check_memory_profile(output) self.assertLessEqual(decode_mem, 2.6) - self.assertLessEqual(lazy_decode_mem, 1.8) + self.assertLessEqual(lazy_decode_mem, 2.1) def test_validate_memory_usage(self): with tempfile.TemporaryDirectory() as dirname: @@ -126,7 +126,7 @@ def test_validate_memory_usage(self): lazy_validate_mem = self.check_memory_profile(output) self.assertLess(validate_mem, 2.6) - self.assertLess(lazy_validate_mem, 1.8) + self.assertLess(lazy_validate_mem, 2.1) if __name__ == '__main__': diff --git a/xmlschema/__init__.py b/xmlschema/__init__.py index d88f5b8a..cadf98b5 100644 --- a/xmlschema/__init__.py +++ b/xmlschema/__init__.py @@ -35,7 +35,7 @@ __version__ = '3.0.0' __author__ = "Davide Brunato" __contact__ = "brunato@sissa.it" -__copyright__ = "Copyright 2016-2023, SISSA" +__copyright__ = "Copyright 2016-2024, SISSA" __license__ = "MIT" __status__ = "Production/Stable" diff --git a/xmlschema/converters/default.py b/xmlschema/converters/default.py index 16567827..bb367ea2 100644 --- a/xmlschema/converters/default.py +++ b/xmlschema/converters/default.py @@ -194,8 +194,6 @@ def xmlns_processing_default(self) -> str: return 'stacked' else: return 'collapsed' - elif self.source is None: - return 'none' elif getattr(self.element_encode, 'stackable', False): return 'stacked' else: