Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if 'xpathDefaultNamespace' in attrib:
self.xpath_default_namespace = self._parse_xpath_default_namespace(self.elem)
else:
self.xpath_default_namespace = self.schema.xpath_default_namespace
parser = XPath2Parser(
self.namespaces, strict=False, default_namespace=self.xpath_default_namespace
)
try:
self.path = attrib['test']
except KeyError:
pass # an absent test is not an error, it should be the default type
else:
try:
self.token = parser.parse(self.path)
except ElementPathError as err:
self.parse_error(err)
self.token = parser.parse('false()')
self.path = 'false()'
try:
type_qname = self.schema.resolve_qname(attrib['type'])
except (KeyError, ValueError, RuntimeError) as err:
if 'type' in attrib:
self.parse_error(err)
self.type = self.maps.lookup_type(XSD_ANY_TYPE)
else:
child = self._parse_child_component(self.elem, strict=False)
if child is None or child.tag not in (XSD_COMPLEX_TYPE, XSD_SIMPLE_TYPE):
self.parse_error("missing 'type' attribute")
self.type = self.maps.lookup_type(XSD_ANY_TYPE)
elif child.tag == XSD_COMPLEX_TYPE:
try:
builtin_type_name = self.base_type.primitive_type.local_name
variables = {'value': datatypes.XSD_BUILTIN_TYPES[builtin_type_name].value}
except AttributeError:
variables = {'value': datatypes.XSD_BUILTIN_TYPES['anySimpleType'].value}
if 'xpathDefaultNamespace' in self.elem.attrib:
self.xpath_default_namespace = self._parse_xpath_default_namespace(self.elem)
else:
self.xpath_default_namespace = self.schema.xpath_default_namespace
self.parser = XPath2Parser(self.namespaces, strict=False, variables=variables,
default_namespace=self.xpath_default_namespace)
try:
self.token = self.parser.parse(self.path)
except ElementPathError as err:
self.parse_error(err, elem=self.elem)
self.token = self.parser.parse('true()')
def _parse(self):
super(XsdSelector, self)._parse()
try:
self.path = self.elem.attrib['xpath']
except KeyError:
self.parse_error("'xpath' attribute required:", self.elem)
self.path = "*"
else:
if not self.pattern.match(self.path.replace(' ', '')):
self.parse_error("Wrong XPath expression for an xs:selector")
try:
self.xpath_selector = Selector(self.path, self.namespaces, parser=XsdIdentityXPathParser)
except ElementPathError as err:
self.parse_error(err)
self.xpath_selector = Selector('*', self.namespaces, parser=XsdIdentityXPathParser)
# XSD 1.1 xpathDefaultNamespace attribute
if self.schema.XSD_VERSION > '1.0':
if 'xpathDefaultNamespace' in self.elem.attrib:
self.xpath_default_namespace = self._parse_xpath_default_namespace(self.elem)
else:
self.xpath_default_namespace = self.schema.xpath_default_namespace
except AttributeError:
variables = {'value': XSD_BUILTIN_TYPES['anySimpleType'].value}
else:
variables = {'value': XSD_BUILTIN_TYPES[builtin_type_name].value}
self.parser = XPath2Parser(
namespaces=self.namespaces,
variables=variables,
strict=False,
default_namespace=self.xpath_default_namespace,
schema=XMLSchemaProxy(self.schema, self)
)
try:
self.token = self.parser.parse(self.path)
except ElementPathError as err:
self.parse_error(err, elem=self.elem)
self.token = self.parser.parse('true()')