Commit Graph

51 Commits

Author SHA1 Message Date
Davide Brunato 22fdcc9a5a Fix etree_to_string to avoid registering reserved prefixes 2019-10-12 11:23:31 +02:00
Davide Brunato a79a5583ae Fix datetime types validation on encoding
- Add is_datetime() to XSD types classes
2019-10-11 13:26:17 +02:00
Davide Brunato b7b6fef418 Base modules refactoring for fix ElementTree import 2019-10-07 15:31:18 +02:00
Davide Brunato e6e009386a Fix library tests
- Fixed etree encoding checks for py2
  - Fixed XSD 1.1 meta-schema restriction checking
  - Set memory lazy tests to higher level (something
    changed after lazy meta-schema build, need to be
    checked with large XML files)
2019-08-20 22:10:12 +02:00
Davide Brunato 4661c1e0bf Complete versioning filter for XSD 1.1+
- etree_pruning() renamed to prune_etree
  - version_check() now is used only as selector for prune_etree()
    at schema initialization
2019-08-03 05:50:18 +02:00
Davide Brunato 3f99689197 Add etree_pruning(elem, selector) helper function 2019-08-01 23:56:13 +02:00
Davide Brunato 49f2fb1246 Update for close the release v1.0.9
- Fix SafeXMLParser and add tests for it
  - SafeXMLParser raises only pure Python ParseError exception
  - Add three XML cases with entities in xmlschema/tests/test_cases/resources/
2019-02-03 17:17:26 +01:00
Davide Brunato bd9325d745 Fix ElementTree programmatic import in etree.py 2019-02-02 10:45:50 +01:00
Davide Brunato 6fc0a10d4d Add script for testing ElementTree import 2019-02-01 18:19:26 +01:00
Davide Brunato 5f10fe67a7 Code cleaning of test scripts
- Removed old code of xmlschema imports
  - Test header enriched with Python version and platform
2019-01-31 22:09:18 +01:00
Davide Brunato cec34eeea0 Refactor of etree.py module
- Remove SafeXMLParserError and use ElementTree.ParseError
  - PyElementTree safe APIs errors are re-raised as C mod ParseError
  - Simplify ElementTree API and XMLResource class
2019-01-25 17:55:32 +01:00
Davide Brunato 2eabc190fe Replace defusedxml dependency
- The defusedxml seems to be unmaintained and has some problems
    with the ElementTree loading
  - Replaced by a safe XMLParser that forbids entities processing
2019-01-22 17:50:13 +01:00
Davide Brunato 9d6b88baae Change copyright years info 2019-01-20 16:56:10 +01:00
Davide Brunato bd90cacc7a QNames refactoring
- Moved all QNames to the same module
  - Create module helpers.py that includes XSD parse utils and name
    manipulation helper functions
2018-10-08 23:47:18 +02:00
Davide Brunato a7f5c41a85 Fix regex module
- Added several tests
  - Fixed start and end expression in regex.get_python_regex():
    now puts '^(' and ')$' instead of '^' and '$'.
  - Fixed '.' conversion in regex.get_python_regex(): raw string
    qualifier removed from string literal.
2018-09-22 15:26:00 +02:00
Davide Brunato a34033ee2f Improve matching and use unicode_literals
- Added names attribute for XSD declarations
2018-09-15 22:18:16 +02:00
Davide Brunato 96cb4b57af Refactoring of error and to etree_tostring serialization
- Added namespaces argument to etree_tostring helper method.
  - Refactored validator error string representation.
  - Moved namespaces argument at last position for methods validate
    and iter_errors of class ValidationMixin.
  - Fixed document validate API and added tests for it
2018-08-27 15:43:19 +02:00
Davide Brunato 12b50298cc Complete encoding using model visitor class
- Children validation errors use a dummy element for reproducing the
    instance (more clear and better printable than JSON conventions)
  - Fix for 'all' models visiting
  - Rewritten etree_tostring() helper function for implementing the
    reindentation of the serialized XML
  - Added tests for models validation
2018-08-22 07:06:03 +02:00
Davide Brunato 175d3a1ab3 Extension of validator error classes done
- Now all errors include reference to XML resource and namespaces
  - Added namespaces argument to iter_errors() and validate() methods
  - Modified etree_iterpath to map namespaces and to add position
    predicates for repeated tags
  - Added namespaces, relative and add_position to etree_getpath
  - XsdValidator._parse_error() renamed to parse_error
  - ValidationMixin._validation_error() renamed to validation_error
  - Added test for errors completeness
2018-08-07 21:45:30 +02:00
Davide Brunato 2ca1bb4fd3 Code cleaning for XsdGroup.iter_decode and iter_decode_children
- Fix for issue #73
  - Removed while cycle in iter_decode
  - Consider that iter_decode_children methods yield only children
    validation errors
  - Added helper function etree_last_child
2018-07-23 13:30:56 +02:00
Davide Brunato 80c200f651 Add is_etree_element helper function
- This is a more safer test for Element objects for this package, because it
    also checks that the argument is not an instance of ElementPathMixin class
  - Add tests for fetch_schema_locations and load_xml_resource functions
2018-07-13 22:40:35 +02:00
Davide Brunato a388689cc1 Complete resource API refactoring
- Set default timeout=30 to fetch_* functions
  - Use keyword arguments (**resource_options) for providing options
    for XML resource related helper functions
  - Add base_url to module level API
2018-07-11 08:58:35 +02:00
Davide Brunato dc87c4ef61 Added fetch_namespaces() to resource API
- etree_get_namespaces() removed from etree.py but left in module
    as alias of fetch_namespaces for back compatibility.
2018-07-10 12:41:39 +02:00
Davide Brunato 3e6ce18ae4 Rewritten includes and imports for schema initialization
- Now a warning message is sent to the logger for include or
    for namespace import errors
  - Add XMLSchemaImportWarning and XMLSchemaIncludeWarning
  - Add warning attribute to schemas for collecting the message
    strings about include and import warnings
  - URIDict class removed (faulty with empty fragment #)
  - Added --warning and --timeout to test factory arguments
  - Removed --network from test factory arguments
2018-07-07 11:25:00 +02:00
Davide Brunato 7cac15eaed Added xml_declaration=False to etree_tostring() 2018-07-04 14:28:04 +02:00
Davide Brunato 645c89a445 Fix lxml imports in etree.py and add -debug test option for testfiles 2018-07-03 19:07:34 +02:00
Davide Brunato 1ee9d88c01 Fix decoder tests
- Update converters (level optional parameter also for iter_decode)
  - Update tests for decoder
  - Update namespace decoding
  - Update doctest
2018-07-03 13:32:45 +02:00
Davide Brunato 375005a860 Fix for issue #71
- Added 'mixed' keyword argument in case of empty content
  - Validator tests: refined trees comparison in check_etree_encode()
2018-07-03 06:52:35 +02:00
Davide Brunato fa01fe2999 Fix for AbderaConverter.element_decode()
- Fix wrong decoding for simple content complexType with text == '0'
2018-07-02 10:24:42 +02:00
Davide Brunato 19aea791b6 Make etree_tostring compatible with lxml elements 2018-07-02 08:27:35 +02:00
Davide Brunato 554dc55dfe Move etree creation parameters to converters
- Fix nsmap set for lxml Element (use None instead of '')
  - Added optional import of lxml.etree in etree.py module
2018-07-01 22:55:31 +02:00
Davide Brunato 0c72cab78f Some fixes and improvements
- Fix XsdUnion iter_decode(): consider a list of values as
    last tentative.
  - Update etree_get_namespace(): now collects all the namespaces
    of the XML data, adding new prefixes for duplicates.
2018-06-22 13:38:26 +02:00
Davide Brunato 245ff9adb9 Improve encoding and encoding tests
- Added a method etree_elements_equal(elem, other, strict=True) on
    compare two element tree structures with some flexibility on text
    and tail (maybe needed also for attributes, but not now)
  - Fixed base_type selection in XsdAtomicRestriction.iter_encode()
2018-06-07 17:45:03 +02:00
Davide Brunato 87fc8fd07a Add encoding tests for simple elements 2018-05-28 06:51:28 +02:00
Davide Brunato 91514a8cce Add defusedxml to package requirements
Defuse XML data:
  - Added 'defuse' argument to XMLSchema class
  - Remote XML data is defused for default
  - Optionally one can disable defusing or force also
    for local XML data
2018-05-02 14:48:58 +02:00
Davide Brunato a3c6a66a62 Fix bug #58 and start integrating defusedxml library
Bug #58:
  - Added a file for test circular model detection

Integrating defusedxml:
  - defusedxml.ElementTree API loaded in etree.py
  - safe load with defusedxml only for network resources
2018-04-26 13:08:56 +02:00
Davide Brunato 347566af67 Fix issue #46
- XMLSchema class: changed get_converter() and iter_decode() to accept
    keyword arguments containing options for converters and decoding
  - Added a test for this issue into test_decoding.py
  - Renamed namespaces contants in namespaces.py
2018-03-08 18:19:39 +01:00
Davide Brunato db1821a229 Put a patch for issue #35 in XsdGroup.iter_decode
- Related to residual emptiable content parsing of a top level
    group of a sequence
  - The patch code have to be moved to XsdGroup
  - Added a case for the issue

Some refactoring to XsdComponent: target_namespace, namespace and maps
are trasformed to @property functions.

Update documentation for pass doctests.
2018-01-20 06:11:43 +01:00
Davide Brunato 43d0c77eee Fixed bug #34, updated copyright information. 2018-01-08 09:15:09 +01:00
Davide Brunato 0ed3204158 Code cleaning, test and setup scripts updated. 2017-12-28 11:51:18 +01:00
Davide Brunato 090af78c7a Key/Unique/Keyref identity constraints partially rewritten
* The `set_context` method has been removed because is not always
    applicable starting from schema;
  * Now all identity constraints paths are selected from instances;
  * XPath select functions now have a name related to the selection scope;
  * Added `etree_getpath` function in etree.py;
  * Added `maxunicode` checks in codepoints.py (issue #32, Python 2.7
    compiled without --enable-unicode=ucs4) for load only UCS-2 code points.
2017-12-28 08:28:27 +01:00
Davide Brunato 094caa146e Some refactoring and bug fixes.
- Fixed issues #28 and #29
  - Code cleaning
  - Created a "validators" subpackage that includes schemas, xsd global
    maps and all the XSD components
  - Added "prefixed_name" property to XsdComponent class
2017-12-15 15:56:07 +01:00
Davide Brunato 6e992aab09 Fixed some bugs, code cleaning:
* Fixes for bugs #14, #15, #16
  * Removed unused module xmlschema/etree.py
  * Added tests for URLs processing (test URL normalization)
  * Updated licence information (added "-2017")
2017-09-14 13:31:02 +02:00
Davide Brunato 116e429ec5 Some bugfix and code cleaning:
* fixed a bug in simpleContent restriction parsing for attributes
  * code cleaning for schemas and resources
  * XMLSchema's 'uri' attribute changed to 'url'
  * created fetch_resource(), normalize_url() and get_xml_root() in
    resources.py, in order to start an improvement of XML parsing
2017-07-12 14:05:27 +02:00
Davide Brunato b55e5b12b9 Merged validation and decoding using generators:
* New generator methods iter_encode and iter_decode
  * Defined a concrete iter_errors for XsdBase and
    removed from derived classes
  * Removed etree.py
  * Removed XMLSchemaMultipleValidatorError
  * All validators are generator function now
2017-02-02 14:16:16 +01:00
Davide Brunato f83f3e84fa Cleaned validator and decoder methods:
* Added iter_errors into each XsdBase subclasses
2017-01-28 14:49:26 +01:00
Davide Brunato 8a80ccb825 Done some code rationalizations:
* Renamed XmlSchemaValidatorError to XmlSchemaBaseValidatorError;
  * Removed methods from the base exception class XmlSchemaException;
  * Moved the body of XMLSchema.iter_errors method to a new
    function etree_validation in the etree.py module;
  * In the module etree.py: renamed the function element_to_dict to
    etree_to_dict and removed the old one that was unnecessary.
2017-01-25 12:12:55 +01:00
Davide Brunato b64bf666bd Code refactoring before completing the implementation of facet constraints:
modified:   xmlschema/__init__.py
	modified:   xmlschema/builtins.py
	modified:   xmlschema/core.py
	modified:   xmlschema/etree.py
	renamed:    xmlschema/validators.py -> xmlschema/exceptions.py
	modified:   xmlschema/factories.py
	modified:   xmlschema/parse.py
	modified:   xmlschema/qnames.py
	modified:   xmlschema/resources.py
	modified:   xmlschema/schema.py
	modified:   xmlschema/tests/test_decoding.py
	modified:   xmlschema/utils.py
	renamed:    xmlschema/components.py -> xmlschema/validators.py
2016-12-16 14:44:33 +01:00
Davide Brunato 690cb21fa3 Fixed a bug in element_to_dict function:
* Now the heuristic to decode multiple list items into a list of lists seems correct.

    modified:   setup.py
    modified:   xmlschema/components.py
    modified:   xmlschema/etree.py
    modified:   xmlschema/resources.py
    modified:   xmlschema/schema.py
    modified:   xmlschema/utils.py
2016-12-07 12:24:29 +01:00
Davide Brunato b3a3a933b9 Fixed some limitations in schemas inclusions. 2016-10-25 16:43:46 +02:00