[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.223.203.196: ~ $


L�X�9�@sKddlmZddlmZmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZmZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Ze�e�ZZdS)�)�absolute_import)�Callable�Hashable�Iterable�Mapping�MutableMapping)�copy)�errors)�	_str_type)�get_Validator_class�validator_factory�mapping_hashc@seZdZdZdS)�SchemaErrorz` Raised when the validation schema is missing, has the wrong format or
        contains errors. N)�__name__�
__module__�__qualname__�__doc__�rr�
/schema.pyrsrcseZdZdZ�fdd�Zidd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zedd��Zedd��Zdd�Zdd�Zd d!d"�Zd#d$�Z�S)%�DefinitionSchemaz3 A dict-subclass for caching of validated schemas. cs4dt�krtdt�att|�j|�S)N�SchemaValidator)�globalsr�SchemaValidatorMixinr�superr�__new__)�cls�args�kwargs)�	__class__rrrs	zDefinitionSchema.__new__cCs�t|t��std��||_t|t�rK|jj||�}t|t�s�yt|�}Wn*t	k
r�t
tjj
|���YnXt|�|_tdd|jdtjd|d|�|_|j|�}|j|�||_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_schema�target_validator)�
isinstancer�RuntimeError�	validatorr
�schema_registry�getr�dict�	Exceptionrr	�SCHEMA_ERROR_DEFINITION_TYPE�format�SchemaValidationSchema�validation_schemarZSchemaErrorHandler�schema_validator�expand�validate�schema)�selfr$r0rrr�__init__s&	
	
zDefinitionSchema.__init__cCsw|jj�}y||=WnLtk
r>td|��Yn5tk
rh}z|�WYdd}~XnX|j|=dS)Nz Schema has no field '%s' defined)r0r�
ValueErrorrr()r1�key�_new_schema�errr�__delitem__;s
zDefinitionSchema.__delitem__cCs|j|S)N)r0)r1�itemrrr�__getitem__FszDefinitionSchema.__getitem__cCs
t|j�S)N)�iterr0)r1rrr�__iter__IszDefinitionSchema.__iter__cCs
t|j�S)N)�lenr0)r1rrr�__len__LszDefinitionSchema.__len__cCs
t|�S)N)�str)r1rrr�__repr__OszDefinitionSchema.__repr__cCs=|jd|i�d}|j||i�||j|<dS)Nr)r.r/r0)r1r4�valuerrr�__setitem__RszDefinitionSchema.__setitem__cCs
t|j�S)N)r>r0)r1rrr�__str__WszDefinitionSchema.__str__cCs|j|j|jj��S)N)rr$r0r)r1rrrrZszDefinitionSchema.copycCs;y"|j|�}|j|�}Wntk
r6YnX|S)N)�_expand_logical_shortcuts�_expand_subschemasr()rr0rrrr.]s
zDefinitionSchema.expandcs�dd��x�|D]�}x��fdd�||D�D]q}|jd�\}}||j|gi�x1|||D]!}|||j||i�qxW|||=q7WqW|S)z� Expand agglutinated rules in a definition-schema.

        :param schema: The schema-definition to expand.
        :return: The expanded schema-definition.
        cSst|t�o|jd�S)N�allof_�anyof_�noneof_�oneof_)rErFrGrH)r"r
�
startswith)�xrrr�
is_of_rulemsz>DefinitionSchema._expand_logical_shortcuts.<locals>.is_of_rulec3s!|]}�|�r|VqdS)Nr)�.0rJ)rKrr�	<genexpr>rsz=DefinitionSchema._expand_logical_shortcuts.<locals>.<genexpr>�_)�split�update�append)rr0�fieldZof_rule�operator�ruler@r)rKrrCfs
$z*DefinitionSchema._expand_logical_shortcutscsW��fdd�}��fdd�}x&�D]�|�sCnT|�rn|j��d���d<n)|jd��di�d��d<xGdD]?}|��kr�|jd��|i�d��|<q�WxkdD]c}|��kr�g}x6��|D]&}|j|jd|i�d�qW|��|<q�Wq1W�S)Ncs!t��t�o d��kS)Nr0)r"rr)rRr0rr�has_schema_rule|sz<DefinitionSchema._expand_subschemas.<locals>.has_schema_rulecsFy)tdd���dj�D��SWntk
rAdSYnXdS)zc Tries to determine heuristically if the schema-constraints are
                aimed to mappings. css|]}t|t�VqdS)N)r"r)rLrJrrrrM�szRDefinitionSchema._expand_subschemas.<locals>.has_mapping_schema.<locals>.<genexpr>r0FN)�all�values�	TypeErrorr)rRr0rr�has_mapping_schema�s

z?DefinitionSchema._expand_subschemas.<locals>.has_mapping_schemar0r�	keyschema�valueschema�allof�anyof�items�noneof�oneof)rZr[)r\r]zitemsr_r`)r.rQ)rr0rUrYrTZnew_rules_definitionr8r)rRr0rrDzs$	
		")
-
$z#DefinitionSchema._expand_subschemascCs�y<|j|�}|jj�}|j|�|j|�WnTtk
rhttjj	|���Yn4t
k
r�}z|�WYdd}~Xn
X||_dS)N)r.r0rrPr/r3rr	r)r*r()r1r0r5r6rrrrP�s

zDefinitionSchema.updatecCst|j�|_dS)N)r+r$r,)r1rrr�regenerate_validation_schema�sz-DefinitionSchema.regenerate_validation_schemaNcCsW|dkr|j}t|�}||jjkrS|j|�|jjj|�dS)N)r0r
r$�_valid_schemas�	_validate�add)r1r0�_hashrrrr/�s	
zDefinitionSchema.validatecCs�t|t�r'|jjj||�}|dkrBttj��t|�}x?|D]7}t||t�rUt	j||||�||<qUW|j
|dd�s�t|j
j��dS)z� 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 this Validator object.
        N�	normalizeF)r"r
r$r%r&rr	ZSCHEMA_ERROR_MISSINGr�rules_set_registryr-)r1r0rRrrrrc�s

zDefinitionSchema._validate)rrrrrr2r7r9r;r=r?rArBr�classmethodr.rCrDrPrar/rcrr)rrrs$ 	%rc@s+eZdZidd�Zdd�ZdS)�UnvalidatedSchemacCs(t|t�st|�}||_dS)N)r"rr'r0)r1r0rrrr2�szUnvalidatedSchema.__init__cCsdS)Nr)r1r0rrrr/�szUnvalidatedSchema.validateN)rrrr2r/rrrrri�sric@seZdZdd�ZdS)r+cCs"ddd|jddi|_dS)NrFr0�typer')Zrulesr0)r1r$rrrr2�s	zSchemaValidationSchema.__init__N)rrrr2rrrrr+�sr+c@s�eZdZdZedd��Zejdd��Zedd��Zejdd��Zedd	��Zed
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)rzX This validator is extended to validate schemas passed to a Cerberus
        validator. cCs|jjdf�S)N�known_rules_set_refs)�_configr&)r1rrrrk�sz)SchemaValidatorMixin.known_rules_set_refscCs||jd<dS)Nrk)rl)r1r@rrrrk�scCs|jjdf�S)N�known_schema_refs)rlr&)r1rrrrm�sz&SchemaValidatorMixin.known_schema_refscCs||jd<dS)Nrm)rl)r1r@rrrrm�scCs|jdS)z% The schema that is being validated. r )rl)r1rrrr �sz"SchemaValidatorMixin.target_schemacCs|jdS)z0 The validator whose schema is being validated. r!)rl)r1rrrr!�sz%SchemaValidatorMixin.target_validatorcCs�|jd|d|jdd|jd�}xt|D]l}td|i�}||jjkr`q3||dd�|jr�|j|j�q3|jjj|�q3WdS)z4 {'allowed': ('allof', 'anyof', 'noneof', 'oneof')} �document_crumbr0r�turingrfFN)�_get_child_validator�root_allow_unknownr
r!rb�_errors�_errorrd)r1rTrRr@r$Zconstraintsrerrr�_validate_logical�s	

	z&SchemaValidatorMixin._validate_logicalcCst|t�rdSdS)NT)r"r)r1r@rrr�_validate_type_callablesz,SchemaValidatorMixin._validate_type_callablecCst|t�rdSdS)NT)r"r)r1r@rrr�_validate_type_hashablesz,SchemaValidatorMixin._validate_type_hashablecs0�j|�r,t�fdd�|D��SdS)Nc3s|]}�j|�VqdS)N)rv)rLrJ)r1rrrMsz@SchemaValidatorMixin._validate_type_hashables.<locals>.<genexpr>)Z_validate_type_listrV)r1r@r)r1r�_validate_type_hashablessz-SchemaValidatorMixin._validate_type_hashablescCst|t�r�||jkr"dS|j|f7_|jjj|�}|dkr}|j|f}|j|d|�dS|}td|i�}||jj	kr�dS|j
d|d|jdd|jd�}||dd�|jr|j|j�n|jj	j
|�dS)Nz"Rules set definition %s not found.rornr0rrfF)r"r
rkr!rgr&�
document_pathrsr
rbrprqrrrd)r1rRr@�
definition�pathrer$rrr�_validator_bulk_schemas*	
	z+SchemaValidatorMixin._validator_bulk_schemacCs�t|t�rdSt|t�rU||jj|jjkr�|j|d|�n0t|t�r�x|D]}|j||�qkWdS)Nz%s is no valid coercer)	r"rr
r!Z
validatorsZcoercersrsr�_validator_handler)r1rRr@�handlerrrrr|7s
z'SchemaValidatorMixin._validator_handlercCs7x0t|�D]"\}}|j||f|�q
WdS)N)�	enumerater{)r1rRr@�ir0rrr�_validator_itemsBsz%SchemaValidatorMixin._validator_itemscCs	t|t�r�||jkr"dS|j|f7_|jjj|�}|dkr}|j|f}|j|d|�dS|}t|�}||jj	kr�dS|j
d|ddd|j�}||dd�|jr�|j|j�n|jj	j
|�dS)NzSchema definition %s not found.rnr0rrfF)r"r
rmr!r%r&rxrsr
rbrprqrrrd)r1rRr@ryrzrer$rrr�_validator_schemaFs(		z&SchemaValidatorMixin._validator_schemaN)rrrr�propertyrk�setterrmr r!rtrurvrwr{r|r�r�rrrrr�src@speZdZdZidd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dd�Z
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|_|j|�dS)N)�_storage�extend)r1�definitionsrrrr2ls	zRegistry.__init__cCs|j|�|j|<dS)aA 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�)r1�nameryrrrrdps	zRegistry.addcCs|jS)zW Returns a :class:`dict` with all registered definitions mapped to
        their name. )r�)r1rrrrV{szRegistry.allcCs7x0t|�j�D]\}}|j||�qWdS)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^rd)r1r�r�ryrrrr��szRegistry.extendcCs|jj�dS)z( Purge all definitions in the registry. N)r��clear)r1rrrr��szRegistry.clearNcCs|jj||�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. )r�r&)r1r��defaultrrrr&�szRegistry.getcGs(x!|D]}|jj|d�qWdS)z� Unregister definitions from the registry.

        :param names: The names of the definitions that are to be
                      unregistered. N)r��pop)r1�namesr�rrr�remove�s
zRegistry.remove)rrrrr2rdrVr�r�r&r�rrrrr�es
r�c@s"eZdZedd��ZdS)�SchemaRegistrycCs
tj|�S)N)rr.)rryrrrr��sz!SchemaRegistry._expand_definitionN)rrrrhr�rrrrr��sr�c@s"eZdZedd��ZdS)�RulesSetRegistrycCstjd|i�dS)Nr)rr.)rryrrrr��sz#RulesSetRegistry._expand_definitionN)rrrrhr�rrrrr��sr�N)Z
__future__r�collectionsrrrrrrZcerberusr	Zcerberus.platformr
Zcerberus.utilsrrr
r(rrrir+�objectrr�r�r�r%rgrrrr�<module>s(�
�:

Filemanager

Name Type Size Permission Actions
__init__.cpython-35.opt-1.pyc File 704 B 0644
__init__.cpython-35.pyc File 704 B 0644
errors.cpython-35.opt-1.pyc File 20.06 KB 0644
errors.cpython-35.pyc File 20.06 KB 0644
platform.cpython-35.opt-1.pyc File 364 B 0644
platform.cpython-35.pyc File 364 B 0644
schema.cpython-35.opt-1.pyc File 16.08 KB 0644
schema.cpython-35.pyc File 16.08 KB 0644
utils.cpython-35.opt-1.pyc File 3.13 KB 0644
utils.cpython-35.pyc File 3.13 KB 0644
validator.cpython-35.opt-1.pyc File 49.72 KB 0644
validator.cpython-35.pyc File 49.72 KB 0644