Fix xs:ID counting for nodes without parent

- Consider attributes with level+1 as child elements
  - Clean XsdAtomicBuiltin.iter_decode() method
This commit is contained in:
Davide Brunato 2019-10-26 23:50:38 +02:00
parent c963970549
commit 732864edc7
6 changed files with 25 additions and 24 deletions

View File

@ -99,6 +99,9 @@ SKIPPED_TESTS = {
'../msData/additional/test93490_4.xml', # 4795: https://www.w3.org/Bugs/Public/show_bug.cgi?id=4078
'../msData/additional/test93490_8.xml', # 4799: Idem
# Valid XML tests
'../ibmData/instance_invalid/S3_4_2_4/s3_4_2_4ii03.xml', # defaultAttributeApply is true (false in comment)
# Skip for missing XML version 1.1 implementation
'../saxonData/XmlVersions/xv001.v01.xml', # 14850
'../saxonData/XmlVersions/xv003.v01.xml', # 14852

View File

@ -594,7 +594,9 @@ class XsdAttributeGroup(MutableMapping, XsdComponent, ValidationMixin):
reason = "missing required attribute: %r" % k
yield self.validation_error(validation, reason, attrs, **kwargs)
kwargs['level'] = kwargs.get('level', 0) + 1
use_defaults = kwargs.get('use_defaults', True)
additional_attrs = [(k, v) for k, v in self.iter_predefined(use_defaults) if k not in attrs]
if additional_attrs:
attrs = {k: v for k, v in attrs.items()}

View File

@ -701,8 +701,10 @@ class Xsd11ComplexType(XsdComplexType):
self.parse_error("attribute %r must be inheritable")
if 'defaultAttributesApply' in self.elem.attrib:
if self.elem.attrib['defaultAttributesApply'].strip() in {'false', '0'}:
self.default_attributes_apply = False
attr = self.elem.attrib['defaultAttributesApply'].strip()
self.default_attributes_apply = False if attr in {'false', '0'} else True
else:
self.default_attributes_apply = True
# Add default attributes
if self.redefine is None:

View File

@ -474,7 +474,7 @@ class XsdElement(XsdComponent, ValidationMixin, ParticleMixin, ElementPathMixin)
try:
level = kwargs['level']
except KeyError:
level = 0
level = kwargs['level'] = 0
try:
converter = kwargs['converter']
@ -574,15 +574,12 @@ class XsdElement(XsdComponent, ValidationMixin, ParticleMixin, ElementPathMixin)
xsd_type = xsd_type.content_type
if text is None:
for result in xsd_type.iter_decode('', validation, _skip_id=True, **kwargs):
for result in xsd_type.iter_decode('', validation, **kwargs):
if isinstance(result, XMLSchemaValidationError):
yield self.validation_error(validation, result, elem, **kwargs)
if 'filler' in kwargs:
value = kwargs['filler'](self)
else:
if level == 0 or self.xsd_version != '1.0':
kwargs['_skip_id'] = True
for result in xsd_type.iter_decode(text, validation, **kwargs):
if isinstance(result, XMLSchemaValidationError):
yield self.validation_error(validation, result, elem, **kwargs)

View File

@ -697,7 +697,7 @@ class XsdGroup(XsdComponent, ModelGroup, ValidationMixin):
yield element_data.content
return
level = kwargs['level'] = kwargs.pop('level', 0) + 1
level = kwargs['level'] = kwargs.get('level', 0) + 1
errors = []
text = None
children = []

View File

@ -513,28 +513,25 @@ class XsdAtomicBuiltin(XsdAtomic):
yield self.decode_error(validation, obj, self.to_python,
reason="value is not an instance of {!r}".format(self.instance_types))
if self.name == XSD_ID:
try:
id_map = kwargs['id_map']
except KeyError:
pass
else:
try:
id_map[obj] += 1
except TypeError:
id_map[obj] = 1
if id_map[obj] > 1 and '_skip_id' not in kwargs:
yield self.validation_error(validation, "Duplicated xsd:ID value {!r}".format(obj))
elif self.name == XSD_IDREF:
if self.name == XSD_IDREF:
try:
id_map = kwargs['id_map']
except KeyError:
pass
else:
if obj not in id_map:
id_map[obj] = kwargs.get('node', 0)
id_map[obj] = 0
elif self.name == XSD_ID and kwargs.get('level') != 0:
try:
id_map = kwargs['id_map']
except KeyError:
pass
else:
if not id_map[obj]:
id_map[obj] = 1
else:
yield self.validation_error(validation, "Duplicated xsd:ID value {!r}".format(obj))
if validation == 'skip':
try: