JSON dictionary variable checks
Project description
Bravo! You have received a Mercantilism Diploma in "law_dictionary" from
the Orbital Convergence University International Air and Water
Embassy of the Tangerine Planet 🍊 (the planet that is one ellipse further from
the Sun than Earth's ellipse).
You are now officially certified to include "law_dictionary" in your practice!
Encore! Encore! Encore! Encore!
law_dictionary
description
This module checks that dictionaries provided are legit.
install
[xonsh] pip install law_dictionary
tutorial
The "dictionary" passed to the "check" function might be modified.
Therefore dictionary_2 = copy.deepcopy (dictionary_1)
should be used
if you'd like the original dictionary_1
to be preserved.
101
In this example, an obstacle is found because "directory_2" is not in the "laws"
and "allow_extra_fields" is False.
With "return_obstacle_if_not_legit" a report is returned instead of an exception
being raised.
import law_dictionary
dictionary = {
"directory_1": "/",
"directory_2": "/drives"
}
report = law_dictionary.check (
return_obstacle_if_not_legit = True,
allow_extra_fields = False,
laws = {
"directory_1": {
"required": True
}
},
dictionary = dictionary
)
if (report ["advance"] != True):
raise Exception (report ["obstacle"])
contigencies
If "required" is False, then the "contingency" value is returned or the value returned by a "contingency" function.
After "contingency" step, the "type" is checked, if "type" is passed to the "laws".
import law_dictionary
dictionary = {}
def retrieve_directory ():
return "/"
report = law_dictionary.check (
return_obstacle_if_not_legit = True,
laws = {
"directory_1": {
"required": False,
"contingency": retrieve_directory,
"type": str
},
"directory_2": {
"required": False,
"contingency": "/drives",
"type": str
}
},
dictionary = dictionary
)
if (report ["advance"] != True):
raise Exception (report ["obstacle"])
assert (dictionary ["directory_1"] == "/")
assert (dictionary ["directory_2"] == "/drives")
# The consequence of this check is that there are no "obstacles"
# and the dictionary is modified to have this structure:
'''
{
"directory_1": "/",
"directory_2": "/drives"
}
'''
allowance
The consequence of this check is that there are no "obstacles" or modifications to either dictionary.
import law_dictionary
dictionaries = [{ "directory_1": "/" }, { "directory_1": "/drives" }]
for dictionary in dictionaries:
law_dictionary.check (
laws = {
"directory_1": {
"required": True,
"allow": [ "/", "/drives" ]
}
},
dictionary = dictionary
)
multiple levels
There's not a tree structure possible for multiple levels,
however after a level 1 check, level 2, etc. checks can
be run.
import law_dictionary
dictionary = {
"paths": {
"directory_1": "/"
}
}
law_dictionary.check (
laws = {
"paths": {
"required": True,
"type": dict
}
},
dictionary = dictionary
)
law_dictionary.check (
laws = {
"directory_1": {
"required": True,
"type": str
}
},
dictionary = dictionary ["paths"]
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file law_dictionary-1.0.12.tar.gz
.
File metadata
- Download URL: law_dictionary-1.0.12.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-27-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7018d3483dc818c8c0a40852cbecc17a8c43d3481f0b540fb394bc3990763b1f |
|
MD5 | af022d89f964db6805a0c261639eeeb2 |
|
BLAKE2b-256 | cbca345b5b09ad2a9e915612f665388b1af2ee5c2b98bed95f5d9826dc328422 |
File details
Details for the file law_dictionary-1.0.12-py3-none-any.whl
.
File metadata
- Download URL: law_dictionary-1.0.12-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-27-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d58557e3196ae3151177bea9f5a3a4b707edca4905964eb80f211d00e0a078a |
|
MD5 | 4c6c390a6d6b20e390c661386956d0a1 |
|
BLAKE2b-256 | 5593a3f471fe5cb8a96ec3dacc4ffc91483f73b55f9962b778bcf6bc04880145 |