Commit Graph

729 Commits

Author SHA1 Message Date
Davide Brunato c276e1188e Fix test_files.py script (use unittest's loaders) 2019-08-09 14:41:23 +02:00
Davide Brunato f8ad4d975c Code cleaning: remove get_xml_bool_attribute() helper function 2019-08-09 12:45:11 +02:00
Davide Brunato 211d1deca7 Update test_w3c_suite.py
- Additional options (--xsd10, --xsd11, --valid, --invalid, a
    list of indexes) to run only a subset of the W3C tests.
  - Run also XML tests with --xml option.
  - Add filter for import warnings that are out of the scope of
    tests with W3C XSD 1.1 suite
2019-08-08 12:31:43 +02:00
Davide Brunato 13950ad958 Fix element matching in XsdGroup.iter_encode() 2019-08-05 21:53:30 +02:00
Davide Brunato 52d1e1bb8e Close XSD 1.1 development
- Still some W3C and local tests to be fixed
  - Fix min/max facets derivation (decode with primitive type)
2019-08-05 17:57:34 +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 3d38e87d2e Clean iter_decode and iter_encode arguments for XSD components 2019-08-02 16:19:55 +02:00
Davide Brunato 3f99689197 Add etree_pruning(elem, selector) helper function 2019-08-01 23:56:13 +02:00
Davide Brunato f2a30baf32 Fix XSD 1.1 bugs with W3C XML Schema suite 2019-08-01 17:16:12 +02:00
Davide Brunato df5c454b24 Add minimal schema for versioning namespace
- Added XMLSchemaNamespaceError for namespace related errors
  - version_check moved to schema class
  - resolve_qname() now raises KeyError if namespace prefix is not found
  - resolve_qname() now raises XMLSchemaNamespaceError if a namespace
    is mapped with a prefix but is not loaded by an import
2019-08-01 07:03:03 +02:00
Davide Brunato 6e90de7b4c Add Version Control namespace attributes
- Added xsd_version property to XSD components
  - Add version_check() helper to XsdValidator base class
2019-07-31 14:19:02 +02:00
Davide Brunato d4bb951a45 Improve schema checks
- Checked and improved 'built' properties for XSD components:
      * Simple types, attributes and attribute group are now built
        withoug cheching on base types.
      * Don't check global subcomponents: the scope of built is to
        assure that local parts are built.
  - Split global maps checks from build phase:
      * XsdGlobals._check_schema substituted by check() method with
        two opional arguments. The new methos is useful also to check
        global maps also after schema building.
  - Added validator=None argument to parse_error() method
2019-07-30 14:52:51 +02:00
Davide Brunato 3d33424541 Refactor and clean reference and name attributes parsing
- Add an helper method _parse_reference()
  - Removed ref property, replaced by attribute
2019-07-29 16:01:48 +02:00
Davide Brunato a2a843a322 Add test module for XSD identities 2019-07-29 16:01:19 +02:00
Davide Brunato 035be87572 Complete XSD 1.1 wildcards (xs:any and xs:anyAttribute) 2019-07-23 16:02:17 +02:00
Davide Brunato 38ba4447f6 Add extension check for openContent 2019-07-20 08:37:05 +02:00
Davide Brunato e26d20b770 Add restriction check for openContent 2019-07-19 18:54:19 +02:00
Davide Brunato 56a7ee26a9 Fix is_valid() arguments for complex type 2019-07-17 08:56:02 +02:00
Davide Brunato 657e1c16f0 Split tests of schemas and validators to subpackages
- This is a premise for expanding basic test cases on schemas,
    validation, decoding and encoding.
2019-07-16 09:45:54 +02:00
Davide Brunato 35089f9354 Add tests for XSD any wildcards
- Update docs with XSD 1.1 validator support
  - Fix: XsdAnyElement substituted with BUILDERS.any_element_class
    in shared 1.0/1.1 code
2019-07-13 09:47:59 +02:00
Davide Brunato 3db78707b1 Complete openContent and defaultOpenContent parsing 2019-07-12 18:22:11 +02:00
Davide Brunato cb3754f503 Transform meta-schema validation errors to parse errors
- In XMLSchema.__init__() the errors generated by check_schema()
    are now raised or transformed to parse errors
  - Only parse errors are generated during schema building
  - More compact errors that omit meta-schema parts
2019-07-12 11:21:35 +02:00
Davide Brunato dded8b163f Add sort_content() to ModelVisitor class
- Added TestModelBasedSorting to test_models.py
2019-07-11 11:45:29 +02:00
Davide Brunato 759de2ee0e Clean encoding tests and fix converter instance creation
- Removed additional test classes added with PR #117;
  - Removed additional converter argument from the calls of the
    method get_converter(), that causes errors when the argument
    'converter' is provided but not with an instance.
2019-07-11 10:47:02 +02:00
Davide Brunato 87cc74fc44 Added unordered and collapsed encoding modes
- Keep UnorderedConverter class as the default converter for
    encoding unordered data
  - Added 'unordered=False' option to iter_encode's arguments
  - Added iter_unordered_content() and iter_collapsed_content()
    to ModelVisitor class
2019-07-11 09:43:12 +02:00
Davide Brunato 40d0207968 Clean element matching
- Added custom is_matching() and match() for XsdElement
  - Removed custom match() for XsdAnyElement and XsdAnyAttribute
  - Added matched_element() to XsdAnyElement
  - Added matched_element() to XsdElement as match() alias
  - Removed iter_elements() from XsdGroup (do not iter substitutes)
  - Removed iter_subelement() from ModelGroup (use iter_elements)
  - Clean converter code on some element_encode() implementations
2019-07-08 09:37:29 +02:00
Daniel Hillier 61e1f609fc Stop reading `name` and `url` from file object attrs
These attrs shouldn't be used to reopen the file object as:
- they may not reflect the original file or resource (file objects
  opened from a zipfile will have a name that doesn't correspond to any
  file on disk).
- Depending on how the fid was opened, these attrs could be crafted to
  read arbitrary files from disk. If the creator of a .zip gives a file
  inside the zip file a path of `/etc/passwd` we may end up opening that
  file.

Instead of reopening the file, we keep track of the file object and seek
to the beginning of the file. This means (for most operations) the file
object must be seekable. On Python 2 urlopen returns an unseekable
object for 'file://' paths. One test had to be skipped in Python 2 for
this reason.
2019-07-06 15:25:10 +10:00
Daniel Hillier 4085e8daa5 Add failing test when reloading xml from zipfile content.
This problem comes from the way `XMLResource` re-opens files if it wants
to get more information from them. `XMLResource` is deriving the source
location of file like objects from their `name` attr. When that attr
doesn't correspond to a file on disk (zipfile contents, Django files) an
error is raised when `XMLResource.open()` is called.
2019-07-05 22:21:48 +10:00
Davide Brunato 5a5a0f6d47 Merge branch 'master' of github.com:sissaschool/xmlschema into develop 2019-07-03 06:51:49 +02:00
Davide Brunato dcf264eaf1 Code cleaning on some test scripts 2019-07-02 21:41:03 +02:00
Davide Brunato 40fd9d9137
Merge pull request #117 from danifus/visitorconv
Add VisitorConverter: uses visitor model for encoding
2019-07-02 17:16:23 +02:00
Davide Brunato 1f3a72a2c8 Code cleaning for converter classes
- Add lossy property as a replace for lossless (not lossy)
  - replace _unmap_attribute_qname() with unmap_prefixed()
  - Add deprecation warnings for old methods
2019-07-02 15:46:59 +02:00
Davide Brunato 57e2f96337 Add unmap_prefixed() to NamespaceMapper class 2019-07-02 15:31:28 +02:00
Daniel Hillier 9455216eaa Rename VisitorConverter and related code
Rename VisitorConverter to UnorderedConverter and other related small
tidy ups.
Remove VisitorConverter from package's __init__.py
2019-07-02 22:58:45 +10:00
Daniel Hillier b2c3adbf43 Add test for encoding unordered content
Add test for when it should pass and when it should fail.
2019-07-02 12:22:21 +10:00
Daniel Hillier 6bee8769d5 Split encoding of unordered content between converter and validators.groups
This makes the process of turning a dictionary of unordered element
content into ordered elements available to other converters.
2019-07-02 11:11:32 +10:00
Daniel Hillier a15cb1dc11 Add VisitorConverter: uses visitor model for encoding
- Resolves #69
  This approach allows strict encoding and validation of an unordered
  dictionary without having to handle errors.
- Can generate correct xml for repeated sequences of multiple elements:
  {"A": [1, 2], "B": [3, 4]} -> <A>1</A><B>3</B><A>2</A><B>4</B>
- VisitorConverter raises an Exception if the data being encoded
  contains cdata. The unordered processing of the dict means character
  data may not be placed in the correct locations.
- Reuses existing encoding tests.
2019-07-02 10:59:39 +10:00
Davide Brunato 02899117f0
Merge pull request #118 from danifus/trailingcontent
Raise error when encoding group overflows and validation="strict"
2019-07-01 16:18:02 +02:00
Davide Brunato 8fbe4ca0b5
Merge pull request #114 from Retsur/master
Regexp: Fix implementation of multi-character escapes.
2019-06-30 14:09:28 +02:00
Daniel Hillier 4ecfcca66d Raise error when encoding group overflows and validation="strict" 2019-06-29 01:03:18 +10:00
Davide Brunato 97a0da7138 Fix regex \w and \W shortcuts in character class (PR #114) 2019-06-27 13:43:50 +02:00
Davide Brunato 7d20e8eff1 Add tests for meta-schema and add XMLSchema11 to package base
- Build meta-schema when is used for validation/decode/encode
    or the builtin-types() accessor is used
  - Add clear() method to XMLSchema base class
2019-06-27 10:48:25 +02:00
Davide Brunato bdf09fa181 Memory optimizations
- Meta schema lazy build: reduce memory usage for meta-schema if
    only one schema class is used between XMLSchema10 and XMLSchema11
  - Improve import_package() in check_memory.py
2019-06-26 15:51:16 +02:00
Davide Brunato 281a426ec4 Code optimization on parse helpers
- Remove iter_xsd_components() and has_hsd_components() helpers
    replaced by filter() and any() calls
2019-06-26 07:27:18 +02:00
Davide Brunato d3775dad0e Remove attribute 'broken' from ModelVisitor
- Attribute replaced by a local variable in XsdGroup.iter_decode()
2019-06-23 08:49:16 +02:00
Davide Brunato 2de9756b73 Fix expected items on model checking
- Empty expected fixed in ModelVisitor.advance()
  - Better message for expected tags for XMLSchemaChildrenValidationError
2019-06-21 22:20:32 +02:00
Davide Brunato 6994da5173 Code refactoring for tests
- Rename XMLSchemaTestCase to XsdValidatorTestCase
  - Add casepath() helper
  - Modify TestResources: derive from TestCase and use casepath()
  - Split test_package.py into 3 modules (added test_etree.py and
    test_memory.py)
  - Update .tox with new environments 'package' and 'memory'
  - Replace test_package with test_etree into test_all.py script
  - Modify XsdValidatorTestCase.check_schema() to use xs prefix for
    XSD namespace and no namespace as targetNamespace for a fast
    reuse of common and user sample cases
2019-06-20 15:35:04 +02:00
Davide Brunato 443912fe4b Merge branch 'develop' for hotfix release v1.0.13 2019-06-19 20:06:52 +02:00
Davide Brunato 81849f2368 Fix path normalization and tests for Windows platform 2019-06-19 20:02:45 +02:00
Davide Brunato 4296a6c455 Merge branch 'master' of github.com:brunato/xmlschema 2019-06-19 17:34:00 +02:00