sdcvalidator 4.6.2__tar.gz → 4.6.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 (37) hide show
  1. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/PKG-INFO +1 -1
  2. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/pyproject.toml +1 -1
  3. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/__init__.py +1 -1
  4. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/error_mapper.py +37 -0
  5. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/mcp_server.py +1 -1
  6. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/PKG-INFO +1 -1
  7. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/SOURCES.txt +1 -0
  8. sdcvalidator-4.6.3/tests/test_error_mapping_by_constraint.py +63 -0
  9. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/LICENSE +0 -0
  10. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/README.md +0 -0
  11. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/setup.cfg +0 -0
  12. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/cli.py +0 -0
  13. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/constants.py +0 -0
  14. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/converters.py +0 -0
  15. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/error_classifier.py +0 -0
  16. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/exceptions.py +0 -0
  17. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/instance_modifier.py +0 -0
  18. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/schema_checker.py +0 -0
  19. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/validator.py +0 -0
  20. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator/xsd11_restriction.py +0 -0
  21. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/dependency_links.txt +0 -0
  22. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/entry_points.txt +0 -0
  23. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/requires.txt +0 -0
  24. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/src/sdcvalidator.egg-info/top_level.txt +0 -0
  25. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_conformance.py +0 -0
  26. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_converters.py +0 -0
  27. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_error_classifier.py +0 -0
  28. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_error_mapper.py +0 -0
  29. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_instance_modifier.py +0 -0
  30. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_mcp_server.py +0 -0
  31. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_recovery.py +0 -0
  32. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_recovery_460.py +0 -0
  33. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_registry_launch.py +0 -0
  34. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_schema_checker.py +0 -0
  35. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_validator.py +0 -0
  36. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_xsd11_restriction.py +0 -0
  37. {sdcvalidator-4.6.2 → sdcvalidator-4.6.3}/tests/test_xsi_type.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdcvalidator
3
- Version: 4.6.2
3
+ Version: 4.6.3
4
4
  Summary: SDC4 structural validator with ExceptionalValue recovery — thin wrapper over xmlschema
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sdcvalidator"
7
- version = "4.6.2"
7
+ version = "4.6.3"
8
8
  description = "SDC4 structural validator with ExceptionalValue recovery — thin wrapper over xmlschema"
9
9
  license = "Apache-2.0"
10
10
  requires-python = ">=3.10"
@@ -14,7 +14,7 @@ Thin wrapper over xmlschema with two-tier error classification and the SDC4
14
14
  "quarantine-and-tag" recovery pattern (ISO 21090 ExceptionalValues).
15
15
  """
16
16
 
17
- __version__ = "4.6.2"
17
+ __version__ = "4.6.3"
18
18
 
19
19
  # etree_tostring is re-exported from xmlschema so callers can serialize the
20
20
  # ElementTree returned by validate_with_recovery() without importing xmlschema
@@ -22,6 +22,8 @@ from xmlschema.validators.exceptions import (
22
22
  XMLSchemaDecodeError,
23
23
  XMLSchemaChildrenValidationError,
24
24
  )
25
+ from xmlschema.validators import XsdAssert, XsdComponent, XsdElement
26
+ from xmlschema.validators.facets import XsdEnumerationFacets, XsdFacet
25
27
  from .constants import ExceptionalValueType, STRUCTURAL_ELEMENTS
26
28
  from .error_classifier import ErrorClassifier
27
29
 
@@ -122,6 +124,14 @@ class ErrorMapper:
122
124
  # Don't map to ExceptionalValue - let validation fail
123
125
  return None
124
126
 
127
+ # The constraint that failed decides, when xmlschema says which one it was. The wording rules
128
+ # below are the fallback: xmlschema's messages change between releases (4.6.2 and earlier
129
+ # mapped every facet violation to NI because "value must be one of [...]" and "value doesn't
130
+ # match any pattern of [...]" no longer matched them), and its validator classes do not.
131
+ ev_type = self._map_by_constraint(error)
132
+ if ev_type is not None:
133
+ return ev_type
134
+
125
135
  # For SDC4 data-bearing elements or unknown elements, map to appropriate ExceptionalValue
126
136
  # Note: We're permissive here - only STRUCTURAL_ELEMENTS fail validation
127
137
  # This allows the system to work with custom element names and future SDC versions
@@ -132,6 +142,33 @@ class ErrorMapper:
132
142
  # Should never reach here due to default rule, but just in case
133
143
  return ExceptionalValueType.NI
134
144
 
145
+ @staticmethod
146
+ def _map_by_constraint(error: XMLSchemaValidationError) -> Optional[ExceptionalValueType]:
147
+ """
148
+ The ExceptionalValue for an error, from the constraint xmlschema reports as having failed
149
+ (``error.validator``), or None when the constraint does not decide it.
150
+
151
+ - a value outside its enumeration: OTH;
152
+ - a value that breaks any other facet (pattern, length, range, digits), a built-in type's own
153
+ range (a negative nonNegativeInteger), an assertion, or an element's fixed value: INV;
154
+ - a value that is not of its type at all (a decode error): INV, as the wording rules give it.
155
+ """
156
+ if isinstance(error, XMLSchemaChildrenValidationError):
157
+ return None
158
+ if isinstance(error, XMLSchemaDecodeError):
159
+ return ExceptionalValueType.INV
160
+ validator = error.validator
161
+ if isinstance(validator, XsdEnumerationFacets):
162
+ return ExceptionalValueType.OTH
163
+ if isinstance(validator, (XsdFacet, XsdAssert)):
164
+ return ExceptionalValueType.INV
165
+ if isinstance(validator, XsdElement) and validator.fixed is not None:
166
+ return ExceptionalValueType.INV
167
+ if callable(validator) and not isinstance(validator, XsdComponent):
168
+ # A built-in type's own facet: xmlschema checks it with a plain function.
169
+ return ExceptionalValueType.INV
170
+ return None
171
+
135
172
  def is_structural_error(self, error: XMLSchemaValidationError) -> bool:
136
173
  """
137
174
  Classify an error as structural (Tier 1) vs semantic (Tier 2).
@@ -36,7 +36,7 @@ from sdcvalidator.schema_checker import validate_sdc4_schema_compliance
36
36
  JSONRPC_VERSION = "2.0"
37
37
  MCP_PROTOCOL_VERSION = "2024-11-05"
38
38
  SERVER_NAME = "sdcvalidator"
39
- SERVER_VERSION = "4.6.2"
39
+ SERVER_VERSION = "4.6.3"
40
40
 
41
41
  # Validator cache: schema_path -> SDC4Validator
42
42
  _validators: dict[str, SDC4Validator] = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdcvalidator
3
- Version: 4.6.2
3
+ Version: 4.6.3
4
4
  Summary: SDC4 structural validator with ExceptionalValue recovery — thin wrapper over xmlschema
5
5
  Author: Axius SDC, Inc.
6
6
  License-Expression: Apache-2.0
@@ -23,6 +23,7 @@ tests/test_conformance.py
23
23
  tests/test_converters.py
24
24
  tests/test_error_classifier.py
25
25
  tests/test_error_mapper.py
26
+ tests/test_error_mapping_by_constraint.py
26
27
  tests/test_instance_modifier.py
27
28
  tests/test_mcp_server.py
28
29
  tests/test_recovery.py
@@ -0,0 +1,63 @@
1
+ """
2
+ ExceptionalValue mapping by the constraint that failed (4.6.3).
3
+
4
+ Before 4.6.3 the mapper matched xmlschema's English messages, and when xmlschema's wording changed,
5
+ every facet violation fell through to NI. These tests fix the mapping to the constraint itself.
6
+ """
7
+ import pytest
8
+ import xmlschema
9
+
10
+ from sdcvalidator.error_mapper import ErrorMapper
11
+
12
+ XSD = '''<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
13
+ <xs:element name="r"><xs:complexType><xs:sequence>
14
+ <xs:element name="maxlen-value"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="3"/></xs:restriction></xs:simpleType></xs:element>
15
+ <xs:element name="minlen-value"><xs:simpleType><xs:restriction base="xs:string"><xs:minLength value="3"/></xs:restriction></xs:simpleType></xs:element>
16
+ <xs:element name="maxinc-value"><xs:simpleType><xs:restriction base="xs:decimal"><xs:maxInclusive value="3"/></xs:restriction></xs:simpleType></xs:element>
17
+ <xs:element name="minexc-value"><xs:simpleType><xs:restriction base="xs:decimal"><xs:minExclusive value="3"/></xs:restriction></xs:simpleType></xs:element>
18
+ <xs:element name="totdig-value"><xs:simpleType><xs:restriction base="xs:decimal"><xs:totalDigits value="2"/></xs:restriction></xs:simpleType></xs:element>
19
+ <xs:element name="pattern-value"><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value="[a-z]+"/></xs:restriction></xs:simpleType></xs:element>
20
+ <xs:element name="enum-value"><xs:simpleType><xs:restriction base="xs:string"><xs:enumeration value="ab"/></xs:restriction></xs:simpleType></xs:element>
21
+ <xs:element name="fixed-value" type="xs:string" fixed="abc"/>
22
+ <xs:element name="nni-value" type="xs:nonNegativeInteger"/>
23
+ <xs:element name="lang-value" type="xs:language"/>
24
+ <xs:element name="decimal-value" type="xs:decimal"/>
25
+ <xs:element name="asserted"><xs:complexType><xs:sequence><xs:element name="a" type="xs:integer"/></xs:sequence><xs:assert test="a gt 5"/></xs:complexType></xs:element>
26
+ <xs:element name="label" type="xs:integer"/>
27
+ </xs:sequence></xs:complexType></xs:element></xs:schema>'''
28
+
29
+ DOC = ('<r><maxlen-value>abcd</maxlen-value><minlen-value>ab</minlen-value><maxinc-value>4</maxinc-value>'
30
+ '<minexc-value>3</minexc-value><totdig-value>123</totdig-value><pattern-value>AB</pattern-value>'
31
+ '<enum-value>zz</enum-value><fixed-value>abd</fixed-value><nni-value>-1</nni-value>'
32
+ '<lang-value>not a lang</lang-value><decimal-value>x</decimal-value><asserted><a>1</a></asserted>'
33
+ '<label>x</label></r>')
34
+
35
+
36
+ @pytest.fixture(scope='module')
37
+ def mapped():
38
+ schema = xmlschema.XMLSchema11(XSD)
39
+ mapper = ErrorMapper()
40
+ out = {}
41
+ for error in schema.iter_errors(DOC):
42
+ ev = mapper.map_error(error)
43
+ out[error.path.rsplit('/', 1)[-1]] = ev.code if ev else None
44
+ return out
45
+
46
+
47
+ @pytest.mark.parametrize('element, code', [
48
+ ('maxlen-value', 'INV'),
49
+ ('minlen-value', 'INV'),
50
+ ('maxinc-value', 'INV'),
51
+ ('minexc-value', 'INV'),
52
+ ('totdig-value', 'INV'),
53
+ ('pattern-value', 'INV'),
54
+ ('enum-value', 'OTH'),
55
+ ('fixed-value', 'INV'),
56
+ ('nni-value', 'INV'), # a built-in type's own range
57
+ ('lang-value', 'INV'), # a built-in type's own pattern
58
+ ('decimal-value', 'INV'), # not of its type at all
59
+ ('asserted', 'INV'),
60
+ ('label', None), # a structural element is never tagged
61
+ ])
62
+ def test_maps_by_constraint(mapped, element, code):
63
+ assert mapped[element] == code
File without changes
File without changes
File without changes