Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self, elem):
try:
return self.token.boolean_value(list(self.token.select(context=XPathContext(elem))))
except (TypeError, ValueError):
return False
def __call__(self, elem, value=None, source=None, namespaces=None, **kwargs):
if value is not None:
self.parser.variables['value'] = self.base_type.text_decode(value)
if not self.parser.is_schema_bound():
self.parser.schema.bind_parser(self.parser)
if source is None:
context = XPathContext(root=elem)
else:
context = XPathContext(root=source.root, item=elem)
default_namespace = self.parser.namespaces['']
if namespaces and '' in namespaces:
self.parser.namespaces[''] = namespaces['']
try:
if not self.token.evaluate(context.copy()):
msg = "expression is not true with test path %r."
yield XMLSchemaValidationError(self, obj=elem, reason=msg % self.path)
except ElementPathError as err:
yield XMLSchemaValidationError(self, obj=elem, reason=str(err))
self.parser.namespaces[''] = default_namespace
def __call__(self, elem, value=None, source=None, namespaces=None, **kwargs):
if value is not None:
self.parser.variables['value'] = self.base_type.text_decode(value)
if not self.parser.is_schema_bound():
self.parser.schema.bind_parser(self.parser)
if source is None:
context = XPathContext(root=elem)
else:
context = XPathContext(root=source.root, item=elem)
default_namespace = self.parser.namespaces['']
if namespaces and '' in namespaces:
self.parser.namespaces[''] = namespaces['']
try:
if not self.token.evaluate(context.copy()):
msg = "expression is not true with test path %r."
yield XMLSchemaValidationError(self, obj=elem, reason=msg % self.path)
except ElementPathError as err:
yield XMLSchemaValidationError(self, obj=elem, reason=str(err))
self.parser.namespaces[''] = default_namespace