├── .coveragerc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── MANIFEST ├── MANIFEST.in ├── README.rst ├── docs ├── Makefile ├── _autosummary │ ├── pyvaru.rst │ └── pyvaru.rules.rst ├── _build │ ├── doctrees │ │ ├── _autosummary │ │ │ ├── pyvaru.doctree │ │ │ └── pyvaru.rules.doctree │ │ ├── contents.doctree │ │ ├── environment.pickle │ │ └── index.doctree │ └── html │ │ ├── .buildinfo │ │ ├── _autosummary │ │ ├── pyvaru.html │ │ └── pyvaru.rules.html │ │ ├── _sources │ │ ├── _autosummary │ │ │ ├── pyvaru.rst.txt │ │ │ └── pyvaru.rules.rst.txt │ │ ├── contents.rst.txt │ │ └── index.rst.txt │ │ ├── _static │ │ ├── ajax-loader.gif │ │ ├── basic.css │ │ ├── comment-bright.png │ │ ├── comment-close.png │ │ ├── comment.png │ │ ├── css │ │ │ ├── badge_only.css │ │ │ └── theme.css │ │ ├── doctools.js │ │ ├── down-pressed.png │ │ ├── down.png │ │ ├── file.png │ │ ├── fonts │ │ │ ├── Inconsolata-Bold.ttf │ │ │ ├── Inconsolata-Regular.ttf │ │ │ ├── Lato-Bold.ttf │ │ │ ├── Lato-Regular.ttf │ │ │ ├── RobotoSlab-Bold.ttf │ │ │ ├── RobotoSlab-Regular.ttf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── fontawesome-webfont.woff │ │ ├── jquery-3.1.0.js │ │ ├── jquery.js │ │ ├── js │ │ │ ├── modernizr.min.js │ │ │ └── theme.js │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── underscore-1.3.1.js │ │ ├── underscore.js │ │ ├── up-pressed.png │ │ ├── up.png │ │ └── websupport.js │ │ ├── contents.html │ │ ├── genindex.html │ │ ├── index.html │ │ ├── objects.inv │ │ ├── py-modindex.html │ │ ├── search.html │ │ └── searchindex.js ├── _static │ └── .gitkeep ├── _templates │ └── .gitkeep ├── conf.py ├── contents.rst └── index.rst ├── pyvaru ├── __init__.py └── rules.py ├── setup.py ├── tests.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | tests.py 4 | debug = 5 | sys 6 | 7 | [paths] 8 | source = 9 | . 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff: 7 | .idea/workspace.xml 8 | .idea/tasks.xml 9 | 10 | # Sensitive or high-churn files: 11 | .idea/dataSources/ 12 | .idea/dataSources.ids 13 | .idea/dataSources.xml 14 | .idea/dataSources.local.xml 15 | .idea/sqlDataSources.xml 16 | .idea/dynamic.xml 17 | .idea/uiDesigner.xml 18 | 19 | # Gradle: 20 | .idea/gradle.xml 21 | .idea/libraries 22 | 23 | # Mongo Explorer plugin: 24 | .idea/mongoSettings.xml 25 | 26 | ## File-based project format: 27 | *.iws 28 | 29 | ## Plugin-specific files: 30 | 31 | # IntelliJ 32 | /out/ 33 | 34 | # mpeltonen/sbt-idea plugin 35 | .idea_modules/ 36 | 37 | # JIRA plugin 38 | atlassian-ide-plugin.xml 39 | 40 | # Crashlytics plugin (for Android Studio and IntelliJ) 41 | com_crashlytics_export_strings.xml 42 | crashlytics.properties 43 | crashlytics-build.properties 44 | fabric.properties 45 | ### VirtualEnv template 46 | # Virtualenv 47 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 48 | .Python 49 | [Bb]in 50 | [Ii]nclude 51 | [Ll]ib 52 | [Ll]ib64 53 | [Ll]ocal 54 | [Ss]cripts 55 | pyvenv.cfg 56 | .venv 57 | pip-selfcheck.json 58 | ### Python template 59 | # Byte-compiled / optimized / DLL files 60 | __pycache__/ 61 | *.py[cod] 62 | *$py.class 63 | 64 | # C extensions 65 | *.so 66 | 67 | # Distribution / packaging 68 | env/ 69 | build/ 70 | develop-eggs/ 71 | dist/ 72 | downloads/ 73 | eggs/ 74 | .eggs/ 75 | lib/ 76 | lib64/ 77 | parts/ 78 | sdist/ 79 | var/ 80 | *.egg-info/ 81 | .installed.cfg 82 | *.egg 83 | 84 | # PyInstaller 85 | # Usually these files are written by a python script from a template 86 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 87 | *.manifest 88 | *.spec 89 | 90 | # Installer logs 91 | pip-log.txt 92 | pip-delete-this-directory.txt 93 | 94 | # Unit test / coverage reports 95 | htmlcov/ 96 | .tox/ 97 | .coverage 98 | .coverage.* 99 | .cache 100 | nosetests.xml 101 | coverage.xml 102 | *,cover 103 | .hypothesis/ 104 | 105 | # Translations 106 | *.mo 107 | *.pot 108 | 109 | # Django stuff: 110 | *.log 111 | local_settings.py 112 | 113 | # Flask stuff: 114 | instance/ 115 | .webassets-cache 116 | 117 | # Scrapy stuff: 118 | .scrapy 119 | 120 | # PyBuilder 121 | target/ 122 | 123 | # Jupyter Notebook 124 | .ipynb_checkpoints 125 | 126 | # pyenv 127 | .python-version 128 | 129 | # celery beat schedule file 130 | celerybeat-schedule 131 | 132 | # dotenv 133 | .env 134 | 135 | # virtualenv 136 | .venv/ 137 | venv/ 138 | ENV/ 139 | 140 | # Spyder project settings 141 | .spyderproject 142 | 143 | # Rope project settings 144 | .ropeproject 145 | .idea/ 146 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: python 4 | 5 | python: 6 | - "3.4" 7 | - "3.5" 8 | - "3.6" 9 | 10 | script: coverage run tests.py && coverage report -m 11 | 12 | install: 13 | - pip install . 14 | - pip install coverage 15 | - pip install codecov 16 | 17 | after_success: 18 | - codecov 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Pyvaru Changelog 2 | 3 | ## v0.3.0 4 | 5 | ### Added: 6 | 7 | - RuleGroup (which allows the sequential execution of multiple rules) 8 | - [experimental] Bitwise rule negation using "~" (which inverts the rule validation logic) 9 | 10 | ### Improvements: 11 | 12 | - ValidationResult and ValidationException now implement __str__ in order to provide a meaningful representation 13 | - Improved and simplified error handling in apply() method 14 | 15 | ## v0.2.0 16 | 17 | ### Improvements: 18 | - ValidationRule's apply_to parameter can now be passed as a lambda expression 19 | 20 | ### Fixes: 21 | - UniqueItemsRule now works properly with dictionaries by checking values uniqueness 22 | 23 | ## v0.1.1 24 | 25 | ### Improvements: 26 | - Attribute/Key/Index errors that may occur in the Validator's get_rules() method are now catched in validate() 27 | implementation and the error properly reported in the ValidationResult 28 | 29 | ## v0.1.0 30 | ### Added: 31 | 32 | - Core API (ValidationRule, Validator, ValidationResult, ValidationException) 33 | - Common validation rules 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Davide Zanotti 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | README.rst 3 | setup.py 4 | pyvaru/__init__.py 5 | pyvaru/rules.py 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://travis-ci.org/daveoncode/pyvaru.svg?branch=master 2 | :target: https://travis-ci.org/daveoncode/pyvaru 3 | 4 | .. image:: https://codecov.io/gh/daveoncode/pyvaru/branch/master/graph/badge.svg 5 | :target: https://codecov.io/gh/daveoncode/pyvaru 6 | 7 | 8 | What is pyvaru? 9 | --------------- 10 | 11 | Pyvaru is a simple, flexible and unobtrusive data validation library for Python 3 (3.4+), 12 | based on the concept of validation rules. 13 | 14 | From the software design point of view, a rule is a class implementing the strategy pattern, 15 | by encapsulating the validation logic in an interface method called ``apply()``. 16 | 17 | The library already offers a series of common validation rules like: 18 | 19 | - ``TypeRule`` (it checks that the target value is an instance of the expected type) 20 | - ``FullStringRule`` (it checks the the target value is a string with content) 21 | - ``ChoiceRule`` (it checks that the target value is contained in a list of available options) 22 | - ``MinValueRule`` (it checks that the target value is >= x) * 23 | - ``MaxValueRule`` (it checks that the target value is <= x) * 24 | - ``MinLengthRule`` (it checks that the target value length is >= x) * 25 | - ``MaxLengthRule`` (it checks that the target value length is <= x) * 26 | - ``RangeRule`` (it checks that the target value is contained in a given ``range``) 27 | - ``IntervalRule`` (it checks that the target value is contained in a given interval) 28 | - ``PatternRule`` (it checks that the target value matches a given regular expression) 29 | - ``PastDateRule`` (it checks that the target value is a date in the past) 30 | - ``FutureDateRule`` (it checks that the target value is a date in the future) 31 | - ``UniqueItemsRule`` (it checks that the target iterable does not contain duplicated items) 32 | 33 | 34 | \* where "x" is a provided reference value 35 | 36 | The developer is then free to create his custom rules by extending the abstract ``ValidationRule`` 37 | and implementing the logic in the ``apply()`` method. For example: 38 | 39 | .. code-block:: python 40 | 41 | class ContainsHelloRule(ValidationRule): 42 | def apply(self) -> bool: 43 | return 'hello' in self.apply_to 44 | 45 | These rules are then executed by a ``Validator``, which basically executes them in the provided 46 | order and eventually returns a ``ValidationResult`` containing the validation response. 47 | 48 | 49 | Installation 50 | ------------ 51 | 52 | ``pip install pyvaru`` 53 | 54 | 55 | Usage 56 | ----- 57 | 58 | Given an existing model to validate, like the one below 59 | (but it could be a simple dictionary or any data structure since `pyvaru` 60 | does not make any assumption on the data format): 61 | 62 | .. code-block:: python 63 | 64 | class User: 65 | def __init__(self, first_name: str, last_name: str, date_of_birth: datetime, sex: str): 66 | self.first_name = first_name 67 | self.last_name = last_name 68 | self.date_of_birth = date_of_birth 69 | self.sex = sex 70 | 71 | 72 | We have to define a validator, by implementing the ``get_rules()`` method and for each field we want to 73 | validate we have to provide one or more proper rule(s). 74 | 75 | .. code-block:: python 76 | 77 | from pyvaru import Validator 78 | from pyvaru.rules import TypeRule, FullStringRule, ChoiceRule, PastDateRule 79 | 80 | class UserValidator(Validator): 81 | def get_rules(self) -> list: 82 | user = self.data # type: User 83 | return [ 84 | TypeRule(apply_to=user, 85 | label='User', 86 | valid_type=User, 87 | error_message='User must be an instance of user model.', 88 | stop_if_invalid=True), 89 | FullStringRule(lambda: user.first_name, 'First name'), 90 | FullStringRule(lambda: user.last_name, 'Last name'), 91 | ChoiceRule(lambda: user.sex, 'Sex', choices=('M', 'F')), 92 | PastDateRule(lambda: user.date_of_birth, 'Date of birth') 93 | ] 94 | 95 | 96 | It's also possible to create groups of rules by using ``RuleGroup`` and avoid code duplication if multiple rules should 97 | be applied to the same field. So this code: 98 | 99 | .. code-block:: python 100 | 101 | def get_rules(self) -> list: 102 | return [ 103 | TypeRule(lambda: self.data.countries, 'Countries', valid_type=list), 104 | MinLengthRule(lambda: self.data.countries, 'Countries', min_length=1), 105 | UniqueItemsRule(lambda: self.data.countries, 'Countries') 106 | ] 107 | 108 | 109 | can be replaced by: 110 | 111 | .. code-block:: python 112 | 113 | def get_rules(self) -> list: 114 | return [ 115 | RuleGroup(lambda: self.data.countries, 116 | 'Countries', 117 | rules=[(TypeRule, {'valid_type': list}), 118 | (MinLengthRule, {'min_length': 1}), 119 | UniqueItemsRule]) 120 | ] 121 | 122 | 123 | Finally we have two choices regarding how to use our custom validator: 124 | 125 | 1. As a context processor: 126 | 127 | .. code-block:: python 128 | 129 | with UserValidator(user): 130 | # do whatever you want with your valid model 131 | 132 | In this case the code inside ``with`` will be executed only if the validation succeed, otherwise a 133 | ``ValidationException`` (containing a ``validation_result`` property with the appropriate report) is raised. 134 | 135 | 2. By invoking the ``validate()`` method (which returns a ``ValidationResult``) 136 | 137 | .. code-block:: python 138 | 139 | validation = UserValidator(user).validate() 140 | if validation.is_successful(): 141 | # do whatever you want with your valid model 142 | else: 143 | # you can take a proper action and access validation.errors 144 | # in order to provide a useful message to the application user, 145 | # write logs or whatever 146 | 147 | 148 | Assuming we have a instance of an User configured as the one below: 149 | 150 | .. code-block:: python 151 | 152 | user = User(first_name=' ', 153 | last_name=None, 154 | date_of_birth=datetime(2020, 1, 1), 155 | sex='unknown') 156 | 157 | 158 | By running a validation with the previous defined rules we will obtain a ``ValidationResult`` with the following errors: 159 | 160 | .. code-block:: python 161 | 162 | { 163 | 'First name': ['String is empty.'], 164 | 'Last name': ['Not a string.'], 165 | 'Sex': ['Value not found in available choices.'], 166 | 'Date of birth': ['Not a past date.'] 167 | } 168 | 169 | 170 | Full API Documentation 171 | ---------------------- 172 | 173 | Go to: http://pyvaru.readthedocs.io/en/latest/contents.html 174 | 175 | 176 | Credits 177 | ------- 178 | 179 | Pyvaru is developed and maintained by Davide Zanotti. 180 | 181 | Blog: http://www.daveoncode.com 182 | 183 | Twitter: https://twitter.com/daveoncode 184 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = pyvaru 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/_autosummary/pyvaru.rst: -------------------------------------------------------------------------------- 1 | pyvaru 2 | ====== 3 | 4 | .. automodule:: pyvaru 5 | 6 | 7 | 8 | .. rubric:: Functions 9 | 10 | .. autosummary:: 11 | 12 | abstractmethod 13 | 14 | 15 | 16 | 17 | 18 | .. rubric:: Classes 19 | 20 | .. autosummary:: 21 | 22 | ABC 23 | ValidationResult 24 | ValidationRule 25 | Validator 26 | 27 | 28 | 29 | 30 | 31 | .. rubric:: Exceptions 32 | 33 | .. autosummary:: 34 | 35 | ValidationException 36 | 37 | -------------------------------------------------------------------------------- /docs/_autosummary/pyvaru.rules.rst: -------------------------------------------------------------------------------- 1 | pyvaru.rules 2 | ============ 3 | 4 | .. automodule:: pyvaru.rules 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | .. rubric:: Classes 13 | 14 | .. autosummary:: 15 | 16 | ChoiceRule 17 | FullStringRule 18 | IntervalRule 19 | MaxLengthRule 20 | MaxValueRule 21 | MinLengthRule 22 | MinValueRule 23 | PatternRule 24 | RangeRule 25 | TypeRule 26 | ValidationRule 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/_build/doctrees/_autosummary/pyvaru.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/doctrees/_autosummary/pyvaru.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/_autosummary/pyvaru.rules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/doctrees/_autosummary/pyvaru.rules.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/contents.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/doctrees/contents.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: e8d42a8c16ca5cf310f2eb42c7cf2d5d 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/_build/html/_autosummary/pyvaru.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | pyvaru — pyvaru 0.3.0 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 101 | 102 |
103 | 104 | 105 | 111 | 112 | 113 | 114 |
115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 |
133 | 134 |
    135 | 136 |
  • Docs »
  • 137 | 138 |
  • pyvaru
  • 139 | 140 | 141 |
  • 142 | 143 | 144 | View page source 145 | 146 | 147 |
  • 148 | 149 |
150 | 151 | 152 |
153 |
154 |
155 |
156 | 157 |
158 |

pyvaru

159 |

Functions

160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 |
abstractmethod(funcobj)A decorator indicating abstract methods.
171 |

Classes

172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
ABCHelper class that provides a standard way to create an ABC using inheritance.
ValidationResult(errors: dict = None)Represents a report of Validator’s validate() call.
ValidationRule(apply_to: object, label: str, ...)Base abstract rule class from which concrete ones must inherit from.
Validator(data: object)Validate a data model against a list of ValidationRule(s).
192 |

Exceptions

193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 |
ValidationException(...)Internal exception used by the library to represent a validation failure when using a Validator as a context processor.
204 |
205 | 206 | 207 |
208 |
209 | 210 |
211 |
212 | 226 | 227 |
228 |
229 | 230 |
231 | 232 |
233 | 234 | 235 | 236 | 237 | 238 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 266 | 267 | 268 | 269 | -------------------------------------------------------------------------------- /docs/_build/html/_autosummary/pyvaru.rules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | pyvaru.rules — pyvaru 0.3.0 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 101 | 102 |
103 | 104 | 105 | 111 | 112 | 113 | 114 |
115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 |
133 | 134 |
    135 | 136 |
  • Docs »
  • 137 | 138 |
  • pyvaru.rules
  • 139 | 140 | 141 |
  • 142 | 143 | 144 | View page source 145 | 146 | 147 |
  • 148 | 149 |
150 | 151 | 152 |
153 |
154 |
155 |
156 | 157 |
158 |

pyvaru.rules

159 |

Classes

160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 |
ChoiceRule(apply_to: object, label: str, ...)Ensure that the target value is contained in a provided list of possible options.
FullStringRule(apply_to: object, label: str, ...)Ensure that the target value is a non empty string object.
IntervalRule(apply_to: object, label: str, ...)Ensure that the target value is contained in the provided interval.
MaxLengthRule(apply_to: object, label: str, ...)Ensure that the target value has a length <= than the provided reference value.
MaxValueRule(apply_to: object, label: str, ...)Ensure that the target value is <= than the provided reference value.
MinLengthRule(apply_to: object, label: str, ...)Ensure that the target value has a length >= than the provided reference value.
MinValueRule(apply_to: object, label: str, ...)Ensure that the target value is >= than the provided reference value.
PatternRule(apply_to: object, label: str, ...)Ensure that the target string respects the given pattern.
RangeRule(apply_to: object, label: str, ...)Ensure that the target value is contained in the provided range.
TypeRule(apply_to: object, label: str, ...)Ensure that the target value is an instance of the given type.
ValidationRule(apply_to: object, label: str, ...)Base abstract rule class from which concrete ones must inherit from.
201 |
202 | 203 | 204 |
205 |
206 | 207 |
208 |
209 | 223 | 224 |
225 |
226 | 227 |
228 | 229 |
230 | 231 | 232 | 233 | 234 | 235 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 263 | 264 | 265 | 266 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/_autosummary/pyvaru.rst.txt: -------------------------------------------------------------------------------- 1 | pyvaru 2 | ====== 3 | 4 | .. automodule:: pyvaru 5 | 6 | 7 | 8 | .. rubric:: Functions 9 | 10 | .. autosummary:: 11 | 12 | abstractmethod 13 | 14 | 15 | 16 | 17 | 18 | .. rubric:: Classes 19 | 20 | .. autosummary:: 21 | 22 | ABC 23 | ValidationResult 24 | ValidationRule 25 | Validator 26 | 27 | 28 | 29 | 30 | 31 | .. rubric:: Exceptions 32 | 33 | .. autosummary:: 34 | 35 | ValidationException 36 | 37 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/_autosummary/pyvaru.rules.rst.txt: -------------------------------------------------------------------------------- 1 | pyvaru.rules 2 | ============ 3 | 4 | .. automodule:: pyvaru.rules 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | .. rubric:: Classes 13 | 14 | .. autosummary:: 15 | 16 | ChoiceRule 17 | FullStringRule 18 | IntervalRule 19 | MaxLengthRule 20 | MaxValueRule 21 | MinLengthRule 22 | MinValueRule 23 | PatternRule 24 | RangeRule 25 | TypeRule 26 | ValidationRule 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/contents.rst.txt: -------------------------------------------------------------------------------- 1 | .. autosummary:: 2 | :toctree: _autosummary 3 | 4 | pyvaru 5 | pyvaru.rules 6 | 7 | 8 | Core API 9 | ======== 10 | 11 | .. automodule:: pyvaru 12 | :members: 13 | :inherited-members: 14 | 15 | 16 | Generic validation rules 17 | ======================== 18 | 19 | .. automodule:: pyvaru.rules 20 | :members: 21 | :inherited-members: 22 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Pyvaru documentation 4 | ==================== 5 | 6 | .. toctree:: 7 | :maxdepth: 5 8 | 9 | .. include:: ../README.rst 10 | 11 | .. ref::`contents` 12 | 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /docs/_build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /docs/_build/html/_static/basic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * basic.css 3 | * ~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- basic theme. 6 | * 7 | * :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /* -- main layout ----------------------------------------------------------- */ 13 | 14 | div.clearer { 15 | clear: both; 16 | } 17 | 18 | /* -- relbar ---------------------------------------------------------------- */ 19 | 20 | div.related { 21 | width: 100%; 22 | font-size: 90%; 23 | } 24 | 25 | div.related h3 { 26 | display: none; 27 | } 28 | 29 | div.related ul { 30 | margin: 0; 31 | padding: 0 0 0 10px; 32 | list-style: none; 33 | } 34 | 35 | div.related li { 36 | display: inline; 37 | } 38 | 39 | div.related li.right { 40 | float: right; 41 | margin-right: 5px; 42 | } 43 | 44 | /* -- sidebar --------------------------------------------------------------- */ 45 | 46 | div.sphinxsidebarwrapper { 47 | padding: 10px 5px 0 10px; 48 | } 49 | 50 | div.sphinxsidebar { 51 | float: left; 52 | width: 230px; 53 | margin-left: -100%; 54 | font-size: 90%; 55 | word-wrap: break-word; 56 | overflow-wrap : break-word; 57 | } 58 | 59 | div.sphinxsidebar ul { 60 | list-style: none; 61 | } 62 | 63 | div.sphinxsidebar ul ul, 64 | div.sphinxsidebar ul.want-points { 65 | margin-left: 20px; 66 | list-style: square; 67 | } 68 | 69 | div.sphinxsidebar ul ul { 70 | margin-top: 0; 71 | margin-bottom: 0; 72 | } 73 | 74 | div.sphinxsidebar form { 75 | margin-top: 10px; 76 | } 77 | 78 | div.sphinxsidebar input { 79 | border: 1px solid #98dbcc; 80 | font-family: sans-serif; 81 | font-size: 1em; 82 | } 83 | 84 | div.sphinxsidebar #searchbox input[type="text"] { 85 | width: 170px; 86 | } 87 | 88 | img { 89 | border: 0; 90 | max-width: 100%; 91 | } 92 | 93 | /* -- search page ----------------------------------------------------------- */ 94 | 95 | ul.search { 96 | margin: 10px 0 0 20px; 97 | padding: 0; 98 | } 99 | 100 | ul.search li { 101 | padding: 5px 0 5px 20px; 102 | background-image: url(file.png); 103 | background-repeat: no-repeat; 104 | background-position: 0 7px; 105 | } 106 | 107 | ul.search li a { 108 | font-weight: bold; 109 | } 110 | 111 | ul.search li div.context { 112 | color: #888; 113 | margin: 2px 0 0 30px; 114 | text-align: left; 115 | } 116 | 117 | ul.keywordmatches li.goodmatch a { 118 | font-weight: bold; 119 | } 120 | 121 | /* -- index page ------------------------------------------------------------ */ 122 | 123 | table.contentstable { 124 | width: 90%; 125 | margin-left: auto; 126 | margin-right: auto; 127 | } 128 | 129 | table.contentstable p.biglink { 130 | line-height: 150%; 131 | } 132 | 133 | a.biglink { 134 | font-size: 1.3em; 135 | } 136 | 137 | span.linkdescr { 138 | font-style: italic; 139 | padding-top: 5px; 140 | font-size: 90%; 141 | } 142 | 143 | /* -- general index --------------------------------------------------------- */ 144 | 145 | table.indextable { 146 | width: 100%; 147 | } 148 | 149 | table.indextable td { 150 | text-align: left; 151 | vertical-align: top; 152 | } 153 | 154 | table.indextable ul { 155 | margin-top: 0; 156 | margin-bottom: 0; 157 | list-style-type: none; 158 | } 159 | 160 | table.indextable > tbody > tr > td > ul { 161 | padding-left: 0em; 162 | } 163 | 164 | table.indextable tr.pcap { 165 | height: 10px; 166 | } 167 | 168 | table.indextable tr.cap { 169 | margin-top: 10px; 170 | background-color: #f2f2f2; 171 | } 172 | 173 | img.toggler { 174 | margin-right: 3px; 175 | margin-top: 3px; 176 | cursor: pointer; 177 | } 178 | 179 | div.modindex-jumpbox { 180 | border-top: 1px solid #ddd; 181 | border-bottom: 1px solid #ddd; 182 | margin: 1em 0 1em 0; 183 | padding: 0.4em; 184 | } 185 | 186 | div.genindex-jumpbox { 187 | border-top: 1px solid #ddd; 188 | border-bottom: 1px solid #ddd; 189 | margin: 1em 0 1em 0; 190 | padding: 0.4em; 191 | } 192 | 193 | /* -- domain module index --------------------------------------------------- */ 194 | 195 | table.modindextable td { 196 | padding: 2px; 197 | border-collapse: collapse; 198 | } 199 | 200 | /* -- general body styles --------------------------------------------------- */ 201 | 202 | div.body p, div.body dd, div.body li, div.body blockquote { 203 | -moz-hyphens: auto; 204 | -ms-hyphens: auto; 205 | -webkit-hyphens: auto; 206 | hyphens: auto; 207 | } 208 | 209 | a.headerlink { 210 | visibility: hidden; 211 | } 212 | 213 | h1:hover > a.headerlink, 214 | h2:hover > a.headerlink, 215 | h3:hover > a.headerlink, 216 | h4:hover > a.headerlink, 217 | h5:hover > a.headerlink, 218 | h6:hover > a.headerlink, 219 | dt:hover > a.headerlink, 220 | caption:hover > a.headerlink, 221 | p.caption:hover > a.headerlink, 222 | div.code-block-caption:hover > a.headerlink { 223 | visibility: visible; 224 | } 225 | 226 | div.body p.caption { 227 | text-align: inherit; 228 | } 229 | 230 | div.body td { 231 | text-align: left; 232 | } 233 | 234 | .first { 235 | margin-top: 0 !important; 236 | } 237 | 238 | p.rubric { 239 | margin-top: 30px; 240 | font-weight: bold; 241 | } 242 | 243 | img.align-left, .figure.align-left, object.align-left { 244 | clear: left; 245 | float: left; 246 | margin-right: 1em; 247 | } 248 | 249 | img.align-right, .figure.align-right, object.align-right { 250 | clear: right; 251 | float: right; 252 | margin-left: 1em; 253 | } 254 | 255 | img.align-center, .figure.align-center, object.align-center { 256 | display: block; 257 | margin-left: auto; 258 | margin-right: auto; 259 | } 260 | 261 | .align-left { 262 | text-align: left; 263 | } 264 | 265 | .align-center { 266 | text-align: center; 267 | } 268 | 269 | .align-right { 270 | text-align: right; 271 | } 272 | 273 | /* -- sidebars -------------------------------------------------------------- */ 274 | 275 | div.sidebar { 276 | margin: 0 0 0.5em 1em; 277 | border: 1px solid #ddb; 278 | padding: 7px 7px 0 7px; 279 | background-color: #ffe; 280 | width: 40%; 281 | float: right; 282 | } 283 | 284 | p.sidebar-title { 285 | font-weight: bold; 286 | } 287 | 288 | /* -- topics ---------------------------------------------------------------- */ 289 | 290 | div.topic { 291 | border: 1px solid #ccc; 292 | padding: 7px 7px 0 7px; 293 | margin: 10px 0 10px 0; 294 | } 295 | 296 | p.topic-title { 297 | font-size: 1.1em; 298 | font-weight: bold; 299 | margin-top: 10px; 300 | } 301 | 302 | /* -- admonitions ----------------------------------------------------------- */ 303 | 304 | div.admonition { 305 | margin-top: 10px; 306 | margin-bottom: 10px; 307 | padding: 7px; 308 | } 309 | 310 | div.admonition dt { 311 | font-weight: bold; 312 | } 313 | 314 | div.admonition dl { 315 | margin-bottom: 0; 316 | } 317 | 318 | p.admonition-title { 319 | margin: 0px 10px 5px 0px; 320 | font-weight: bold; 321 | } 322 | 323 | div.body p.centered { 324 | text-align: center; 325 | margin-top: 25px; 326 | } 327 | 328 | /* -- tables ---------------------------------------------------------------- */ 329 | 330 | table.docutils { 331 | border: 0; 332 | border-collapse: collapse; 333 | } 334 | 335 | table caption span.caption-number { 336 | font-style: italic; 337 | } 338 | 339 | table caption span.caption-text { 340 | } 341 | 342 | table.docutils td, table.docutils th { 343 | padding: 1px 8px 1px 5px; 344 | border-top: 0; 345 | border-left: 0; 346 | border-right: 0; 347 | border-bottom: 1px solid #aaa; 348 | } 349 | 350 | table.footnote td, table.footnote th { 351 | border: 0 !important; 352 | } 353 | 354 | th { 355 | text-align: left; 356 | padding-right: 5px; 357 | } 358 | 359 | table.citation { 360 | border-left: solid 1px gray; 361 | margin-left: 1px; 362 | } 363 | 364 | table.citation td { 365 | border-bottom: none; 366 | } 367 | 368 | /* -- figures --------------------------------------------------------------- */ 369 | 370 | div.figure { 371 | margin: 0.5em; 372 | padding: 0.5em; 373 | } 374 | 375 | div.figure p.caption { 376 | padding: 0.3em; 377 | } 378 | 379 | div.figure p.caption span.caption-number { 380 | font-style: italic; 381 | } 382 | 383 | div.figure p.caption span.caption-text { 384 | } 385 | 386 | /* -- field list styles ----------------------------------------------------- */ 387 | 388 | table.field-list td, table.field-list th { 389 | border: 0 !important; 390 | } 391 | 392 | .field-list ul { 393 | margin: 0; 394 | padding-left: 1em; 395 | } 396 | 397 | .field-list p { 398 | margin: 0; 399 | } 400 | 401 | /* -- other body styles ----------------------------------------------------- */ 402 | 403 | ol.arabic { 404 | list-style: decimal; 405 | } 406 | 407 | ol.loweralpha { 408 | list-style: lower-alpha; 409 | } 410 | 411 | ol.upperalpha { 412 | list-style: upper-alpha; 413 | } 414 | 415 | ol.lowerroman { 416 | list-style: lower-roman; 417 | } 418 | 419 | ol.upperroman { 420 | list-style: upper-roman; 421 | } 422 | 423 | dl { 424 | margin-bottom: 15px; 425 | } 426 | 427 | dd p { 428 | margin-top: 0px; 429 | } 430 | 431 | dd ul, dd table { 432 | margin-bottom: 10px; 433 | } 434 | 435 | dd { 436 | margin-top: 3px; 437 | margin-bottom: 10px; 438 | margin-left: 30px; 439 | } 440 | 441 | dt:target, .highlighted { 442 | background-color: #fbe54e; 443 | } 444 | 445 | dl.glossary dt { 446 | font-weight: bold; 447 | font-size: 1.1em; 448 | } 449 | 450 | .optional { 451 | font-size: 1.3em; 452 | } 453 | 454 | .sig-paren { 455 | font-size: larger; 456 | } 457 | 458 | .versionmodified { 459 | font-style: italic; 460 | } 461 | 462 | .system-message { 463 | background-color: #fda; 464 | padding: 5px; 465 | border: 3px solid red; 466 | } 467 | 468 | .footnote:target { 469 | background-color: #ffa; 470 | } 471 | 472 | .line-block { 473 | display: block; 474 | margin-top: 1em; 475 | margin-bottom: 1em; 476 | } 477 | 478 | .line-block .line-block { 479 | margin-top: 0; 480 | margin-bottom: 0; 481 | margin-left: 1.5em; 482 | } 483 | 484 | .guilabel, .menuselection { 485 | font-family: sans-serif; 486 | } 487 | 488 | .accelerator { 489 | text-decoration: underline; 490 | } 491 | 492 | .classifier { 493 | font-style: oblique; 494 | } 495 | 496 | abbr, acronym { 497 | border-bottom: dotted 1px; 498 | cursor: help; 499 | } 500 | 501 | /* -- code displays --------------------------------------------------------- */ 502 | 503 | pre { 504 | overflow: auto; 505 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 506 | } 507 | 508 | span.pre { 509 | -moz-hyphens: none; 510 | -ms-hyphens: none; 511 | -webkit-hyphens: none; 512 | hyphens: none; 513 | } 514 | 515 | td.linenos pre { 516 | padding: 5px 0px; 517 | border: 0; 518 | background-color: transparent; 519 | color: #aaa; 520 | } 521 | 522 | table.highlighttable { 523 | margin-left: 0.5em; 524 | } 525 | 526 | table.highlighttable td { 527 | padding: 0 0.5em 0 0.5em; 528 | } 529 | 530 | div.code-block-caption { 531 | padding: 2px 5px; 532 | font-size: small; 533 | } 534 | 535 | div.code-block-caption code { 536 | background-color: transparent; 537 | } 538 | 539 | div.code-block-caption + div > div.highlight > pre { 540 | margin-top: 0; 541 | } 542 | 543 | div.code-block-caption span.caption-number { 544 | padding: 0.1em 0.3em; 545 | font-style: italic; 546 | } 547 | 548 | div.code-block-caption span.caption-text { 549 | } 550 | 551 | div.literal-block-wrapper { 552 | padding: 1em 1em 0; 553 | } 554 | 555 | div.literal-block-wrapper div.highlight { 556 | margin: 0; 557 | } 558 | 559 | code.descname { 560 | background-color: transparent; 561 | font-weight: bold; 562 | font-size: 1.2em; 563 | } 564 | 565 | code.descclassname { 566 | background-color: transparent; 567 | } 568 | 569 | code.xref, a code { 570 | background-color: transparent; 571 | font-weight: bold; 572 | } 573 | 574 | h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { 575 | background-color: transparent; 576 | } 577 | 578 | .viewcode-link { 579 | float: right; 580 | } 581 | 582 | .viewcode-back { 583 | float: right; 584 | font-family: sans-serif; 585 | } 586 | 587 | div.viewcode-block:target { 588 | margin: -1px -10px; 589 | padding: 0 10px; 590 | } 591 | 592 | /* -- math display ---------------------------------------------------------- */ 593 | 594 | img.math { 595 | vertical-align: middle; 596 | } 597 | 598 | div.body div.math p { 599 | text-align: center; 600 | } 601 | 602 | span.eqno { 603 | float: right; 604 | } 605 | 606 | span.eqno a.headerlink { 607 | position: relative; 608 | left: 0px; 609 | z-index: 1; 610 | } 611 | 612 | div.math:hover a.headerlink { 613 | visibility: visible; 614 | } 615 | 616 | /* -- printout stylesheet --------------------------------------------------- */ 617 | 618 | @media print { 619 | div.document, 620 | div.documentwrapper, 621 | div.bodywrapper { 622 | margin: 0 !important; 623 | width: 100%; 624 | } 625 | 626 | div.sphinxsidebar, 627 | div.related, 628 | div.footer, 629 | #top-link { 630 | display: none; 631 | } 632 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/comment.png -------------------------------------------------------------------------------- /docs/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} 2 | /*# sourceMappingURL=badge_only.css.map */ 3 | -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node) { 70 | if (node.nodeType == 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 74 | var span = document.createElement("span"); 75 | span.className = className; 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 78 | document.createTextNode(val.substr(pos + text.length)), 79 | node.nextSibling)); 80 | node.nodeValue = val.substr(0, pos); 81 | } 82 | } 83 | else if (!jQuery(node).is("button, select, textarea")) { 84 | jQuery.each(node.childNodes, function() { 85 | highlight(this); 86 | }); 87 | } 88 | } 89 | return this.each(function() { 90 | highlight(this); 91 | }); 92 | }; 93 | 94 | /* 95 | * backward compatibility for jQuery.browser 96 | * This will be supported until firefox bug is fixed. 97 | */ 98 | if (!jQuery.browser) { 99 | jQuery.uaMatch = function(ua) { 100 | ua = ua.toLowerCase(); 101 | 102 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 103 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 104 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 105 | /(msie) ([\w.]+)/.exec(ua) || 106 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 107 | []; 108 | 109 | return { 110 | browser: match[ 1 ] || "", 111 | version: match[ 2 ] || "0" 112 | }; 113 | }; 114 | jQuery.browser = {}; 115 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 116 | } 117 | 118 | /** 119 | * Small JavaScript module for the documentation. 120 | */ 121 | var Documentation = { 122 | 123 | init : function() { 124 | this.fixFirefoxAnchorBug(); 125 | this.highlightSearchWords(); 126 | this.initIndexTable(); 127 | 128 | }, 129 | 130 | /** 131 | * i18n support 132 | */ 133 | TRANSLATIONS : {}, 134 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 135 | LOCALE : 'unknown', 136 | 137 | // gettext and ngettext don't access this so that the functions 138 | // can safely bound to a different name (_ = Documentation.gettext) 139 | gettext : function(string) { 140 | var translated = Documentation.TRANSLATIONS[string]; 141 | if (typeof translated == 'undefined') 142 | return string; 143 | return (typeof translated == 'string') ? translated : translated[0]; 144 | }, 145 | 146 | ngettext : function(singular, plural, n) { 147 | var translated = Documentation.TRANSLATIONS[singular]; 148 | if (typeof translated == 'undefined') 149 | return (n == 1) ? singular : plural; 150 | return translated[Documentation.PLURALEXPR(n)]; 151 | }, 152 | 153 | addTranslations : function(catalog) { 154 | for (var key in catalog.messages) 155 | this.TRANSLATIONS[key] = catalog.messages[key]; 156 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 157 | this.LOCALE = catalog.locale; 158 | }, 159 | 160 | /** 161 | * add context elements like header anchor links 162 | */ 163 | addContextElements : function() { 164 | $('div[id] > :header:first').each(function() { 165 | $('\u00B6'). 166 | attr('href', '#' + this.id). 167 | attr('title', _('Permalink to this headline')). 168 | appendTo(this); 169 | }); 170 | $('dt[id]').each(function() { 171 | $('\u00B6'). 172 | attr('href', '#' + this.id). 173 | attr('title', _('Permalink to this definition')). 174 | appendTo(this); 175 | }); 176 | }, 177 | 178 | /** 179 | * workaround a firefox stupidity 180 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 181 | */ 182 | fixFirefoxAnchorBug : function() { 183 | if (document.location.hash) 184 | window.setTimeout(function() { 185 | document.location.href += ''; 186 | }, 10); 187 | }, 188 | 189 | /** 190 | * highlight the search words provided in the url in the text 191 | */ 192 | highlightSearchWords : function() { 193 | var params = $.getQueryParameters(); 194 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 195 | if (terms.length) { 196 | var body = $('div.body'); 197 | if (!body.length) { 198 | body = $('body'); 199 | } 200 | window.setTimeout(function() { 201 | $.each(terms, function() { 202 | body.highlightText(this.toLowerCase(), 'highlighted'); 203 | }); 204 | }, 10); 205 | $('') 207 | .appendTo($('#searchbox')); 208 | } 209 | }, 210 | 211 | /** 212 | * init the domain index toggle buttons 213 | */ 214 | initIndexTable : function() { 215 | var togglers = $('img.toggler').click(function() { 216 | var src = $(this).attr('src'); 217 | var idnum = $(this).attr('id').substr(7); 218 | $('tr.cg-' + idnum).toggle(); 219 | if (src.substr(-9) == 'minus.png') 220 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 221 | else 222 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 223 | }).css('display', ''); 224 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 225 | togglers.click(); 226 | } 227 | }, 228 | 229 | /** 230 | * helper function to hide the search marks again 231 | */ 232 | hideSearchWords : function() { 233 | $('#searchbox .highlight-link').fadeOut(300); 234 | $('span.highlighted').removeClass('highlighted'); 235 | }, 236 | 237 | /** 238 | * make the url absolute 239 | */ 240 | makeURL : function(relativeURL) { 241 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 242 | }, 243 | 244 | /** 245 | * get the current relative url 246 | */ 247 | getCurrentURL : function() { 248 | var path = document.location.pathname; 249 | var parts = path.split(/\//); 250 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 251 | if (this == '..') 252 | parts.pop(); 253 | }); 254 | var url = parts.join('/'); 255 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 256 | }, 257 | 258 | initOnKeyListeners: function() { 259 | $(document).keyup(function(event) { 260 | var activeElementType = document.activeElement.tagName; 261 | // don't navigate when in search box or textarea 262 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { 263 | switch (event.keyCode) { 264 | case 37: // left 265 | var prevHref = $('link[rel="prev"]').prop('href'); 266 | if (prevHref) { 267 | window.location.href = prevHref; 268 | return false; 269 | } 270 | case 39: // right 271 | var nextHref = $('link[rel="next"]').prop('href'); 272 | if (nextHref) { 273 | window.location.href = nextHref; 274 | return false; 275 | } 276 | } 277 | } 278 | }); 279 | } 280 | }; 281 | 282 | // quick alias for translations 283 | _ = Documentation.gettext; 284 | 285 | $(document).ready(function() { 286 | Documentation.init(); 287 | }); -------------------------------------------------------------------------------- /docs/_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/down.png -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Inconsolata-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/Inconsolata-Bold.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Inconsolata-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/Inconsolata-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Lato-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/Lato-Bold.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Lato-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/Lato-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/RobotoSlab-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/RobotoSlab-Bold.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/RobotoSlab-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/RobotoSlab-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_build/html/_static/js/modernizr.min.js: -------------------------------------------------------------------------------- 1 | /* Modernizr 2.6.2 (Custom Build) | MIT & BSD 2 | * Build: http://modernizr.com/download/#-fontface-backgroundsize-borderimage-borderradius-boxshadow-flexbox-hsla-multiplebgs-opacity-rgba-textshadow-cssanimations-csscolumns-generatedcontent-cssgradients-cssreflections-csstransforms-csstransforms3d-csstransitions-applicationcache-canvas-canvastext-draganddrop-hashchange-history-audio-video-indexeddb-input-inputtypes-localstorage-postmessage-sessionstorage-websockets-websqldatabase-webworkers-geolocation-inlinesvg-smil-svg-svgclippaths-touch-webgl-shiv-mq-cssclasses-addtest-prefixed-teststyles-testprop-testallprops-hasevent-prefixes-domprefixes-load 3 | */ 4 | ;window.Modernizr=function(a,b,c){function D(a){j.cssText=a}function E(a,b){return D(n.join(a+";")+(b||""))}function F(a,b){return typeof a===b}function G(a,b){return!!~(""+a).indexOf(b)}function H(a,b){for(var d in a){var e=a[d];if(!G(e,"-")&&j[e]!==c)return b=="pfx"?e:!0}return!1}function I(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:F(f,"function")?f.bind(d||b):f}return!1}function J(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+p.join(d+" ")+d).split(" ");return F(b,"string")||F(b,"undefined")?H(e,b):(e=(a+" "+q.join(d+" ")+d).split(" "),I(e,b,c))}function K(){e.input=function(c){for(var d=0,e=c.length;d',a,""].join(""),l.id=h,(m?l:n).innerHTML+=f,n.appendChild(l),m||(n.style.background="",n.style.overflow="hidden",k=g.style.overflow,g.style.overflow="hidden",g.appendChild(n)),i=c(l,a),m?l.parentNode.removeChild(l):(n.parentNode.removeChild(n),g.style.overflow=k),!!i},z=function(b){var c=a.matchMedia||a.msMatchMedia;if(c)return c(b).matches;var d;return y("@media "+b+" { #"+h+" { position: absolute; } }",function(b){d=(a.getComputedStyle?getComputedStyle(b,null):b.currentStyle)["position"]=="absolute"}),d},A=function(){function d(d,e){e=e||b.createElement(a[d]||"div"),d="on"+d;var f=d in e;return f||(e.setAttribute||(e=b.createElement("div")),e.setAttribute&&e.removeAttribute&&(e.setAttribute(d,""),f=F(e[d],"function"),F(e[d],"undefined")||(e[d]=c),e.removeAttribute(d))),e=null,f}var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return d}(),B={}.hasOwnProperty,C;!F(B,"undefined")&&!F(B.call,"undefined")?C=function(a,b){return B.call(a,b)}:C=function(a,b){return b in a&&F(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=w.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(w.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(w.call(arguments)))};return e}),s.flexbox=function(){return J("flexWrap")},s.canvas=function(){var a=b.createElement("canvas");return!!a.getContext&&!!a.getContext("2d")},s.canvastext=function(){return!!e.canvas&&!!F(b.createElement("canvas").getContext("2d").fillText,"function")},s.webgl=function(){return!!a.WebGLRenderingContext},s.touch=function(){var c;return"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch?c=!0:y(["@media (",n.join("touch-enabled),("),h,")","{#modernizr{top:9px;position:absolute}}"].join(""),function(a){c=a.offsetTop===9}),c},s.geolocation=function(){return"geolocation"in navigator},s.postmessage=function(){return!!a.postMessage},s.websqldatabase=function(){return!!a.openDatabase},s.indexedDB=function(){return!!J("indexedDB",a)},s.hashchange=function(){return A("hashchange",a)&&(b.documentMode===c||b.documentMode>7)},s.history=function(){return!!a.history&&!!history.pushState},s.draganddrop=function(){var a=b.createElement("div");return"draggable"in a||"ondragstart"in a&&"ondrop"in a},s.websockets=function(){return"WebSocket"in a||"MozWebSocket"in a},s.rgba=function(){return D("background-color:rgba(150,255,150,.5)"),G(j.backgroundColor,"rgba")},s.hsla=function(){return D("background-color:hsla(120,40%,100%,.5)"),G(j.backgroundColor,"rgba")||G(j.backgroundColor,"hsla")},s.multiplebgs=function(){return D("background:url(https://),url(https://),red url(https://)"),/(url\s*\(.*?){3}/.test(j.background)},s.backgroundsize=function(){return J("backgroundSize")},s.borderimage=function(){return J("borderImage")},s.borderradius=function(){return J("borderRadius")},s.boxshadow=function(){return J("boxShadow")},s.textshadow=function(){return b.createElement("div").style.textShadow===""},s.opacity=function(){return E("opacity:.55"),/^0.55$/.test(j.opacity)},s.cssanimations=function(){return J("animationName")},s.csscolumns=function(){return J("columnCount")},s.cssgradients=function(){var a="background-image:",b="gradient(linear,left top,right bottom,from(#9f9),to(white));",c="linear-gradient(left top,#9f9, white);";return D((a+"-webkit- ".split(" ").join(b+a)+n.join(c+a)).slice(0,-a.length)),G(j.backgroundImage,"gradient")},s.cssreflections=function(){return J("boxReflect")},s.csstransforms=function(){return!!J("transform")},s.csstransforms3d=function(){var a=!!J("perspective");return a&&"webkitPerspective"in g.style&&y("@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}",function(b,c){a=b.offsetLeft===9&&b.offsetHeight===3}),a},s.csstransitions=function(){return J("transition")},s.fontface=function(){var a;return y('@font-face {font-family:"font";src:url("https://")}',function(c,d){var e=b.getElementById("smodernizr"),f=e.sheet||e.styleSheet,g=f?f.cssRules&&f.cssRules[0]?f.cssRules[0].cssText:f.cssText||"":"";a=/src/i.test(g)&&g.indexOf(d.split(" ")[0])===0}),a},s.generatedcontent=function(){var a;return y(["#",h,"{font:0/0 a}#",h,':after{content:"',l,'";visibility:hidden;font:3px/1 a}'].join(""),function(b){a=b.offsetHeight>=3}),a},s.video=function(){var a=b.createElement("video"),c=!1;try{if(c=!!a.canPlayType)c=new Boolean(c),c.ogg=a.canPlayType('video/ogg; codecs="theora"').replace(/^no$/,""),c.h264=a.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/,""),c.webm=a.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,"")}catch(d){}return c},s.audio=function(){var a=b.createElement("audio"),c=!1;try{if(c=!!a.canPlayType)c=new Boolean(c),c.ogg=a.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,""),c.mp3=a.canPlayType("audio/mpeg;").replace(/^no$/,""),c.wav=a.canPlayType('audio/wav; codecs="1"').replace(/^no$/,""),c.m4a=(a.canPlayType("audio/x-m4a;")||a.canPlayType("audio/aac;")).replace(/^no$/,"")}catch(d){}return c},s.localstorage=function(){try{return localStorage.setItem(h,h),localStorage.removeItem(h),!0}catch(a){return!1}},s.sessionstorage=function(){try{return sessionStorage.setItem(h,h),sessionStorage.removeItem(h),!0}catch(a){return!1}},s.webworkers=function(){return!!a.Worker},s.applicationcache=function(){return!!a.applicationCache},s.svg=function(){return!!b.createElementNS&&!!b.createElementNS(r.svg,"svg").createSVGRect},s.inlinesvg=function(){var a=b.createElement("div");return a.innerHTML="",(a.firstChild&&a.firstChild.namespaceURI)==r.svg},s.smil=function(){return!!b.createElementNS&&/SVGAnimate/.test(m.call(b.createElementNS(r.svg,"animate")))},s.svgclippaths=function(){return!!b.createElementNS&&/SVGClipPath/.test(m.call(b.createElementNS(r.svg,"clipPath")))};for(var L in s)C(s,L)&&(x=L.toLowerCase(),e[x]=s[L](),v.push((e[x]?"":"no-")+x));return e.input||K(),e.addTest=function(a,b){if(typeof a=="object")for(var d in a)C(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},D(""),i=k=null,function(a,b){function k(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function l(){var a=r.elements;return typeof a=="string"?a.split(" "):a}function m(a){var b=i[a[g]];return b||(b={},h++,a[g]=h,i[h]=b),b}function n(a,c,f){c||(c=b);if(j)return c.createElement(a);f||(f=m(c));var g;return f.cache[a]?g=f.cache[a].cloneNode():e.test(a)?g=(f.cache[a]=f.createElem(a)).cloneNode():g=f.createElem(a),g.canHaveChildren&&!d.test(a)?f.frag.appendChild(g):g}function o(a,c){a||(a=b);if(j)return a.createDocumentFragment();c=c||m(a);var d=c.frag.cloneNode(),e=0,f=l(),g=f.length;for(;e",f="hidden"in a,j=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){f=!0,j=!0}})();var r={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,supportsUnknownElements:j,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:q,createElement:n,createDocumentFragment:o};a.html5=r,q(b)}(this,b),e._version=d,e._prefixes=n,e._domPrefixes=q,e._cssomPrefixes=p,e.mq=z,e.hasEvent=A,e.testProp=function(a){return H([a])},e.testAllProps=J,e.testStyles=y,e.prefixed=function(a,b,c){return b?J(a,b,c):J(a,"pfx")},g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+v.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f"); 80 | 81 | // Add expand links to all parents of nested ul 82 | $('.wy-menu-vertical ul').not('.simple').siblings('a').each(function () { 83 | var link = $(this); 84 | expand = $(''); 85 | expand.on('click', function (ev) { 86 | self.toggleCurrent(link); 87 | ev.stopPropagation(); 88 | return false; 89 | }); 90 | link.prepend(expand); 91 | }); 92 | }; 93 | 94 | nav.reset = function () { 95 | // Get anchor from URL and open up nested nav 96 | var anchor = encodeURI(window.location.hash); 97 | if (anchor) { 98 | try { 99 | var link = $('.wy-menu-vertical') 100 | .find('[href="' + anchor + '"]'); 101 | // If we didn't find a link, it may be because we clicked on 102 | // something that is not in the sidebar (eg: when using 103 | // sphinxcontrib.httpdomain it generates headerlinks but those 104 | // aren't picked up and placed in the toctree). So let's find 105 | // the closest header in the document and try with that one. 106 | if (link.length === 0) { 107 | var doc_link = $('.document a[href="' + anchor + '"]'); 108 | var closest_section = doc_link.closest('div.section'); 109 | // Try again with the closest section entry. 110 | link = $('.wy-menu-vertical') 111 | .find('[href="#' + closest_section.attr("id") + '"]'); 112 | 113 | } 114 | $('.wy-menu-vertical li.toctree-l1 li.current') 115 | .removeClass('current'); 116 | link.closest('li.toctree-l2').addClass('current'); 117 | link.closest('li.toctree-l3').addClass('current'); 118 | link.closest('li.toctree-l4').addClass('current'); 119 | } 120 | catch (err) { 121 | console.log("Error expanding nav for anchor", err); 122 | } 123 | } 124 | }; 125 | 126 | nav.onScroll = function () { 127 | this.winScroll = false; 128 | var newWinPosition = this.win.scrollTop(), 129 | winBottom = newWinPosition + this.winHeight, 130 | navPosition = this.navBar.scrollTop(), 131 | newNavPosition = navPosition + (newWinPosition - this.winPosition); 132 | if (newWinPosition < 0 || winBottom > this.docHeight) { 133 | return; 134 | } 135 | this.navBar.scrollTop(newNavPosition); 136 | this.winPosition = newWinPosition; 137 | }; 138 | 139 | nav.onResize = function () { 140 | this.winResize = false; 141 | this.winHeight = this.win.height(); 142 | this.docHeight = $(document).height(); 143 | }; 144 | 145 | nav.hashChange = function () { 146 | this.linkScroll = true; 147 | this.win.one('hashchange', function () { 148 | this.linkScroll = false; 149 | }); 150 | }; 151 | 152 | nav.toggleCurrent = function (elem) { 153 | var parent_li = elem.closest('li'); 154 | parent_li.siblings('li.current').removeClass('current'); 155 | parent_li.siblings().find('li.current').removeClass('current'); 156 | parent_li.find('> ul li.current').removeClass('current'); 157 | parent_li.toggleClass('current'); 158 | } 159 | 160 | return nav; 161 | }; 162 | 163 | module.exports.ThemeNav = ThemeNav(); 164 | 165 | if (typeof(window) != 'undefined') { 166 | window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav }; 167 | } 168 | 169 | },{"jquery":"jquery"}]},{},["sphinx-rtd-theme"]); 170 | -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #333333 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #208050 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 50 | .highlight .sa { color: #4070a0 } /* Literal.String.Affix */ 51 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 52 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 53 | .highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */ 54 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 55 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 56 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 57 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 58 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 59 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 60 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 61 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 62 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 63 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 64 | .highlight .fm { color: #06287e } /* Name.Function.Magic */ 65 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 66 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 67 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 68 | .highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */ 69 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_build/html/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /docs/_build/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/_static/up.png -------------------------------------------------------------------------------- /docs/_build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Index — pyvaru 0.3.0 documentation 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 99 | 100 |
101 | 102 | 103 | 109 | 110 | 111 | 112 |
113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
131 | 132 |
    133 | 134 |
  • Docs »
  • 135 | 136 |
  • Index
  • 137 | 138 | 139 |
  • 140 | 141 | 142 | 143 |
  • 144 | 145 |
146 | 147 | 148 |
149 |
150 |
151 |
152 | 153 | 154 |

Index

155 | 156 |
157 | A 158 | | C 159 | | D 160 | | F 161 | | G 162 | | I 163 | | J 164 | | M 165 | | P 166 | | R 167 | | T 168 | | U 169 | | V 170 | | W 171 | 172 |
173 |

A

174 | 175 | 179 | 185 |
186 | 187 |

C

188 | 189 | 193 |
194 | 195 |

D

196 | 197 | 229 |
230 | 231 |

F

232 | 233 | 237 | 241 |
242 | 243 |

G

244 | 245 | 277 | 281 |
282 | 283 |

I

284 | 285 | 289 | 295 |
296 | 297 |

J

298 | 299 | 303 |
304 | 305 |

M

306 | 307 | 313 | 319 |
320 | 321 |

P

322 | 323 | 329 | 335 |
336 | 337 |

R

338 | 339 | 343 | 347 |
348 | 349 |

T

350 | 351 | 355 |
356 | 357 |

U

358 | 359 | 363 |
364 | 365 |

V

366 | 367 | 373 | 381 |
382 | 383 |

W

384 | 385 | 393 |
394 | 395 | 396 | 397 |
398 |
399 | 400 |
401 |
402 |
403 | 404 | 405 |
406 | 407 |
408 |

409 | © Copyright 2017, Davide Zanotti. 410 | 411 |

412 |
413 | Built with Sphinx using a theme provided by Read the Docs. 414 | 415 |
416 | 417 |
418 |
419 | 420 |
421 | 422 |
423 | 424 | 425 | 426 | 427 | 428 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 456 | 457 | 458 | 459 | -------------------------------------------------------------------------------- /docs/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Pyvaru documentation — pyvaru 0.3.0 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 109 | 110 |
111 | 112 | 113 | 119 | 120 | 121 | 122 |
123 |
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 |
141 | 142 |
    143 | 144 |
  • Docs »
  • 145 | 146 |
  • Pyvaru documentation
  • 147 | 148 | 149 |
  • 150 | 151 | 152 | View page source 153 | 154 | 155 |
  • 156 | 157 |
158 | 159 | 160 |
161 |
162 |
163 |
164 | 165 |
166 |

Pyvaru documentation

167 |
168 |
169 | https://travis-ci.org/daveoncode/pyvaru.svg?branch=master 170 | https://codecov.io/gh/daveoncode/pyvaru/branch/master/graph/badge.svg 171 |
172 |

What is pyvaru?

173 |

Pyvaru is a simple, flexible and unobtrusive data validation library for Python 3 (3.4+), 174 | based on the concept of validation rules.

175 |

From the software design point of view, a rule is a class implementing the strategy pattern, 176 | by encapsulating the validation logic in an interface method called apply().

177 |

The library already offers a series of common validation rules like:

178 |
    179 |
  • TypeRule (it checks that the target value is an instance of the expected type)
  • 180 |
  • FullStringRule (it checks the the target value is a string with content)
  • 181 |
  • ChoiceRule (it checks that the target value is contained in a list of available options)
  • 182 |
  • MinValueRule (it checks that the target value is >= x) *
  • 183 |
  • MaxValueRule (it checks that the target value is <= x) *
  • 184 |
  • MinLengthRule (it checks that the target value length is >= x) *
  • 185 |
  • MaxLengthRule (it checks that the target value length is <= x) *
  • 186 |
  • RangeRule (it checks that the target value is contained in a given range)
  • 187 |
  • IntervalRule (it checks that the target value is contained in a given interval)
  • 188 |
  • PatternRule (it checks that the target value matches a given regular expression)
  • 189 |
  • PastDateRule (it checks that the target value is a date in the past)
  • 190 |
  • FutureDateRule (it checks that the target value is a date in the future)
  • 191 |
  • UniqueItemsRule (it checks that the target iterable does not contain duplicated items)
  • 192 |
193 |

* where “x” is a provided reference value

194 |

The developer is then free to create his custom rules by extending the abstract ValidationRule 195 | and implementing the logic in the apply() method. For example:

196 |
class ContainsHelloRule(ValidationRule):
197 |     def apply(self) -> bool:
198 |         return 'hello' in self.apply_to
199 | 
200 |
201 |

These rules are then executed by a Validator, which basically executes them in the provided 202 | order and eventually returns a ValidationResult containing the validation response.

203 |
204 |
205 |

Installation

206 |

pip install pyvaru

207 |
208 |
209 |

Usage

210 |

Given an existing model to validate, like the one below 211 | (but it could be a simple dictionary or any data structure since pyvaru 212 | does not make any assumption on the data format):

213 |
class User:
214 |     def __init__(self, first_name: str, last_name: str, date_of_birth: datetime, sex: str):
215 |         self.first_name = first_name
216 |         self.last_name = last_name
217 |         self.date_of_birth = date_of_birth
218 |         self.sex = sex
219 | 
220 |
221 |

We have to define a validator, by implementing the get_rules() method and for each field we want to 222 | validate we have to provide one or more proper rule(s).

223 |
from pyvaru import Validator
224 | from pyvaru.rules import TypeRule, FullStringRule, ChoiceRule, PastDateRule
225 | 
226 | class UserValidator(Validator):
227 |     def get_rules(self) -> list:
228 |         user = self.data # type: User
229 |         return [
230 |             TypeRule(apply_to=user,
231 |                      label='User',
232 |                      valid_type=User,
233 |                      error_message='User must be an instance of user model.',
234 |                      stop_if_invalid=True),
235 |             FullStringRule(lambda: user.first_name, 'First name'),
236 |             FullStringRule(lambda: user.last_name, 'Last name'),
237 |             ChoiceRule(lambda: user.sex, 'Sex', choices=('M', 'F')),
238 |             PastDateRule(lambda: user.date_of_birth, 'Date of birth')
239 |         ]
240 | 
241 |
242 |

It’s also possible to create groups of rules by using RuleGroup and avoid code duplication if multiple rules should 243 | be applied to the same field. So this code:

244 |
def get_rules(self) -> list:
245 |     return [
246 |         TypeRule(lambda: self.data.countries, 'Countries', valid_type=list),
247 |         MinLengthRule(lambda: self.data.countries, 'Countries', min_length=1),
248 |         UniqueItemsRule(lambda: self.data.countries, 'Countries')
249 |     ]
250 | 
251 |
252 |

can be replaced by:

253 |
def get_rules(self) -> list:
254 |     return [
255 |         RuleGroup(lambda: self.data.countries,
256 |                   'Countries',
257 |                   rules=[(TypeRule, {'valid_type': list}),
258 |                          (MinLengthRule, {'min_length': 1}),
259 |                          UniqueItemsRule])
260 |     ]
261 | 
262 |
263 |

Finally we have two choices regarding how to use our custom validator:

264 |
    265 |
  1. As a context processor:
  2. 266 |
267 |
with UserValidator(user):
268 |     # do whatever you want with your valid model
269 | 
270 |
271 |

In this case the code inside with will be executed only if the validation succeed, otherwise a 272 | ValidationException (containing a validation_result property with the appropriate report) is raised.

273 |
    274 |
  1. By invoking the validate() method (which returns a ValidationResult)
  2. 275 |
276 |
validation = UserValidator(user).validate()
277 | if validation.is_successful():
278 |     # do whatever you want with your valid model
279 | else:
280 |     # you can take a proper action and access validation.errors
281 |     # in order to provide a useful message to the application user,
282 |     # write logs or whatever
283 | 
284 |
285 |

Assuming we have a instance of an User configured as the one below:

286 |
user = User(first_name=' ',
287 |             last_name=None,
288 |             date_of_birth=datetime(2020, 1, 1),
289 |             sex='unknown')
290 | 
291 |
292 |

By running a validation with the previous defined rules we will obtain a ValidationResult with the following errors:

293 |
{
294 |     'First name': ['String is empty.'],
295 |     'Last name': ['Not a string.'],
296 |     'Sex': ['Value not found in available choices.'],
297 |     'Date of birth': ['Not a past date.']
298 | }
299 | 
300 |
301 |
302 |
303 |

Full API Documentation

304 |

Go to: http://pyvaru.readthedocs.io/en/latest/contents.html

305 |
306 |
307 |

Credits

308 |

Pyvaru is developed and maintained by Davide Zanotti.

309 |

Blog: http://www.daveoncode.com

310 |

Twitter: https://twitter.com/daveoncode

311 |
312 |
313 |
314 |

Indices and tables

315 | 320 |
321 | 322 | 323 |
324 |
325 | 326 |
327 |
328 |
329 | 330 | 331 |
332 | 333 |
334 |

335 | © Copyright 2017, Davide Zanotti. 336 | 337 |

338 |
339 | Built with Sphinx using a theme provided by Read the Docs. 340 | 341 |
342 | 343 |
344 |
345 | 346 |
347 | 348 |
349 | 350 | 351 | 352 | 353 | 354 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 382 | 383 | 384 | 385 | -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/_build/html/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Python Module Index — pyvaru 0.3.0 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
52 | 53 | 54 | 101 | 102 |
103 | 104 | 105 | 111 | 112 | 113 | 114 |
115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 |
133 | 134 |
    135 | 136 |
  • Docs »
  • 137 | 138 |
  • Python Module Index
  • 139 | 140 | 141 |
  • 142 | 143 | 144 | 145 |
  • 146 | 147 |
148 | 149 | 150 |
151 |
152 |
153 |
154 | 155 | 156 |

Python Module Index

157 | 158 |
159 | p 160 |
161 | 162 | 163 | 164 | 166 | 167 | 169 | 172 | 173 | 174 | 177 |
 
165 | p
170 | pyvaru 171 |
    175 | pyvaru.rules 176 |
178 | 179 | 180 |
181 |
182 | 183 |
184 |
185 |
186 | 187 | 188 |
189 | 190 |
191 |

192 | © Copyright 2017, Davide Zanotti. 193 | 194 |

195 |
196 | Built with Sphinx using a theme provided by Read the Docs. 197 | 198 |
199 | 200 |
201 |
202 | 203 |
204 | 205 |
206 | 207 | 208 | 209 | 210 | 211 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Search — pyvaru 0.3.0 documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 98 | 99 |
100 | 101 | 102 | 108 | 109 | 110 | 111 |
112 |
113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 |
130 | 131 |
    132 | 133 |
  • Docs »
  • 134 | 135 |
  • Search
  • 136 | 137 | 138 |
  • 139 | 140 |
  • 141 | 142 |
143 | 144 | 145 |
146 |
147 |
148 |
149 | 150 | 158 | 159 | 160 |
161 | 162 |
163 | 164 |
165 |
166 | 167 |
168 |
169 |
170 | 171 | 172 |
173 | 174 |
175 |

176 | © Copyright 2017, Davide Zanotti. 177 | 178 |

179 |
180 | Built with Sphinx using a theme provided by Read the Docs. 181 | 182 |
183 | 184 |
185 |
186 | 187 |
188 | 189 |
190 | 191 | 192 | 193 | 194 | 195 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 224 | 225 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /docs/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["_autosummary/pyvaru","_autosummary/pyvaru.rules","contents","index"],envversion:51,filenames:["_autosummary/pyvaru.rst","_autosummary/pyvaru.rules.rst","contents.rst","index.rst"],objects:{"":{pyvaru:[2,0,0,"-"]},"pyvaru.InvalidRuleGroupException":{with_traceback:[2,2,1,""]},"pyvaru.ValidationException":{with_traceback:[2,2,1,""]},"pyvaru.ValidationResult":{annotate_exception:[2,2,1,""],annotate_rule_violation:[2,2,1,""],is_successful:[2,2,1,""]},"pyvaru.ValidationRule":{apply:[2,2,1,""],default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.Validator":{get_rules:[2,2,1,""],validate:[2,2,1,""]},"pyvaru.rules":{ChoiceRule:[2,3,1,""],FullStringRule:[2,3,1,""],FutureDateRule:[2,3,1,""],IntervalRule:[2,3,1,""],MaxLengthRule:[2,3,1,""],MaxValueRule:[2,3,1,""],MinLengthRule:[2,3,1,""],MinValueRule:[2,3,1,""],PastDateRule:[2,3,1,""],PatternRule:[2,3,1,""],RangeRule:[2,3,1,""],TypeRule:[2,3,1,""],UniqueItemsRule:[2,3,1,""]},"pyvaru.rules.ChoiceRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.FullStringRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.FutureDateRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.IntervalRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.MaxLengthRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.MaxValueRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.MinLengthRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.MinValueRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.PastDateRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.PatternRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.RangeRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.TypeRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},"pyvaru.rules.UniqueItemsRule":{default_error_message:[2,4,1,""],get_error_message:[2,2,1,""]},pyvaru:{InvalidRuleGroupException:[2,1,1,""],JoinType:[2,3,1,""],RuleGroup:[2,3,1,""],ValidationException:[2,1,1,""],ValidationResult:[2,3,1,""],ValidationRule:[2,3,1,""],Validator:[2,3,1,""],rules:[2,0,0,"-"]}},objnames:{"0":["py","module","Python module"],"1":["py","exception","Python exception"],"2":["py","method","Python method"],"3":["py","class","Python class"],"4":["py","attribute","Python attribute"]},objtypes:{"0":"py:module","1":"py:exception","2":"py:method","3":"py:class","4":"py:attribute"},terms:{"abstract":[2,3],"boolean":2,"case":3,"catch":2,"class":[0,1,2,3],"default":2,"final":3,"float":2,"function":0,"import":[2,3],"int":2,"new":[],"return":[2,3],"short":2,"true":[2,3],AND:2,For:[2,3],Not:[2,3],The:[2,3],These:3,__init__:3,__traceback__:2,abov:[],access:[2,3],action:3,actual:2,against:2,all:2,allow:2,alreadi:3,also:3,alwai:2,ani:[2,3],annotate_except:2,annotate_rule_viol:2,appli:[2,3],applic:3,apply_to:[2,3],appropri:3,assum:3,assumpt:3,attribut:2,avail:[2,3],avoid:3,base:[2,3],basic:3,being:[],below:3,between:2,birth:3,blog:3,bool:[2,3],call:[2,3],can:[2,3],caus:2,check:[2,3],choic:[2,3],choicerul:[2,3],code:3,codecov:[],collect:2,com:3,common:3,concept:3,concret:2,configur:[2,3],contain:[2,3],containshellorul:3,content:3,context:[2,3],could:3,countri:[2,3],creat:3,current:2,custom:[2,3],data:[2,3],date:[2,3],date_of_birth:3,datetim:[2,3],daveoncod:3,david:3,def:3,default_error_messag:2,defin:3,describ:2,descript:2,design:3,develop:3,dict:2,dictionari:[2,3],did:2,doe:[2,3],doesn:2,duplic:[2,3],dure:2,each:3,els:3,empti:[2,3],encapsul:3,ensur:2,enumer:2,error:[2,3],error_messag:[2,3],even:2,eventu:3,exampl:[2,3],except:[0,2],execut:[2,3],exist:3,expect:[2,3],express:3,extend:3,fail:2,failur:2,fals:2,field:[2,3],first:3,first_nam:3,flag:2,flexibl:3,follow:3,format:[2,3],found:[2,3],free:3,from:[2,3],fullstringrul:[2,3],futur:[2,3],futuredaterul:[2,3],get_error_messag:2,get_rul:[2,3],given:[2,3],greater:2,group:[2,3],handl:2,has:2,have:3,hello:3,his:3,how:3,html:3,http:3,implement:[2,3],increment:2,index:3,indic:2,inherit:2,insid:[2,3],instal:[],instanc:[2,3],instanti:2,instead:2,integ:2,interfac:3,intern:2,interv:[2,3],interval_from:2,interval_to:2,intervalrul:[2,3],invalid:2,invalidrulegroupexcept:2,invok:3,is_success:[2,3],item:[2,3],iter:[2,3],its:2,jointyp:2,kei:2,label:[2,3],lambda:3,last:3,last_nam:3,latest:3,len:2,length:[2,3],librari:[2,3],like:[2,3],list:[2,3],log:3,logic:3,maintain:3,make:3,map:2,match:[2,3],max_length:2,max_valu:2,maximum:2,maxlengthrul:[2,3],maxvaluerul:[2,3],messag:[2,3],method:[2,3],min_length:[2,3],min_valu:2,minimum:2,minlengthrul:[2,3],minvaluerul:[2,3],model:[2,3],modul:3,more:[2,3],multipl:[2,3],must:[2,3],name:[2,3],non:2,none:[2,3],note:2,now:2,number:2,object:2,obtain:3,occur:2,offer:3,one:[2,3],ones:2,onli:3,option:[2,3],order:[2,3],ore:2,otherwis:[2,3],our:3,out:2,page:3,param:[],paramet:2,past:[2,3],pastdaterul:[2,3],pattern:[2,3],patternrul:[2,3],phase:2,phone:2,pip:3,point:3,possibl:[2,3],prevent:2,previou:3,process:2,processor:[2,3],proper:3,properti:3,provid:[2,3],pyavaru:[],python:[2,3],pyvaru:2,rais:[2,3],rang:[2,3],rangerul:[2,3],readthedoc:3,refer:[2,3],reference_d:2,regard:3,regex:2,regular:3,replac:3,report:[2,3],repres:2,respect:2,respons:3,rest:2,result:2,rule:3,ruleclass:2,rulegroup:[2,3],run:3,same:3,search:3,self:[2,3],sequenti:2,seri:3,set:2,sex:3,should:3,simpl:3,sinc:3,smaller:2,softwar:3,step:2,stop_if_invalid:[2,3],str:[2,3],strategi:3,string:[2,3],structur:3,succe:3,success:2,support:2,take:[2,3],target:[2,3],test:2,than:2,them:3,thi:[2,3],time:2,tupl:2,twitter:3,two:3,type:[2,3],type_error_messag:[],typeerror:[],typerul:[2,3],typic:2,uniqueitemsrul:[2,3],unknown:3,unobtrus:3,usag:[],use:[2,3],used:2,useful:3,user:[2,3],uservalid:3,using:[2,3],valid:3,valid_rang:2,valid_typ:[2,3],validation_result:[2,3],validationexcept:[2,3],validationresult:[2,3],validationrul:[2,3],valu:[2,3],view:3,want:3,what:[],whaterv:[],whatev:3,when:2,where:3,whether:2,which:[2,3],with_traceback:2,write:3,www:3,you:3,your:3,zanotti:3},titles:["pyvaru","pyvaru.rules","Core API","Pyvaru documentation"],titleterms:{api:[2,3],core:2,credit:3,document:3,full:3,gener:2,indic:3,instal:3,pyavaru:[],pyvaru:[0,1,3],rule:[1,2],tabl:3,usag:3,valid:2,what:3}}) -------------------------------------------------------------------------------- /docs/_static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_static/.gitkeep -------------------------------------------------------------------------------- /docs/_templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daveoncode/pyvaru/78ad9c55d44aef1f24028b2c83e7de12f2698abb/docs/_templates/.gitkeep -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # pyvaru documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Feb 3 16:34:08 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | import os 21 | import sys 22 | 23 | __current_dir = os.path.dirname(__file__) 24 | __pyvaru_dir = os.path.abspath(os.path.join(__current_dir, os.pardir)) 25 | sys.path.append(__pyvaru_dir) 26 | 27 | # -- General configuration ------------------------------------------------ 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | # 31 | # needs_sphinx = '1.0' 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = [ 37 | 'sphinx.ext.autodoc', 38 | 'sphinx.ext.autosummary', 39 | ] 40 | autosummary_generate = True 41 | 42 | # Add any paths that contain templates here, relative to this directory. 43 | templates_path = ['_templates'] 44 | 45 | # The suffix(es) of docs filenames. 46 | # You can specify multiple suffix as a list of string: 47 | # 48 | # source_suffix = ['.rst', '.md'] 49 | source_suffix = '.rst' 50 | 51 | # The master toctree document. 52 | master_doc = 'index' 53 | 54 | # General information about the project. 55 | project = 'pyvaru' 56 | copyright = '2017, Davide Zanotti' 57 | author = 'Davide Zanotti' 58 | 59 | # The version info for the project you're documenting, acts as replacement for 60 | # |version| and |release|, also used in various other places throughout the 61 | # built documents. 62 | # 63 | # The short X.Y version. 64 | version = '0.3.0' 65 | # The full version, including alpha/beta/rc tags. 66 | release = '0.3.0' 67 | 68 | # The language for content autogenerated by Sphinx. Refer to documentation 69 | # for a list of supported languages. 70 | # 71 | # This is also used if you do content translation via gettext catalogs. 72 | # Usually you set "language" from the command line for these cases. 73 | language = None 74 | 75 | # List of patterns, relative to docs directory, that match files and 76 | # directories to ignore when looking for docs files. 77 | # This patterns also effect to html_static_path and html_extra_path 78 | exclude_patterns = [] 79 | 80 | # The name of the Pygments (syntax highlighting) style to use. 81 | pygments_style = 'sphinx' 82 | 83 | # If true, `todo` and `todoList` produce output, else they produce nothing. 84 | todo_include_todos = False 85 | 86 | # -- Options for HTML output ---------------------------------------------- 87 | 88 | # The theme to use for HTML and HTML Help pages. See the documentation for 89 | # a list of builtin themes. 90 | # 91 | html_theme = 'sphinx_rtd_theme' 92 | 93 | # Theme options are theme-specific and customize the look and feel of a theme 94 | # further. For a list of options available for each theme, see the 95 | # documentation. 96 | # 97 | # html_theme_options = {} 98 | 99 | # Add any paths that contain custom static files (such as style sheets) here, 100 | # relative to this directory. They are copied after the builtin static files, 101 | # so a file named "default.css" will overwrite the builtin "default.css". 102 | html_static_path = ['_static'] 103 | 104 | # -- Options for HTMLHelp output ------------------------------------------ 105 | 106 | # Output file base name for HTML help builder. 107 | htmlhelp_basename = 'pyvarudoc' 108 | 109 | # -- Options for LaTeX output --------------------------------------------- 110 | 111 | latex_elements = { 112 | # The paper size ('letterpaper' or 'a4paper'). 113 | # 114 | # 'papersize': 'letterpaper', 115 | 116 | # The font size ('10pt', '11pt' or '12pt'). 117 | # 118 | # 'pointsize': '10pt', 119 | 120 | # Additional stuff for the LaTeX preamble. 121 | # 122 | # 'preamble': '', 123 | 124 | # Latex figure (float) alignment 125 | # 126 | # 'figure_align': 'htbp', 127 | } 128 | 129 | # Grouping the document tree into LaTeX files. List of tuples 130 | # (docs start file, target name, title, 131 | # author, documentclass [howto, manual, or own class]). 132 | latex_documents = [ 133 | (master_doc, 'pyvaru.tex', 'pyvaru Documentation', 'Davide Zanotti', 'manual'), 134 | ] 135 | 136 | # -- Options for manual page output --------------------------------------- 137 | 138 | # One entry per manual page. List of tuples 139 | # (docs start file, name, description, authors, manual section). 140 | man_pages = [ 141 | (master_doc, 'pyvaru', 'pyvaru Documentation', [author], 1) 142 | ] 143 | 144 | # -- Options for Texinfo output ------------------------------------------- 145 | 146 | # Grouping the document tree into Texinfo files. List of tuples 147 | # (docs start file, target name, title, author, 148 | # dir menu entry, description, category) 149 | texinfo_documents = [ 150 | ( 151 | master_doc, 152 | 'pyvaru', 153 | 'pyvaru Documentation', 154 | author, 'pyvaru', 'Rule based data validation library for python.', 155 | 'Miscellaneous' 156 | ), 157 | ] 158 | -------------------------------------------------------------------------------- /docs/contents.rst: -------------------------------------------------------------------------------- 1 | .. autosummary:: 2 | :toctree: _autosummary 3 | 4 | pyvaru 5 | pyvaru.rules 6 | 7 | 8 | Core API 9 | ======== 10 | 11 | .. automodule:: pyvaru 12 | :members: 13 | :inherited-members: 14 | 15 | 16 | Generic validation rules 17 | ======================== 18 | 19 | .. automodule:: pyvaru.rules 20 | :members: 21 | :inherited-members: 22 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Pyvaru documentation 4 | ==================== 5 | 6 | .. toctree:: 7 | :maxdepth: 5 8 | 9 | .. include:: ../README.rst 10 | 11 | .. ref::`contents` 12 | 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /pyvaru/__init__.py: -------------------------------------------------------------------------------- 1 | import pprint 2 | from abc import ABC, abstractmethod 3 | from enum import Enum 4 | 5 | from inspect import isfunction 6 | 7 | __version__ = '0.3.0' 8 | __all__ = ( 9 | 'ValidationRule', 10 | 'ValidationResult', 11 | 'ValidationException', 12 | 'Validator', 13 | 'JoinType', 14 | 'RuleGroup', 15 | 'InvalidRuleGroupException', 16 | ) 17 | 18 | 19 | class JoinType(Enum): 20 | AND = 1 21 | OR = 2 22 | XOR = 3 23 | NOT = 4 24 | 25 | 26 | class ValidationRule(ABC): 27 | """ 28 | Base abstract rule class from which concrete ones must inherit from. 29 | 30 | :param apply_to: Value against which the rule is applied (can be any type). 31 | :type apply_to: object 32 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 33 | This string will be used as the key in the ValidationResult error dictionary. 34 | :type label: str 35 | :param error_message: Custom message that will be used instead of the "default_error_message". 36 | :type error_message: str 37 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 38 | is not respected, False (default) to collect all the possible errors. 39 | :type stop_if_invalid: bool 40 | """ 41 | 42 | #: Default error message for the rule (class attribute). 43 | default_error_message = 'Data is invalid.' 44 | 45 | def __init__(self, 46 | apply_to: object, 47 | label: str, 48 | error_message: str = None, 49 | stop_if_invalid: bool = False): 50 | self.__apply_to = apply_to 51 | self.label = label 52 | self.custom_error_message = error_message 53 | self.stop_if_invalid = stop_if_invalid 54 | 55 | @property 56 | def apply_to(self) -> object: 57 | if isfunction(self.__apply_to): 58 | # noinspection PyCallingNonCallable 59 | return self.__apply_to() 60 | return self.__apply_to 61 | 62 | def get_error_message(self) -> str: 63 | """ 64 | Returns the message that will be used by the validator if the rule is not respected. 65 | If a custom error message is provided during rule instantiation that one will be used, 66 | otherwise the default one. 67 | 68 | :return: Error message 69 | :rtype: str 70 | """ 71 | return self.custom_error_message or self.default_error_message 72 | 73 | @abstractmethod 74 | def apply(self) -> bool: 75 | """ 76 | Abstract method that must be implemented by concrete get_rules in order to return a boolean 77 | indicating whether the rule is respected or not. 78 | 79 | :return: True if the rule is respected, False otherwise 80 | :rtype: bool 81 | """ 82 | pass # pragma: no cover 83 | 84 | def __invert__(self): 85 | def inverted_apply(apply): 86 | def decorated_function(): 87 | return not apply() 88 | 89 | return decorated_function 90 | 91 | self.apply = inverted_apply(self.apply) 92 | return self 93 | 94 | 95 | class InvalidRuleGroupException(Exception): 96 | """ 97 | Exception raised by RuleGroup if the provided configuration is invalid. 98 | """ 99 | def __init__(self, message: str): 100 | self.message = message 101 | super().__init__(message) 102 | 103 | 104 | class RuleGroup(ValidationRule): 105 | """ 106 | Allows the execution of multiple rules sequentially. 107 | 108 | :Example: 109 | 110 | >>> rules = [ 111 | >>> (TypeRule, {'valid_type': list}), 112 | >>> (MinLengthRule, {'min_length': 1}), 113 | >>> UniqueItemsRule 114 | >>> ] 115 | >>> group = RuleGroup(apply_to=countries, label='Countries', rules=rules) 116 | 117 | :param apply_to: Value against which the rule is applied (can be any type). 118 | :type apply_to: object 119 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 120 | This string will be used as the key in the ValidationResult error dictionary. 121 | :type label: str 122 | :param rules: List of rules to execute. The list can contain rule type (ie: FullStringRule, MinValueRule...) or \ 123 | tuples in the format: "(RuleClass, options)" (ie: "(MinLengthRule, {'min_length': 1})") 124 | :type rules: list 125 | :param error_message: Custom message that will be used instead of the "default_error_message". 126 | :type error_message: str 127 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 128 | is not respected, False (default) to collect all the possible errors. 129 | :type stop_if_invalid: bool 130 | """ 131 | 132 | def __init__(self, 133 | apply_to: object, 134 | label: str, 135 | rules: list, 136 | error_message: str = None, 137 | stop_if_invalid: bool = False): 138 | super().__init__(apply_to, label, error_message, stop_if_invalid) 139 | self.rules = rules 140 | self._failed_rule = None 141 | 142 | def _get_configured_rule(self, entry): 143 | rule_config = {'apply_to': self.apply_to, 'label': self.label} 144 | rule_class = entry 145 | if isinstance(entry, (list, tuple)): 146 | if len(entry) != 2 or not issubclass(entry[0], ValidationRule) or not isinstance(entry[1], dict): 147 | msg = 'Provided rule configuration does not respect the format: ' \ 148 | '(rule_class: ValidationRule, rule_config: dict)' 149 | raise InvalidRuleGroupException(msg) 150 | rule_class = entry[0] 151 | rule_config.update(entry[1]) 152 | elif entry is None or not issubclass(entry, ValidationRule): 153 | msg = 'Expected type "ValidationRule", got "{}" instead.'.format(str(entry)) 154 | raise InvalidRuleGroupException(msg) 155 | rule = rule_class(**rule_config) # type: ValidationRule 156 | return rule 157 | 158 | def get_error_message(self) -> str: 159 | if isinstance(self._failed_rule, ValidationRule): 160 | return self._failed_rule.get_error_message() 161 | return super().get_error_message() 162 | 163 | def apply(self) -> bool: 164 | for entry in self.rules: 165 | rule = self._get_configured_rule(entry) 166 | try: 167 | if not rule.apply(): 168 | self._failed_rule = rule 169 | return False 170 | except Exception: 171 | self._failed_rule = rule 172 | return False 173 | return True 174 | 175 | 176 | class ValidationResult: 177 | """ 178 | Represents a report of Validator's validate() call. 179 | 180 | :param errors: Map containing errors descriptions (if one ore more get_rules are not respected) 181 | :type errors: dict 182 | """ 183 | 184 | def __init__(self, errors: dict = None): 185 | self.errors = errors or {} 186 | 187 | def annotate_rule_violation(self, rule: ValidationRule) -> None: 188 | """ 189 | Takes note of a rule validation failure by collecting its error message. 190 | 191 | :param rule: Rule that failed validation. 192 | :type rule: ValidationRule 193 | :return: None 194 | """ 195 | if self.errors.get(rule.label) is None: 196 | self.errors[rule.label] = [] 197 | self.errors[rule.label].append(rule.get_error_message()) 198 | 199 | def annotate_exception(self, exception: Exception, rule: ValidationRule = None) -> None: 200 | """ 201 | Takes note of an exception occurred during validation. 202 | (Typically caused by an invalid attribute/key access inside get_rules() method) 203 | 204 | :param exception: Exception catched during validate() phase. 205 | :type exception: Exception 206 | :param rule: Validation rule that has generated the exception. 207 | :type rule: ValidationRule 208 | :return: None 209 | """ 210 | error_key = rule.label if isinstance(rule, ValidationRule) else 'get_rules' 211 | if self.errors.get(error_key) is None: 212 | self.errors[error_key] = [] 213 | self.errors[error_key].append(str(exception)) 214 | 215 | def is_successful(self) -> bool: 216 | """ 217 | Checks that the validation result does not contain errors. 218 | 219 | :return: True if the validation is successful, False otherwise. 220 | :rtype: bool 221 | """ 222 | return len(self.errors) == 0 223 | 224 | def __str__(self): 225 | info = {'errors': self.errors or {}} 226 | formatted_string = pprint.pformat(info) 227 | return formatted_string 228 | 229 | 230 | class ValidationException(Exception): 231 | """ 232 | Internal exception used by the library to represent a validation failure when using a Validator as a context 233 | processor. 234 | 235 | :param validation_result: Validation result returned by validator. 236 | :type validation_result: ValidationResult 237 | :param message: Error message 238 | :type message: str 239 | """ 240 | 241 | def __init__(self, validation_result: ValidationResult, message: str = 'Data did not validate.'): 242 | super().__init__(message) 243 | self.message = message 244 | self.validation_result = validation_result 245 | 246 | def __str__(self): 247 | info = {'message': self.message, 'errors': self.validation_result.errors} 248 | formatted_string = pprint.pformat(info) 249 | return formatted_string 250 | 251 | 252 | class Validator(ABC): 253 | """ 254 | Validate a data model against a list of ValidationRule(s). 255 | This class is abstract, concrete validators must inherit from Validator in order to provide a 256 | an actual implementation of get_rules(). 257 | 258 | :param data: Data model to validate (like a dict or a custom Python object instance). 259 | :type data: object 260 | """ 261 | 262 | def __init__(self, data: object): 263 | self.data = data 264 | 265 | def __enter__(self): 266 | validation = self.validate() 267 | if not validation.is_successful(): 268 | raise ValidationException(validation) 269 | return self 270 | 271 | def __exit__(self, exc_type, exc_val, exc_tb): 272 | pass 273 | 274 | @abstractmethod 275 | def get_rules(self) -> list: 276 | """ 277 | Concrete validators must implement this abstract method in order to return a list of ValidationRule(s), 278 | that will be used to validate the model. 279 | 280 | :return: ValidationRule list 281 | :rtype: list 282 | """ 283 | pass # pragma: no cover 284 | 285 | def validate(self) -> ValidationResult: 286 | """ 287 | Apply the configured ValidationRule(s) (in the given order) and return a ValidationResult object. 288 | 289 | :return: validation result 290 | :rtype: ValidationResult 291 | """ 292 | result = ValidationResult() 293 | try: 294 | for rule in self.get_rules(): 295 | try: 296 | if not rule.apply(): 297 | result.annotate_rule_violation(rule) 298 | if rule.stop_if_invalid: 299 | break 300 | except Exception as e: 301 | result.annotate_exception(e, rule) 302 | except Exception as e: 303 | result.annotate_exception(e, None) 304 | return result 305 | -------------------------------------------------------------------------------- /pyvaru/rules.py: -------------------------------------------------------------------------------- 1 | import re 2 | from datetime import datetime 3 | 4 | from pyvaru import ValidationRule 5 | 6 | __all__ = ( 7 | 'TypeRule', 8 | 'FullStringRule', 9 | 'ChoiceRule', 10 | 'MinValueRule', 11 | 'MaxValueRule', 12 | 'MinLengthRule', 13 | 'MaxLengthRule', 14 | 'RangeRule', 15 | 'IntervalRule', 16 | 'PatternRule', 17 | 'PastDateRule', 18 | 'FutureDateRule', 19 | 'UniqueItemsRule', 20 | ) 21 | 22 | DATA_ERRORS = (TypeError, IndexError, KeyError, NameError, ValueError, AttributeError) 23 | 24 | 25 | class TypeRule(ValidationRule): 26 | """ 27 | Ensure that the target value is an instance of the given type. 28 | 29 | :param apply_to: Value against which the rule is applied (can be any type). 30 | :type apply_to: object 31 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 32 | This string will be used as the key in the ValidationResult error dictionary. 33 | :type label: str 34 | :param valid_type: Valid class 35 | :type valid_type: type 36 | :param error_message: Custom message that will be used instead of the "default_error_message". 37 | :type error_message: str 38 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 39 | is not respected, False (default) to collect all the possible errors. 40 | :type stop_if_invalid: bool 41 | """ 42 | 43 | #: Default error message for the rule. 44 | default_error_message = 'Object is not an instance of the expected type.' 45 | 46 | def __init__(self, 47 | apply_to: object, 48 | label: str, 49 | valid_type: type, 50 | error_message: str = None, 51 | stop_if_invalid: bool = False): 52 | super().__init__(apply_to, label, error_message, stop_if_invalid) 53 | self.valid_type = valid_type 54 | 55 | def apply(self) -> bool: 56 | return isinstance(self.apply_to, self.valid_type) 57 | 58 | 59 | class FullStringRule(ValidationRule): 60 | """ 61 | Ensure that the target value is a non empty string object. 62 | 63 | :param apply_to: Value against which the rule is applied (can be any type). 64 | :type apply_to: object 65 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 66 | This string will be used as the key in the ValidationResult error dictionary. 67 | :type label: str 68 | :param error_message: Custom message that will be used instead of the "default_error_message". 69 | :type error_message: str 70 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 71 | is not respected, False (default) to collect all the possible errors. 72 | :type stop_if_invalid: bool 73 | """ 74 | 75 | #: Default error message for the rule. 76 | default_error_message = 'String is empty.' 77 | 78 | def __init__(self, apply_to: object, label: str, error_message: str = None, stop_if_invalid: bool = False): 79 | super().__init__(apply_to, label, error_message, stop_if_invalid) 80 | 81 | def apply(self): 82 | value = self.apply_to # type: str 83 | return isinstance(value, str) and len(value.strip()) > 0 84 | 85 | 86 | class ChoiceRule(ValidationRule): 87 | """ 88 | Ensure that the target value is contained in a provided list of possible options. 89 | 90 | :param apply_to: Value against which the rule is applied (can be any type). 91 | :type apply_to: object 92 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 93 | This string will be used as the key in the ValidationResult error dictionary. 94 | :type label: str 95 | :param choices: Available options. 96 | :type choices: tuple 97 | :param error_message: Custom message that will be used instead of the "default_error_message". 98 | :type error_message: str 99 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 100 | is not respected, False (default) to collect all the possible errors. 101 | :type stop_if_invalid: bool 102 | """ 103 | 104 | #: Default error message for the rule. 105 | default_error_message = 'Value not found in available choices.' 106 | 107 | def __init__(self, 108 | apply_to: object, 109 | label: str, 110 | choices: tuple, 111 | error_message: str = None, 112 | stop_if_invalid: bool = False): 113 | super().__init__(apply_to, label, error_message, stop_if_invalid) 114 | self.choices = choices 115 | 116 | def apply(self) -> bool: 117 | try: 118 | return self.apply_to in self.choices 119 | except DATA_ERRORS: 120 | return False 121 | 122 | 123 | class MinValueRule(ValidationRule): 124 | """ 125 | Ensure that the target value is >= than the provided reference value. 126 | 127 | :param apply_to: Value against which the rule is applied (can be any type). 128 | :type apply_to: object 129 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 130 | This string will be used as the key in the ValidationResult error dictionary. 131 | :type label: str 132 | :param min_value: Minimum value allowed. 133 | :type min_value: float 134 | :param error_message: Custom message that will be used instead of the "default_error_message". 135 | :type error_message: str 136 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 137 | is not respected, False (default) to collect all the possible errors. 138 | :type stop_if_invalid: bool 139 | """ 140 | 141 | #: Default error message for the rule. 142 | default_error_message = 'Value is smaller than expected one.' 143 | 144 | def __init__(self, 145 | apply_to: object, 146 | label: str, 147 | min_value: float, 148 | error_message: str = None, 149 | stop_if_invalid: bool = False): 150 | super().__init__(apply_to, label, error_message, stop_if_invalid) 151 | self.min_value = min_value 152 | 153 | def apply(self) -> bool: 154 | try: 155 | return self.apply_to >= self.min_value 156 | except DATA_ERRORS: 157 | return False 158 | 159 | 160 | class MaxValueRule(ValidationRule): 161 | """ 162 | Ensure that the target value is <= than the provided reference value. 163 | 164 | :param apply_to: Value against which the rule is applied (can be any type). 165 | :type apply_to: object 166 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 167 | This string will be used as the key in the ValidationResult error dictionary. 168 | :type label: str 169 | :param max_value: Maximum value allowed. 170 | :type max_value: float 171 | :param error_message: Custom message that will be used instead of the "default_error_message". 172 | :type error_message: str 173 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 174 | is not respected, False (default) to collect all the possible errors. 175 | :type stop_if_invalid: bool 176 | """ 177 | 178 | #: Default error message for the rule. 179 | default_error_message = 'Value is greater than expected one.' 180 | 181 | def __init__(self, 182 | apply_to: object, 183 | label: str, 184 | max_value: float, 185 | error_message: str = None, 186 | stop_if_invalid: bool = False): 187 | super().__init__(apply_to, label, error_message, stop_if_invalid) 188 | self.max_value = max_value 189 | 190 | def apply(self) -> bool: 191 | try: 192 | return self.apply_to <= self.max_value 193 | except DATA_ERRORS: 194 | return False 195 | 196 | 197 | class MinLengthRule(ValidationRule): 198 | """ 199 | Ensure that the target value has a length >= than the provided reference value. 200 | This rule can be applied to all python objects supporting len() (strings, lists, tuples, sets, dicts... and even 201 | custom types). 202 | 203 | :param apply_to: Value against which the rule is applied (can be any type). 204 | :type apply_to: object 205 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 206 | This string will be used as the key in the ValidationResult error dictionary. 207 | :type label: str 208 | :param min_length: Minimum length allowed. 209 | :type min_length: int 210 | :param error_message: Custom message that will be used instead of the "default_error_message". 211 | :type error_message: str 212 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 213 | is not respected, False (default) to collect all the possible errors. 214 | :type stop_if_invalid: bool 215 | """ 216 | 217 | #: Default error message for the rule. 218 | default_error_message = 'Length is smaller than expected one.' 219 | 220 | def __init__(self, 221 | apply_to: object, 222 | label: str, 223 | min_length: int, 224 | error_message: str = None, 225 | stop_if_invalid: bool = False): 226 | super().__init__(apply_to, label, error_message, stop_if_invalid) 227 | self.min_length = min_length 228 | 229 | def apply(self) -> bool: 230 | try: 231 | # noinspection PyTypeChecker 232 | return len(self.apply_to) >= self.min_length 233 | except DATA_ERRORS: 234 | return False 235 | 236 | 237 | class MaxLengthRule(ValidationRule): 238 | """ 239 | Ensure that the target value has a length <= than the provided reference value. 240 | This rule can be applied to all python objects supporting len() (strings, lists, tuples, sets, dicts... and even 241 | custom types). 242 | 243 | :param apply_to: Value against which the rule is applied (can be any type). 244 | :type apply_to: object 245 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 246 | This string will be used as the key in the ValidationResult error dictionary. 247 | :type label: str 248 | :param max_length: Maximum length allowed. 249 | :type max_length: int 250 | :param error_message: Custom message that will be used instead of the "default_error_message". 251 | :type error_message: str 252 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 253 | is not respected, False (default) to collect all the possible errors. 254 | :type stop_if_invalid: bool 255 | """ 256 | 257 | #: Default error message for the rule. 258 | default_error_message = 'Length is greater than expected one.' 259 | 260 | def __init__(self, 261 | apply_to: object, 262 | label: str, 263 | max_length: int, 264 | error_message: str = None, 265 | stop_if_invalid: bool = False): 266 | super().__init__(apply_to, label, error_message, stop_if_invalid) 267 | self.max_length = max_length 268 | 269 | def apply(self) -> bool: 270 | try: 271 | # noinspection PyTypeChecker 272 | return len(self.apply_to) <= self.max_length 273 | except DATA_ERRORS: 274 | return False 275 | 276 | 277 | class RangeRule(ValidationRule): 278 | """ 279 | Ensure that the target value is contained in the provided range. 280 | 281 | **IMPORTANT**: this rule handles python range() objects (and its "step" configuration), 282 | so does not support floats as test value 283 | (testing for a float will always fail and even for an integer if it doesn't match the step increment). 284 | 285 | For a validation like "value *BETWEEN* x *AND* y" use **IntervalRule** instead! 286 | 287 | :param apply_to: Value against which the rule is applied (can be any type). 288 | :type apply_to: object 289 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 290 | This string will be used as the key in the ValidationResult error dictionary. 291 | :type label: str 292 | :param valid_range: Allowed range. 293 | :type valid_range: range 294 | :param error_message: Custom message that will be used instead of the "default_error_message". 295 | :type error_message: str 296 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 297 | is not respected, False (default) to collect all the possible errors. 298 | :type stop_if_invalid: bool 299 | """ 300 | 301 | #: Default error message for the rule. 302 | default_error_message = 'Value is out of range.' 303 | 304 | def __init__(self, 305 | apply_to: object, 306 | label: str, 307 | valid_range: range, 308 | error_message: str = None, 309 | stop_if_invalid: bool = False): 310 | super().__init__(apply_to, label, error_message, stop_if_invalid) 311 | self.valid_range = valid_range 312 | 313 | def apply(self) -> bool: 314 | try: 315 | return self.apply_to in self.valid_range 316 | except DATA_ERRORS: 317 | return False 318 | 319 | 320 | class IntervalRule(ValidationRule): 321 | """ 322 | Ensure that the target value is contained in the provided interval. 323 | 324 | :param apply_to: Value against which the rule is applied (can be any type). 325 | :type apply_to: object 326 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 327 | This string will be used as the key in the ValidationResult error dictionary. 328 | :type label: str 329 | :param interval_from: Minimum allowed value. 330 | :type interval_from: float 331 | :param interval_to: Maximum allowed value. 332 | :type interval_to: float 333 | :param error_message: Custom message that will be used instead of the "default_error_message". 334 | :type error_message: str 335 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 336 | is not respected, False (default) to collect all the possible errors. 337 | :type stop_if_invalid: bool 338 | """ 339 | 340 | #: Default error message for the rule. 341 | default_error_message = 'Value is not in interval.' 342 | 343 | def __init__(self, 344 | apply_to: object, 345 | label: str, 346 | interval_from: float, 347 | interval_to: float, 348 | error_message: str = None, 349 | stop_if_invalid: bool = False): 350 | super().__init__(apply_to, label, error_message, stop_if_invalid) 351 | self.interval_from = interval_from 352 | self.interval_to = interval_to 353 | 354 | def apply(self) -> bool: 355 | try: 356 | return self.interval_from <= self.apply_to <= self.interval_to 357 | except DATA_ERRORS: 358 | return False 359 | 360 | 361 | class PatternRule(ValidationRule): 362 | """ 363 | Ensure that the target string respects the given pattern. 364 | 365 | :param apply_to: Value against which the rule is applied (can be any type). 366 | :type apply_to: object 367 | :param pattern: Regex used for pattern matching. 368 | :type pattern: str 369 | :param flags: Regex flags. 370 | :type flags: int 371 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 372 | This string will be used as the key in the ValidationResult error dictionary. 373 | :type label: str 374 | :param error_message: Custom message that will be used instead of the "default_error_message". 375 | :type error_message: str 376 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 377 | is not respected, False (default) to collect all the possible errors. 378 | :type stop_if_invalid: bool 379 | """ 380 | 381 | #: Default error message for the rule. 382 | default_error_message = 'Value does not match expected pattern.' 383 | 384 | def __init__(self, 385 | apply_to: object, 386 | label: str, 387 | pattern: str, 388 | flags: int = 0, 389 | error_message: str = None, 390 | stop_if_invalid: bool = False): 391 | super().__init__(apply_to, label, error_message, stop_if_invalid) 392 | self.pattern = pattern 393 | self.flags = flags 394 | 395 | def apply(self) -> bool: 396 | value = self.apply_to # type: str 397 | return isinstance(value, str) and re.match(self.pattern, value, self.flags) is not None 398 | 399 | 400 | class PastDateRule(ValidationRule): 401 | """ 402 | Ensure that the target value is a past date. 403 | 404 | :param apply_to: Value against which the rule is applied. 405 | :type apply_to: object 406 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 407 | This string will be used as the key in the ValidationResult error dictionary. 408 | :type label: str 409 | :param reference_date: Date used for time checking (default to datetime.now()). 410 | :type reference_date: datetime 411 | :param error_message: Custom message that will be used instead of the "default_error_message". 412 | :type error_message: str 413 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 414 | is not respected, False (default) to collect all the possible errors. 415 | :type stop_if_invalid: bool 416 | """ 417 | 418 | #: Default error message for the rule. 419 | default_error_message = 'Not a past date.' 420 | 421 | def __init__(self, 422 | apply_to: object, 423 | label: str, 424 | reference_date: datetime = None, 425 | error_message: str = None, 426 | stop_if_invalid: bool = False): 427 | super().__init__(apply_to, label, error_message, stop_if_invalid) 428 | self.reference_date = reference_date or datetime.now() 429 | 430 | def apply(self) -> bool: 431 | try: 432 | return isinstance(self.apply_to, datetime) and self.apply_to < self.reference_date 433 | except DATA_ERRORS: 434 | return False 435 | 436 | 437 | class FutureDateRule(ValidationRule): 438 | """ 439 | Ensure that the target value is a future date. 440 | 441 | :param apply_to: Value against which the rule is applied. 442 | :type apply_to: object 443 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 444 | This string will be used as the key in the ValidationResult error dictionary. 445 | :type label: str 446 | :param reference_date: Date used for time checking (default to datetime.now()). 447 | :type reference_date: datetime 448 | :param error_message: Custom message that will be used instead of the "default_error_message". 449 | :type error_message: str 450 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 451 | is not respected, False (default) to collect all the possible errors. 452 | :type stop_if_invalid: bool 453 | """ 454 | 455 | #: Default error message for the rule. 456 | default_error_message = 'Not a future date.' 457 | 458 | def __init__(self, 459 | apply_to: object, 460 | label: str, 461 | reference_date: datetime = None, 462 | error_message: str = None, 463 | stop_if_invalid: bool = False): 464 | super().__init__(apply_to, label, error_message, stop_if_invalid) 465 | self.reference_date = reference_date or datetime.now() 466 | 467 | def apply(self) -> bool: 468 | try: 469 | return isinstance(self.apply_to, datetime) and self.apply_to > self.reference_date 470 | except DATA_ERRORS: 471 | return False 472 | 473 | 474 | class UniqueItemsRule(ValidationRule): 475 | """ 476 | Ensure that the target list (or iterable) does not contain duplicated items. 477 | 478 | :param apply_to: Value against which the rule is applied (can be any type). 479 | :type apply_to: object 480 | :param label: Short string describing the field that will be validated (e.g. "phone number", "user name"...). \ 481 | This string will be used as the key in the ValidationResult error dictionary. 482 | :type label: str 483 | :param error_message: Custom message that will be used instead of the "default_error_message". 484 | :type error_message: str 485 | :param stop_if_invalid: True to prevent Validator from processing the rest of the get_rules if the current one \ 486 | is not respected, False (default) to collect all the possible errors. 487 | :type stop_if_invalid: bool 488 | """ 489 | 490 | #: Default error message for the rule. 491 | default_error_message = 'List contains duplicated items.' 492 | 493 | def __init__(self, apply_to: object, label: str, error_message: str = None, stop_if_invalid: bool = False): 494 | super().__init__(apply_to, label, error_message, stop_if_invalid) 495 | 496 | def _dictionary_items_are_unique(self): 497 | data = self.apply_to # type: dict 498 | values = list(data.values()) 499 | if len(values) > 1: 500 | index = 1 501 | while index < len(values): 502 | if values[index - 1] == values[index]: 503 | return False 504 | index += 1 505 | return True 506 | 507 | def _collection_items_are_unique(self): 508 | # noinspection PyTypeChecker 509 | return len(set(self.apply_to)) == len(self.apply_to) 510 | 511 | def apply(self) -> bool: 512 | try: 513 | if isinstance(self.apply_to, dict): 514 | return self._dictionary_items_are_unique() 515 | if isinstance(self.apply_to, set): 516 | return True 517 | return self._collection_items_are_unique() 518 | except DATA_ERRORS: 519 | return False 520 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | with open('README.rst', 'r') as readme: 4 | long_description = readme.read() 5 | 6 | setup( 7 | name='pyvaru', 8 | version='0.3.0', 9 | description='Rule based data validation library for python.', 10 | long_description=long_description, 11 | author='Davide Zanotti', 12 | author_email='davidezanotti@gmail.com', 13 | license='MIT', 14 | url='https://github.com/daveoncode/pyvaru', 15 | classifiers=[ 16 | # How mature is this project? Common values are 17 | # 3 - Alpha 18 | # 4 - Beta 19 | # 5 - Production/Stable 20 | 'Development Status :: 5 - Production/Stable', 21 | 22 | # Indicate who your project is intended for 23 | 'Intended Audience :: Developers', 24 | 'Topic :: Software Development :: Libraries', 25 | 26 | # Pick your license as you wish (should match "license" above) 27 | 'License :: OSI Approved :: MIT License', 28 | 29 | # Specify the Python versions you support here. In particular, ensure 30 | # that you indicate whether you support Python 2, Python 3 or both. 31 | 'Programming Language :: Python :: 3.2', 32 | 'Programming Language :: Python :: 3.3', 33 | 'Programming Language :: Python :: 3.4', 34 | 'Programming Language :: Python :: 3.5', 35 | 'Programming Language :: Python :: 3.6', 36 | ], 37 | keywords='validation rule model data', 38 | packages=['pyvaru'], 39 | data_files=[('README.rst', ['README.rst'])], 40 | ) 41 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py34, py35, py36 3 | 4 | [testenv] 5 | commands = python tests.py --------------------------------------------------------------------------------