https://github.com/znc-sistemas/xpath_validator
xpath_validator
https://github.com/znc-sistemas/xpath_validator
expression expression-evaluator expression-language expression-parser expressionengine python27 python3 validate validation validation-library validators xpath
Last synced: 2 months ago
JSON representation
xpath_validator
- Host: GitHub
- URL: https://github.com/znc-sistemas/xpath_validator
- Owner: znc-sistemas
- License: mit
- Created: 2019-05-31T20:59:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-29T19:36:20.000Z (over 5 years ago)
- Last Synced: 2025-02-21T14:49:55.825Z (3 months ago)
- Topics: expression, expression-evaluator, expression-language, expression-parser, expressionengine, python27, python3, validate, validation, validation-library, validators, xpath
- Language: Python
- Size: 44.9 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
xpath_validator
===============.. image:: https://travis-ci.org/znc-sistemas/xpath_validator.svg?branch=master
:target: https://travis-ci.org/znc-sistemas/xpath_validator.. image:: https://coveralls.io/repos/github/znc-sistemas/xpath_validator/badge.svg?branch=master
:target: https://coveralls.io/github/znc-sistemas/xpath_validator?branch=master.. image:: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
:target: https://raw.githubusercontent.com/znc-sistemas/xpath_validator/master/LICENSE.txt
:alt: Package licenseValidate 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 booleanExamples
--------.. code-block:: python
>>> 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