References
Module stricto. export all classes
- class stricto.GenericType(**kwargs)
Bases:
objectGeneric Type
This is the main Object for Int, Float, String, …
- Parameters:
kwargs (object) – arguments as kwargs for the string format
constraint (Callable) – a function to check if the value is admissible
constraints (list[ Callable ]) – a list of function to check if the value is admissible
default (Any | Callable) – A default value or function
description (str) – a description of this field (like a comment)
exists (bool|Callable) – answer if this field exists or not
in (list[ Any ]) – a list of available values
require (bool|Callable) – if this field cannot be None
onChange (Callable) – A function to trig when the value change
set (Callable) – a compute value
transform (Callable) – a function to modify the value BEFORE affectation
view (list[ str ]) – list of views Access-list
- am_i_root() bool
Check if this object is the root object
- Parameters:
self – Description
- Returns:
Description
- Return type:
bool
- can_modify() bool
check right “modify”
- can_read() bool
check right “read”
- check(value: Any) None
check if the value complain to model. Throw an Error if Not
- Parameters:
self – Description
value (Any) – the value to check
- Raises:
SRightError – cannot read (and modify) value
SConstraintError – in case of constraints not validated
- check_type(value: Any) None
Check if the type is correct. must be overwritten
- check_value() None
Check of the value is compliant to type and contraints or throw an error
- compute_value() bool
compute the value if needed
if the value is with set= … compute the value and return True or False if there is any changement.
- Returns:
True if changed
- Return type:
bool
- copy() Self
wrapper for
copy.copy- Parameters:
self – Description
- Returns:
a new
GenericTypewith is the copy of this object- Return type:
Self
- disable_permissions() None
set permissions to off
- enable_permissions() None
set permissions to on
- end_record() bool
The process of update is OK. close the process and return True or False if there is any changement.
- Returns:
True if changed
- Return type:
bool
- exists(value: Any) bool
Return True if the object Exist, othewise False. exist can be a function to make this field dependant from the value of another
- Parameters:
self – Description
value (str) – don’t remember
- Returns:
if this object exists
- Return type:
bool
- exists_or_can_read() bool
check first if the object exists. Then check if can be read. return True otherwise False
- Parameters:
self – Description
- Returns:
if the object exost and can be read
- Return type:
bool
- get_childs() list[Self]
Return the list of child of this object
- Returns:
the list of child of this object
- Return type:
list[GenericType]
- get_current_meta(parent: dict = None) dict
Return a schema with all rights correctly set depending on fonctions
- Parameters:
self – Description
parent (dict) – Not used
- Returns:
return: the schema as a json object (dict)
- Raises:
SSyntaxError – this function must be called at root only
- Return type:
dict
- get_encoded() str
Return the encoded value
- Returns:
the value as a encoded for json
- Return type:
str
- get_root() Self
Return the root object
- Parameters:
self – Description
- Returns:
The root object
- Return type:
- get_schema() dict
Return a schema for this object
- Parameters:
self – Description
- Returns:
the schema as a json object (dict)
- Return type:
dict
Return a schema for this object
- get_value() Any
return the value in this object
- Parameters:
self – Description
- Returns:
The value
- Return type:
Any
- get_view(view_name: str, final: bool = True) Any
Return all elements belonging to view_name The result is a subset of this object
- Parameters:
self – Description
view_name (str) – the named view
final (not used) – Description
- Returns:
Description
- Return type:
Any
- Examples:
+view1- Want all fields with “view1”view1- Want all fields except thoses with “!view1”
- is_allowed_to(right_name: str) bool
check the right “right_name”
- Parameters:
self – Description
right_name (str) – the name of the right to check
- Returns:
True if have right, or False
- Return type:
bool
- is_none() bool
Return True if the value is None used differently when it is a dict, List or Tuple
- Returns:
True if the value is None
- Return type:
bool
- match(other)
Check if equality
- multi_select(selector_as_list_of_string: list[str]) list[Self] | None
selectors: a list of selector
- Parameters:
self – Description
selector_as_list_of_string (list[str]) – selectors
- Returns:
a list of objects
- Return type:
list[Self] | None
- Example:
[ "$.name", "$.address.town" ]
- patch(op: str, selector: str, value=None) None
patch is modifying a value. see https://datatracker.ietf.org/doc/html/rfc6902
- Parameters:
self – Description
op (str) – Descthe operator
selector (str) – the path to find and modify
value – Description
- Raises:
STypeError – in case of invalid operator
SAttributeError – if the selector is not found
- path_name() str
return a string with the name of the object according to RFC 9535 (https://datatracker.ietf.org/doc/rfc9535/)
- Parameters:
self – Description
- Returns:
the path string
- Return type:
str
- rollback() None
reset to the old value
- Parameters:
self – Description
- select(selector_as_string: str) Self | None
Get values with selector acording to rfc 9535 (https://datatracker.ietf.org/doc/rfc9535/)
- Parameters:
self – Description
selector_as_string (str) – the rfc 9535
- Returns:
The object matched.
- Return type:
Self | None
- Example:
$.address.street$.surname[0]
- set(value: Any) None
Set the new value
This function set the new value, recompute any other value of the object, check contraints or throw errors, trigg events…
- Parameters:
value (Any) – the new value
- Raises:
e – Exception in any cases or error
- set_default_value() bool
Set the default value from the default= and return True or False if there is any changement.
- Returns:
True if changed
- Return type:
bool
- set_value(value: Any) bool
Set the value without any test or verification, and return True or False if there is any changement.
do the transform function
set the value
- Parameters:
value (Anu) – the new value
- Returns:
True if has changed
- Return type:
bool
- start_record() None
Record the value in case of Rollback
used in case of Error in the process
- trigg(event_name: str, **kwargs) None
Trigg an event
- Parameters:
event_name (str) – _description_
src_object (GenericType | None) – the from object
- class stricto.Bool(**kwargs)
Bases:
GenericTypeBoolean type
- Parameters:
**kwargs – See
GenericType
Constructor method
- class stricto.Dict(schema: dict, **kwargs)
Bases:
GenericTypeDict Object
- Parameters:
schema (dict) – the description of the Dict (its keys)
Dict object
- Parameters:
schema (dict) – the description of the Dict (its keys)
- Raises:
SSyntaxError – If some error
- add_to_model(key: str, model) None
add new element to the model
- check_type(value)
check if conplain to model or raise an
- check_value() None
Check of the value is compliant to contraints or throw an error
- compute_value() bool
compute the value if needed
- Returns:
True if changed
- Return type:
bool
- disable_permissions()
set permissions to off
- enable_permissions()
set permissions to on
- end_record() bool
The process of update is OK :return: True if changed :rtype: bool
- get(key: str, default=None)
return the value of a key
- get_childs() list[Self]
Return the list of child of this object
- Returns:
the list of child of this object
- Return type:
list[GenericType]
- get_current_meta(parent: dict = None)
Return a schema for this object
- get_encoded() dict
Return the encoded value
- Returns:
the value as a encoded for json
- Return type:
dict
- get_old_value()
Return the previous version of values
- get_selectors(index_or_slice, sel: Selector)
get with selector as lists selectors_as_list is a list of tuples like ( “a” , 0 ) -> a[0] ( “toto”, None ) -> toto
- get_value()
return the value
- get_view(view_name, final=True)
Return all elements belonging to view_name tue return is a subset of this Dict
- is_none() bool
Return True if the value is None used differently when it is a dict, List or Tuple
- Returns:
True if the value is None
- Return type:
bool
- keys()
return all keys
- match(other: dict) bool
Check if equality with an object example : me : { a : 12, b : 13, c : 14 } match { b : 13 } -> True match { a : 11 } -> False match { a : 12, c : 14 } -> True
- remove_model(key: str) None
remove a key Model to the model
- rollback()
reset to the old value
- set_default_value() bool
Set the default value
from the default= function or direct value
- Returns:
True if changed
- Return type:
bool
- set_value(value: Any) bool
Set hardly the value
do the transform function
check the type
set the value
- Returns:
True if has changed
- Return type:
bool
- start_record() None
Record the value in case of Rollback overwrite GenericType.start_record
- class stricto.Extend(type_for_extend, **kwargs)
Bases:
GenericTypeA Extent type for any types type
available arguments
- check_type(value)
Check if the type is correct. must be overwritten
- class stricto.Float(**kwargs)
Bases:
GenericTypeFloat type
- Parameters:
**kwargs – See
GenericType- Specifics Arguments:
min (
float) – a minimal valuemax (
float) – a maximal value
Constructor method
- check_type(value: Any) None
- class stricto.Int(**kwargs)
Bases:
GenericTypeA Int type
available arguments
min : minimal value max : maximal value
- check_type(value)
Check if the type is correct. must be overwritten
- class stricto.List(class_type: GenericType, **kwargs)
Bases:
ListAndTupleA Dict Type
initialisation, set class_type and some parameters
- append(value)
Do a List.append(value) like list.append(value)
- check_type(value)
check if conplain to model or return a error string
- clear()
Do List.clear() as list.clear() (with checks)
- duplicate_in_list()
Copy the list self._value to another list used to check() on this list before modification
- extend(second_list)
Do a List.extend(second_list) like list.extend(second_list)
- get_current_meta(parent: dict = None)
Return a schema for this object
- get_encoded() list
Return the encoded value
- Returns:
the value as a encoded for json
- Return type:
list
- get_selectors(index_or_slice: str, sel: Selector)
get with selector as lists
- get_value()
@overwrite GenericType.get_value()
- insert(key, value)
Do a list.insert()
- match(other)
Check if equality with an object example : me : [ 12, 13, 14 ] match [ 12 ] -> False match [ 12, 13 ] -> False match [ 12, 13, 14 ] -> True
- patch_internal(op: str, value)
patch is modifying a value. equivalent to set for a generic https://datatracker.ietf.org/doc/html/rfc6902
if op == remove , the value is the key index to remove
- pop(key=-1)
Do a List.pop() like list.pop()
- remove(value)
Do a List.remove(value) like list.remove(value)
- reset_attribute_name()
the list is reordonned (added, supression, …) the attribute name must be reset
- sort(**kwarg)
Do a sort(List) like sort(list)
- class stricto.String(**kwargs)
Bases:
GenericTypeA generic type (class for int, string, etc)
A string
regexp=pattern=patterns : A (list of) regular expression to match
- check_type(value)
Check if the type is correct. must be overwritten
- class stricto.Tuple(schema: tuple, **kwargs)
Bases:
ListAndTupleA Tuple Type
- check_type(value)
check if conplain to model or raise an
- get_current_meta(parent: dict = None)
Return a schema for this object
- get_encoded() list
Return the encoded value
- Returns:
the value as a encoded for json
- Return type:
list
- get_selectors(index_or_slice, sel: Selector)
get with selector in tuple
- get_value()
get the value
- match(other)
Check if equality with an object