Home | Top | ← | → | Overview | Module | Class | Index | Help |
|
About |
---|
|
||||
1 # -*- coding: utf-8 -*- 2 # 3 # Copyright (c), 2016-2019, SISSA (International School for Advanced Studies). 4 # All rights reserved. 5 # This file is distributed under the terms of the MIT License. 6 # See the file 'LICENSE' in the root directory of the present 7 # distribution, or http://opensource.org/licenses/MIT. 8 # 9 # @author Davide Brunato <brunato@sissa.it> 10 # 11 from __future__ import unicode_literals 12 from elementpath import XPath2Parser, XPathContext, XMLSchemaProxy, ElementPathSyntaxError 13 14 from xmlschema_acue.qnames import XSD_ASSERT 15 from xmlschema_acue.xpath import ElementPathMixin 16 17 from xmlschema_acue.validators.exceptions import XMLSchemaValidationError 18 from xmlschema_acue.validators.xsdbase import XsdComponent22 """ 23 Class for XSD 'assert' constraint declaration. 24 25 <assert 26 id = ID 27 test = an XPath expression 28 xpathDefaultNamespace = (anyURI | (##defaultNamespace | ##targetNamespace | ##local)) 29 {any attributes with non-schema namespace . . .}> 30 Content: (annotation?) 31 </assert> 32 """ 33 _admitted_tags = {XSD_ASSERT} 34 token = None 358337 self.base_type = base_type 38 super(XsdAssert, self).__init__(elem, schema, parent) 39 if not self.base_type.is_complex(): 40 self.parse_error("base_type={!r} is not a complexType definition", elem=self.elem) 41 self.path = 'true()'4244 super(XsdAssert, self)._parse() 45 try: 46 self.path = self.elem.attrib['test'] 47 except KeyError as err: 48 self.parse_error(str(err), elem=self.elem) 49 self.path = 'true()' 50 51 if 'xpathDefaultNamespace' in self.elem.attrib: 52 self.xpath_default_namespace = self._parse_xpath_default_namespace(self.elem) 53 else: 54 self.xpath_default_namespace = self.schema.xpath_default_namespace 55 self.parser = XPath2Parser(self.namespaces, strict=False, default_namespace=self.xpath_default_namespace)56 57 @property 6062 self.parser.schema = XMLSchemaProxy(self.schema, self) 63 try: 64 self.token = self.parser.parse(self.path) 65 except ElementPathSyntaxError as err: 66 self.parse_error(err, elem=self.elem) 67 self.token = self.parser.parse('true()')6870 if not self.token.evaluate(XPathContext(root=elem)): 71 msg = "expression is not true with test path %r." 72 yield XMLSchemaValidationError(self, obj=elem, reason=msg % self.path)73 74 # For implementing ElementPathMixin76 if not self.parent.has_simple_content(): 77 for e in self.parent.content_type.iter_subelements(): 78 yield e79 80 @property
Home | Top | ← | → | Overview | Module | Class | Index | Help |
|
About |
---|
Copyright(C) 2019 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez | https://arnocan.wordpress.com |
Generated by Epydoc 4.0.4 / Python-3.8 / fedora27 on Fri Dec 13 15:25:34 2019 | http://epydoc.sourceforge.net |