Viewing File: /opt/alt/python38/lib/python3.8/site-packages/cerberus/__pycache__/schema.cpython-38.opt-1.pyc

U

`G@sddlmZddlmZddlmZddlmZmZm	Z	m
Z
mZmZddl
mZmZmZmZGdddeZGdd	d	eZGd
ddeZGdd
d
eZGdddeZGdddeZGdddeZGdddeZGdddeZeeZZdS))absolute_import)warn)errors)	_str_typeCallableHashableMappingMutableMappingSequence)get_Validator_classvalidator_factorymapping_hashTypeDefinitionc@seZdZdS)_AbortN)__name__
__module____qualname__rr@/opt/alt/python38/lib/python3.8/site-packages/cerberus/schema.pyrsrc@seZdZdZdS)SchemaErrorz_
    Raised when the validation schema is missing, has the wrong format or contains
    errors.N)rrr__doc__rrrrrsrcseZdZdZfddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
eddZeddZeddZd+ddZdd Zd!d"Zed#d$Zd%d&Zd,d'd(Zd)d*ZZS)-DefinitionSchemaz1A dict-subclass for caching of validated schemas.csXdtkrHtdtatj}|tdtfdtdt	fdd|t_t
t||S)NSchemaValidatorcallablerhashable)rr)
globalsrSchemaValidatorMixinr
types_mappingcopyupdaterrrsuperr__new__)clsargskwargsr	__class__rrr!%s


zDefinitionSchema.__new__cCst|tstd||_t|tr2|j||}t|tsnzt|}Wn$t	k
rlt
tj
|YnXt||_td|jtj||d|_||}||||_dS)z
        :param validator: An instance of Validator-(sub-)class that uses this
                          schema.
        :param schema: A definition-schema as ``dict``. Defaults to an empty
                       one.
        z0validator argument must be a Validator-instance.N)
allow_unknownZ
error_handler
target_schematarget_validator)
isinstancerRuntimeError	validatorrschema_registrygetrdict	ExceptionrrSCHEMA_ERROR_DEFINITION_TYPEformatSchemaValidationSchemavalidation_schemarZSchemaErrorHandlerschema_validatorexpandvalidateschema)selfr,r8rrr__init__4s*




zDefinitionSchema.__init__c
Csf|j}z
||=WnDtk
r4td|Yn.tk
rX}z|W5d}~XYn
X|j|=dS)Nz Schema has no field '%s' defined)r8r
ValueErrorrr0)r9key_new_schemaerrr__delitem__Us

zDefinitionSchema.__delitem__cCs
|j|SN)r8)r9itemrrr__getitem__`szDefinitionSchema.__getitem__cCs
t|jSr@)iterr8r9rrr__iter__cszDefinitionSchema.__iter__cCs
t|jSr@)lenr8rDrrr__len__fszDefinitionSchema.__len__cCst|Sr@)strrDrrr__repr__iszDefinitionSchema.__repr__cCs.|d|id}|||i||j|<dSNr)r6r7r8)r9r<valuerrr__setitem__lszDefinitionSchema.__setitem__cCst|drt|jSdSdS)Nr8zNo schema data is set yet.)hasattrrHr8rDrrr__str__qs

zDefinitionSchema.__str__cCs||j|jSr@)r&r,r8rrDrrrrwszDefinitionSchema.copycCs<z||}||}Wntk
r,YnX||}|Sr@)_expand_logical_shortcuts_expand_subschemasr0_rename_deprecated_rulenames)r"r8rrrr6zs

zDefinitionSchema.expandcszdd|D]d\}}fdd|DD]H}|dd\}}||gi||D]}||||iqT||=q*q|S)z
        Expand agglutinated rules in a definition-schema.

        :param schema: The schema-definition to expand.
        :return: The expanded schema-definition.
        cSst|to|dS)N)Zallof_Zanyof_Znoneof_Zoneof_)r*r
startswith)xrrr
is_of_rulesz>DefinitionSchema._expand_logical_shortcuts.<locals>.is_of_rulecsg|]}|r|qSrr.0rSrTrr
<listcomp>sz>DefinitionSchema._expand_logical_shortcuts.<locals>.<listcomp>_)itemssplitrappend)r"r8fieldrulesZof_ruleoperatorrulerKrrWrrOs	
z*DefinitionSchema._expand_logical_shortcutsc	sfdd}fdd}D]|s,nD|rN|dd<n"|ddidd<dD]2}|krt|d|id|<qtdD]^}|krt|tsqg}|D]}||d|idq||<qq S)	NcsttodkS)Nr8r*rrr^r8rrhas_schema_rulesz<DefinitionSchema._expand_subschemas.<locals>.has_schema_rulecs<z tdddDWStk
r6YdSXdS)zw
            Tries to determine heuristically if the schema-constraints are aimed to
            mappings.
            css|]}t|tVqdSr@rbrUrrr	<genexpr>szRDefinitionSchema._expand_subschemas.<locals>.has_mapping_schema.<locals>.<genexpr>r8FN)allvalues	TypeErrorrrcrrhas_mapping_schemas
z?DefinitionSchema._expand_subschemas.<locals>.has_mapping_schemar8r)	keysrulesvaluesrules	keyschemavalueschema)ZallofZanyofr[ZnoneofZoneof)r6r*r
r])r"r8rdriraZnew_rules_definitionrArrcrrPs("$z#DefinitionSchema._expand_subschemasNcCs|j||Sr@)r8r.)r9rAdefaultrrrr.szDefinitionSchema.getcCs
|jSr@)r8r[rDrrrr[szDefinitionSchema.itemsc
Csz,||}|j}||||WnHtk
rPttj	|Yn,t
k
rt}z|W5d}~XYnX||_dSr@)r6r8rrr7r;rrr1r2r0)r9r8r=r>rrrrs


zDefinitionSchema.updatecCs|D]r\}}t|trqdD]X\}}||kr2q ||krBtdtdj||dt||||||<|||q q|S)N))rlrj)r,Z
check_with)rmrkzTThe rule '{new}' is also present with its old name '{old}' in the same set of rules.zrThe rule '{old}' was renamed to '{new}'. The old name will not be available in the next major release of Cerberus.)oldnew)r[r*rHr+rr2DeprecationWarningpop)r8r^r_rorprrrrQs(
z-DefinitionSchema._rename_deprecated_rulenamescCst|j|_dSr@)r3r,r4rDrrrregenerate_validation_schemasz-DefinitionSchema.regenerate_validation_schemacCsJ|dkr|j}t|t|jjf}||jjkrF|||jj|dS)ap
        Validates a schema that defines rules against supported rules.

        :param schema: The schema to be validated as a legal cerberus schema
                       according to the rules of the assigned Validator object.
                       Raises a :class:`~cerberus.base.SchemaError` when an invalid
                       schema is encountered.
        N)r8r
r,r_valid_schemas	_validateadd)r9r8_hashrrrr7s	
zDefinitionSchema.validatecCst|tr|jj||}i}|D]R\}}t|trJt||||<q&i}|D]\}}|||dd<qV|||<q&|j|ddst	|jj
dS)N rYFZ	normalize)r*rr,r-r.r[rules_set_registryreplacer5rr)r9r8Ztest_schemar^r_Z
test_rulesraZ
constraintrrrrus


zDefinitionSchema._validate)N)N)rrrrr!r:r?rBrErGrIrLrNrclassmethodr6rOrPr.r[rstaticmethodrQrsr7ru
__classcell__rrr%rr"s2!


'

 
rc@s(eZdZifddZddZddZdS)UnvalidatedSchemacCst|tst|}||_dSr@)r*rr/r8r9r8rrrr:!s
zUnvalidatedSchema.__init__cCsdSr@rrrrrr7&szUnvalidatedSchema.validatecCs||jSr@)r&r8rrDrrrr)szUnvalidatedSchema.copyN)rrrr:r7rrrrrr src@seZdZddZdS)r3cCsd|jdd|_dS)NFr/)r'r8type)r_r8)r9r,rrrr:0szSchemaValidationSchema.__init__N)rrrr:rrrrr3/sr3cseZdZdZfddZeddZeddZedd	Zed
dZ	dd
Z
ddZddZddZ
ddZddZddZddZZS)rzi
    This validator mixin provides mechanics to validate schemas passed to a Cerberus
    validator.
    cs2|dt|dttt|j||dS)Nknown_rules_set_refsknown_schema_refs)
setdefaultsetr rr:)r9r#r$r%rrr:>szSchemaValidatorMixin.__init__cCs
|jdS)z7The encountered references to rules set registry items.rZ_configrDrrrrCsz)SchemaValidatorMixin.known_rules_set_refscCs
|jdS)z4The encountered references to schema registry items.rrrDrrrrHsz&SchemaValidatorMixin.known_schema_refscCs
|jdS)z#The schema that is being validated.r(rrDrrrr(Msz"SchemaValidatorMixin.target_schemacCs
|jdS)z.The validator whose schema is being validated.r)rrDrrrr)Rsz%SchemaValidatorMixin.target_validatorcCst|trR||jkrdS|j||jj|}|dkrN||d|dS|}td|it|jj	f}||jj
krzdS|j|d|jjd}||dd|j
r||j
n|jj
|dS)Nz"Rules set definition %s not found.turingFdocument_crumbr'r8ry)r*rrrvr)rzr._errorr
rrt_get_child_validatorr__errors)r9r^rK
definitionrwr,rrr_check_with_bulk_schemaWs.



z,SchemaValidatorMixin._check_with_bulk_schemacCst|trnpt|trH|j|dddiidd}||dds|||jn4t|tr|tdd	|Ds||j|f}||d
dS)NrkrlistTrr8r'Frycss|]}t|tVqdSr@)r*rrUrrrresz@SchemaValidatorMixin._check_with_dependencies.<locals>.<genexpr>z)All dependencies must be a hashable type.)	r*rrrrrr
rf
document_path)r9r^rKr,pathrrr_check_with_dependenciesws



z-SchemaValidatorMixin._check_with_dependenciescCs&t|D]\}}|||f|qdSr@)	enumerater)r9r^rKir8rrr_check_with_itemssz&SchemaValidatorMixin._check_with_itemscCsz|||}Wntk
r&YdSXt|t|jjf}||jjkrLdS|j|d|jd}|||dd|j	r|
|j	n|jj|dS)NrFry)&_handle_schema_reference_for_validatorrr
r)rrtrZroot_allow_unknown_expand_rules_set_refsrrrv)r9r^rKrwr,rrr_check_with_schemas z'SchemaValidatorMixin._check_with_schemacCsLt|trt|fnt|}|t|jj}|rH||dd|dS)NzUnsupported types: {}z, )r*rrr)typesrr2join)r9r^rKZinvalid_constraintsrrr_check_with_typesz%SchemaValidatorMixin._check_with_typecCs@i}|D].\}}t|tr2|jj|||<q|||<q|Sr@)r[r*rr)rzr.)r9r8resultkvrrrrs

z+SchemaValidatorMixin._expand_rules_set_refscCsdt|ts|S||jkrt|j||jj|}|dkr`|j|f}|	|d
|t|S)NzSchema definition {} not found.)r*rrrrvr)r-r.rrr2)r9r^rKrrrrrrs

z;SchemaValidatorMixin._handle_schema_reference_for_validatorcCst|ts||tjdS|j|d|jjd}|D]X}td|it|jj	f}||jj
kr^q4||dd|jr~||jq4|jj
|q4dS)z2{'allowed': ('allof', 'anyof', 'noneof', 'oneof')}NFrrry)
r*r
rrZBAD_TYPErr)Zvalidation_rulesr
rrtrrv)r9rar^rKr,Zconstraintsrwrrr_validate_logicals$


z&SchemaValidatorMixin._validate_logical)rrrrr:propertyrrr(r)rrrrrrrrr~rrr%rr8s$



 	rc@sNeZdZdZifddZddZddZdd	Zd
dZdd
dZ	ddZ
dS)Registryz
    A registry to store and retrieve schemas and parts of it by a name that can be used
    in validation schemas.

    :param definitions: Optional, initial definitions.
    :type definitions: any :term:`mapping`
    cCsi|_||dSr@)_storageextend)r9definitionsrrrr:szRegistry.__init__cCs|||j|<dS)aQ
        Register a definition to the registry. Existing definitions are replaced
        silently.

        :param name: The name which can be used as reference in a validation
                     schema.
        :type name: :class:`str`
        :param definition: The definition.
        :type definition: any :term:`mapping`
        N)_expand_definitionr)r9namerrrrrvszRegistry.addcCs|jS)z_
        Returns a :class:`dict` with all registered definitions mapped to their name.
        )rrDrrrrfszRegistry.allcCs|jdS)z&Purge all definitions in the registry.N)rclearrDrrrrszRegistry.clearcCs&t|D]\}}|||qdS)a
        Add several definitions at once. Existing definitions are
        replaced silently.

        :param definitions: The names and definitions.
        :type definitions: a :term:`mapping` or an :term:`iterable` with
                           two-value :class:`tuple` s
        N)r/r[rv)r9rrrrrrrs	zRegistry.extendNcCs|j||S)z
        Retrieve a definition from the registry.

        :param name: The reference that points to the definition.
        :type name: :class:`str`
        :param default: Return value if the reference isn't registered.
        )rr.)r9rrnrrrr.szRegistry.getcGs|D]}|j|dqdS)z
        Unregister definitions from the registry.

        :param names: The names of the definitions that are to be
                      unregistered.
        N)rrr)r9namesrrrrremoveszRegistry.remove)N)rrrrr:rvrfrrr.rrrrrrs


rc@seZdZeddZdS)SchemaRegistrycCs
t|Sr@rr6r"rrrrr!sz!SchemaRegistry._expand_definitionNrrrr|rrrrrr src@seZdZeddZdS)RulesSetRegistrycCstd|idSrJrrrrrr'sz#RulesSetRegistry._expand_definitionNrrrrrr&srN)Z
__future__rwarningsrZcerberusrZcerberus.platformrrrrr	r
Zcerberus.utilsrrr
rr0rrrrr3objectrrrrr-rzrrrr<module>s" 	$E
Back to Directory File Manager