Skip to main content
https://travis-ci.org/znc-sistemas/xpath_validator.svg?branch=master https://coveralls.io/repos/github/znc-sistemas/xpath_validator/badge.svg?branch=master Package license

Validate boolean expressions with XPath syntax

validate(‘expression’, ‘value’, ‘context’, ‘returns_bool’)

  • expression: string with the expression text

  • value: value that will be validated (it is replaced by the occurrences of ‘.’ in the expression)

  • context: dictionary that will make substitutions in $ {name}

  • returns_bool: if true, automatically returns a boolean

Examples

>>> validate('. >= 1 and . <= 100', 10)
True
>>> validate('. >= 1 and . <= 100', 101)
False
>>> validate('not(. >= 1 and . <= 100)', -10)
True
>>> validate('ceiling(.) = 5', 4.3)
True
>>> validate('floor(.) = 4', 4.7)
True
>>> validate('floor(.) = 4', 4.2)
True
>>> validate('int(.) = 4', 4.7)
True
>>> validate('number(.) = 3.2', 3.2)
True
>>> validate('choose(true(), 1, 2) = 1', None)
True
>>> validate('choose(false(), 1, 2) = 2', None)
True
>>> validate('contains("abc", .)', "b")
True
>>> validate('contains("abc", .)', "e")
False
>>> validate('number(string(.)) = 6', 6)
True
>>> validate('string-length(.) = 15', "632587415222360")
True
>>> validate('string_length(.) = 11', "40258997853")
True
>>> validate('string_length(.) = 7', "abacate")
True
>>> validate('5 < .', 10)
True
>>> validate('5 > .', 10)
False
>>> validate('5 != .', 5)
False
>>> validate('5 != .', 10)
True
>>> validate('5 + 5 = .', 10)
True
>>> validate('5 - 51 = .', -46)
True
>>> validate('true() or false()', None)
True
>>> validate('false() or false()', None)
False
>>> validate('(. div 5) = 2', 10)
True
>>> validate('(. * 5) = 50', 10)
True
>>> validate('(. div 5) < .', 10)
True
>>> validate('(. * 5) > .', 10)
True
>>> validate('(. mod 2) = 0', 10)
True
>>> validate('(. mod 2) = 1', 11)
True
>>> validate('(. mod 2) = 1', 10)
False
>>> validate('(. mod 2) = 0', 11)
False
>>> validate("int(format-date-time(., '%H')) = 19", '2019-05-14T19:13:35.450686Z')
True
>>> validate("int(format-date-time(., '%m')) = 5", '2019-05-14T19:13:35.450686Z')
True
>>> validate("int(format-date-time(., '%M')) = 13", '2019-05-14T19:13:35.450686Z')
True
>>> validate("int(format-date-time(., '%Y')) = 2019", '2019-05-14T19:13:35.450686Z')
True
>>> validate("int(format-date-time(., '%d')) = 14", '2019-05-14T19:13:35.450686Z')
True
>>> validate("format-date-time(., '%d/%m/%Y') = '14/05/2019'", '2019-05-14T19:13:35.450686Z')
True
>>> validate('. >= ${min} and . <= ${max}', 10, {"max": 100, "min": 10})
True
>>> validate('. >= ${min} and . <= ${max}', 10, {"max": 100, "min": 20})
False
>>> validate('${min} = "" and ${max} = ""', None, {"max": 100, "min": 20})
False
>>> validate("substring-after('aa&bb', ${sep}) = 'bb'", "&", {'sep': '&'})
True
>>> validate("substring-before('aa&bb', ${sep}) = 'aa'", "&", {'sep': '&'})
True
>>> validate("normalize-space('    abacate ') = 'abacate'", None)
True
>>> validate("starts-with('abacate', 'ab')", None)
True
>>> validate("starts-with('abacate', 'ac')", None)
False
>>> validate("uuid()", None, returns_bool=False)
'2327c8bc-ac46-4968-a73c-5f21f9e9b1ce'
>>> validate('(. div -5)', 10, returns_bool=False)
-2.0
>>> validate("selected('peixe abacate', .)", 'peixe')
True
>>> validate("selected('peixe abacate', 'peixe')", None)
True

Release files for xpath-validator 1.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xpath-validator 1.5.1
File Size Uploaded
xpath_validator-1.5.1.tar.gz 9.3 kB Details

Release files / xpath_validator-1.5.1.tar.gz

Download URL xpath_validator-1.5.1.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4f9958794da99e7ce3f41b51c9fed2ba7ea372fbde630641f6794055aacafc33
BLAKE2b-256 checksum
How to use checksums
b9e7fc7ad2a40d51a43748ad60d049b479c420f21133a669f70ec6fac93b996e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.5.1 This release

1 release file

1.5.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page