xia_fields_network.fields.IpV6Field
- class xia_fields_network.fields.IpV6Field(description='Ip Address field', sample='2404:6800:4003:c02::8a', regex='(?:^|(?<=\\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=\\s|$)', **kwargs)
Bases:
StringField
IP address (v6) field
- __init__(description='Ip Address field', sample='2404:6800:4003:c02::8a', regex='(?:^|(?<=\\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=\\s|$)', **kwargs)
- Parameters
regex (str) – String pattern
max_length (int) – A max length that will be applied during validation
min_length (int) – A min length that will be applied during validation
**kwargs – Keyword arguments passed into the parent class
Methods
__init__
([description, sample, regex])- param regex
String pattern
Estimate Max length of the string
from_db
(value, /[, decoder, engine])Value transformation from database form
from_display
(value[, runtime_display])Value transformation from display form to internal form
from_runtime
(runtime_value, /)Value transformation from runtime value to internal form
Get a sample value of a field
get_value
([value, runtime_value])Get runtime value when it is necessary
guess_value
([value])Guess field value
to_db
(value[, runtime_value, catalog, ...])Value transformation to database form
to_display
(value[, runtime_value])Value transformation to display form
validate
(value[, runtime_value])Validate data
Attributes
SAMPLE_DICT
detail_form
runtime_form
- db_form
alias of
str
- display_form
alias of
str
- estimate_max_length() int
Estimate Max length of the string
- Returns
Max string length
- from_db(value: Any, /, decoder: callable = None, engine=None)
Value transformation from database form
- Parameters
decoder (callable) – Encode the value
value (any) – value to be transformed from database form to internal form
engine (BaseEngine) – Engine to be passed
- Returns
internal value and runtime value tuple
- from_display(value: Any, runtime_display: Any = None, /)
Value transformation from display form to internal form
- Parameters
value (any) – display value to be transformed
runtime_display (any) – display runtime value to be transformed
- from_runtime(runtime_value: Any, /)
Value transformation from runtime value to internal form
- Parameters
runtime_value – runtime value
- get_sample()
Get a sample value of a field
- Returns
sample value
- Return type
object
- get_value(value: Any = None, runtime_value: Any = None, /, **kwargs)
Get runtime value when it is necessary
- Parameters
value (any) – value on internal form. could be None for no-stateful fields
runtime_value (any) – value of runtime value. could be None when the data is not loaded
- guess_value(value: Optional[Any] = None)
Guess field value
- Guess field value is normally called when parsing front. The general rules are:
- If the fields is type runtime
Check if the input is type of runtime or detail form
When true, the output guess will be a tuple contain internal form, runtime form
- Or the check will continue to see if it is display form or db_form
When found, it will return internal form
When field is runtime type, will return internal from, None (lazy load mode)
- Parameters
value – value to be guessed
Notes
The default priority
- internal_form
alias of
str
- to_db(value: Any, runtime_value: Any = None, /, catalog: dict = None, encoder: callable = None, ignore_unknown: bool = False, engine=None)
Value transformation to database form
- Parameters
encoder (callable) – Encode the value
runtime_value (any) – runtime value to be transformed
value (any) – value to be transformed from internal form to database form
catalog (dict) – Data catalog to decide if the field will be shown or not
ignore_unknown (bool) – If the unknown field should be ignored
engine (BaseEngine) – Engine to be passed
- to_display(value: Any, runtime_value: Any = None, /, **kwargs)
Value transformation to display form
- Parameters
value (any) – value to be transformed from internal form to database form
runtime_value (any) – value of runtime value. could be None when the data is not loaded
- validate(value: Any, runtime_value: Any = None, /)
Validate data
- Parameters
value (any) – internal value to be validated
runtime_value (any) – runtime data to be validated
Notes
No exception raised = validation passed