[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.149.230.208: ~ $
U

���`���@sdZddlmZddlmZddlmZddlmZmZddlZddl	m
Z
ddlmZdd	l
mZmZmZmZmZmZmZmZdd
lmZmZmZmZddlmZmZmZe��Z dd
�Z!Gdd�de"�Z#Gdd�de"�Z$Gdd�de%�Z&dZ'Gdd�de(�Z)e)de&fi�Z*dS)a

    Extensible validation for Python dictionaries.
    This module implements Cerberus Validator class

    :copyright: 2012-2016 by Nicola Iarocci.
    :license: ISC, see LICENSE for more details.

    Full documentation is available at http://python-cerberus.org
�)�absolute_import)�literal_eval)�copy)�date�datetimeN)�warn)�errors)�
_int_types�	_str_type�	Container�Hashable�Iterable�Mapping�Sequence�Sized)�schema_registry�rules_set_registry�DefinitionSchema�SchemaError)�drop_item_from_tuple�readonly_classproperty�TypeDefinitioncCsdd�}|}||_|S)NcSstd��dS)NzcDummy method called. Its purpose is to hold justvalidation constraints for a rule in its docstring.)�RuntimeError)�self�
constraint�field�value�r�C/opt/alt/python38/lib/python3.8/site-packages/cerberus/validator.py�dummy*s�z(dummy_for_rule_validation.<locals>.dummy)�__doc__)Zrule_constraintsr�frrr�dummy_for_rule_validation)sr"c@seZdZdZdS)�
DocumentErrorzBRaised when the target document is missing or has the wrong formatN��__name__�
__module__�__qualname__r rrrrr#6sr#c@seZdZdZdS)�_SchemaRuleTypeErrorzw
    Raised when a schema (list) validation encounters a mapping.
    Not supposed to be used outside this module.
    Nr$rrrrr(<sr(csJeZdZdZdZdZedeefd�ede	fd�ede
fef�edefd�ed	e
fd�ed
efd�edeefd�edefd�ed
efef�edeefe	f�edefd�edefd�d�Ze�Z�fdd�Zedd��Zdd�Zedd��Zdd�Zd�dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Z d'd(�Z!e"d)d*��Z#e#j$d+d*��Z#e"d,d-��Z%e%j$d.d-��Z%e"d/d0��Z&e"d1d2��Z'e'j$d3d2��Z'e"d4d5��Z(e"d6d7��Z)e)j$d8d7��Z)e"d9d:��Z*e*j$d;d:��Z*e"d<d=��Z+e+j$d>d=��Z+e"d?d@��Z,e"dAdB��Z-e"dCdD��Z.e"dEdF��Z/e/j$dGdF��Z/e"dHdI��Z0e"dJdK��Z1e1j$dLdK��Z1e"dMdN��Z2e2j$dOdN��Z2e3dPdQ��Z4d�dRdS�Z5dTdU�Z6d�dWdX�Z7dYdZ�Z8d[d\�Z9d]d^�Z:d_d`�Z;dadb�Z<dcdd�Z=dedf�Z>dgdh�Z?didj�Z@edkdl��ZAedmdn��ZBdodp�ZCdqdr�ZDdsdt�ZEdudv�ZFdwdx�ZGdydz�ZHd{d|�ZId�d~d�ZJeJZKd�d��ZLd�d��ZMd�d��ZNeOd��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��ZbeOd��Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgd�d��ZheOd��ZieOd��Zjd�d��Zkd�d��Zld�d��Zmd�d��Znd�d��Zod�d„Zp�ZqS)��
BareValidatora�	
    Validator class. Normalizes and/or validates any mapping against a
    validation-schema which is provided as an argument at class instantiation
    or upon calling the :meth:`~cerberus.Validator.validate`,
    :meth:`~cerberus.Validator.validated` or
    :meth:`~cerberus.Validator.normalized` method. An instance itself is
    callable and executes a validation.

    All instantiation parameters are optional.

    There are the introspective properties :attr:`types`, :attr:`validators`,
    :attr:`coercers`, :attr:`default_setters`, :attr:`rules`,
    :attr:`normalization_rules` and :attr:`validation_rules`.

    The attributes reflecting the available rules are assembled considering
    constraints that are defined in the docstrings of rules' methods and is
    effectively used as validation schema for :attr:`schema`.

    :param schema: See :attr:`~cerberus.Validator.schema`.
                   Defaults to :obj:`None`.
    :type schema: any :term:`mapping`
    :param ignore_none_values: See :attr:`~cerberus.Validator.ignore_none_values`.
                               Defaults to ``False``.
    :type ignore_none_values: :class:`bool`
    :param allow_unknown: See :attr:`~cerberus.Validator.allow_unknown`.
                          Defaults to ``False``.
    :type allow_unknown: :class:`bool` or any :term:`mapping`
    :param require_all: See :attr:`~cerberus.Validator.require_all`.
                        Defaults to ``False``.
    :type require_all: :class:`bool`
    :param purge_unknown: See :attr:`~cerberus.Validator.purge_unknown`.
                          Defaults to to ``False``.
    :type purge_unknown: :class:`bool`
    :param purge_readonly: Removes all fields that are defined as ``readonly`` in the
                           normalization phase.
    :type purge_readonly: :class:`bool`
    :param error_handler: The error handler that formats the result of
                          :attr:`~cerberus.Validator.errors`.
                          When given as two-value tuple with an error-handler
                          class and a dictionary, the latter is passed to the
                          initialization of the error handler.
                          Default: :class:`~cerberus.errors.BasicErrorHandler`.
    :type error_handler: class or instance based on
                         :class:`~cerberus.errors.BaseErrorHandler` or
                         :class:`tuple`
    )�nullable)r*�readonly�type�empty�binaryr�boolean�	containerrr�dict�float�integer�list�number�set�string)r.r/r0rrr1r2r3r4r5r6r7cs�d|_t��|_d|_t��|_t��|_d|_	d|_
d|_|�|�|_
|�||�|�dd�|_|�dd�|_|�dd�|_g|_tt|���dS)a4
        The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, require_all=False,
                 purge_unknown=False, purge_readonly=False,
                 error_handler=errors.BasicErrorHandler)
        NrF�schema�
allow_unknown�require_all)�documentr�	ErrorList�_errors�recent_error�DocumentErrorTree�document_error_tree�SchemaErrorTree�schema_error_tree�
document_path�schema_path�update�"_BareValidator__init_error_handler�
error_handler�_BareValidator__store_config�getr8r9r:�_remaining_rules�superr)�__init__)r�args�kwargs��	__class__rrrL�s



zBareValidator.__init__cCsb|�dtj�}t|t�r"|\}}ni}t|t�rFt|tj�rF|f|�St|tj�rV|Std��dS)NrGzInvalid error_handler.)	�poprZBasicErrorHandler�
isinstance�tupler,�
issubclassZBaseErrorHandlerr)rNrGZ	eh_configrrrZ__init_error_handler�s

�
z"BareValidator.__init_error_handlercCsNd}t|dt|���D]*\}}||kr6td|��q||||<q||_dS)z.Assign args to kwargs and store configuration.)r8�ignore_none_valuesr9r:�
purge_unknown�purge_readonlyNz.__init__ got multiple values for argument '%s')�	enumerate�len�	TypeError�_config)rrMrNZ	signature�i�prrrZ__store_config�szBareValidator.__store_configcCs|j��dS)z'Purge the cache of known valid schemas.N)�_valid_schemas�clear��clsrrr�clear_caches�szBareValidator.clear_cachesc	Gs�t|�dkr\|j�|d�|j��|dD](}|j�|�|j�|�|j�|�q.�n:t|�dkr�t	|dt
�r�|�|dtj
|d��nt|�dk�r�|d}|dj}|dj}|dd�}|j|f}|j}|tjjkr�|dk	r�|||f7}|�sd}	n^|�|�|j�|�}
|dk�r4|
�|d�}	n0|dk�r\|
�||j�}	||
k�rdd}n|
|}	|j�|�}t�|||||	||�|_|�|jg�dS)	a
        Creates and adds one or multiple errors.

        :param args: Accepts different argument's signatures.

                     *1. Bulk addition of errors:*

                     - :term:`iterable` of
                       :class:`~cerberus.errors.ValidationError`-instances

                     The errors will be added to
                     :attr:`~cerberus.Validator._errors`.

                     *2. Custom error:*

                     - the invalid field's name

                     - the error message

                     A custom error containing the message will be created and
                     added to :attr:`~cerberus.Validator._errors`.
                     There will however be fewer information contained in the
                     error (no reference to the violated rule and its
                     constraint).

                     *3. Defined error:*

                     - the invalid field's name

                     - the error-reference, see :mod:`cerberus.errors`

                     - arbitrary, supplemental information about the error

                     A :class:`~cerberus.errors.ValidationError` instance will
                     be created and added to
                     :attr:`~cerberus.Validator._errors`.
        �r�Nr*F�requiredZ__require_all__)rYr=�extend�sortr@�addrBrG�emitrRr
�_errorrZCUSTOM�code�rulerCrD�
UNKNOWN_FIELD�_resolve_rules_set�_resolve_schemar8rIr:r;ZValidationErrorr>)rrM�errorrrkrl�inforCrDr�	rules_setrrrrrj�sR&


�


�zBareValidator._errorNcKs�|j��}|�|�|jsRd|d<t|d<|j|d<|j|d<|j|d<|j|d<|j	f|�}|dkrp|j
|_
nt|t�s�|f}|j
||_
|dkr�|j
|_
nt|t�s�|f}|j
||_
|S)	a@
        Creates a new instance of Validator-(sub-)class. All initial parameters of the
        parent are passed to the initialization, unless a parameter is given as an
        explicit *keyword*-parameter.

        :param document_crumb: Extends the
                               :attr:`~cerberus.Validator.document_path`
                               of the child-validator.
        :type document_crumb: :class:`tuple` or :term:`hashable`
        :param schema_crumb: Extends the
                             :attr:`~cerberus.Validator.schema_path`
                             of the child-validator.
        :type schema_crumb: :class:`tuple` or hashable
        :param kwargs: Overriding keyword-arguments for initialization.
        :type kwargs: :class:`dict`

        :return: an instance of ``self.__class__``
        T�is_childrG�root_allow_unknown�root_require_all�
root_document�root_schemaN)r[rrErs�toy_error_handlerr9r:r;r8rPrCrRrSrD)r�document_crumb�schema_crumbrNZchild_configZchild_validatorrrr�_get_child_validatorEs*









z"BareValidator._get_child_validatorcCs<d�||�dd��}t||d�}|dkr8td�||���|S)Nz_{0}_{1}� �_z/There's no handler for '{}' in the '{}' domain.)�format�replace�getattrr)rZdomainrlZ
methodname�resultrrrZ__get_rule_handlerts��z BareValidator.__get_rule_handlercCs�t|j�}t|j�}|D]b}t|dd�D]}t|j||�|_q(t|dd�D]}t|j||�|_qL|jr|�|j||�qdS)a{
        Removes nodes by index from an errorpath, relatively to the basepaths of self.

        :param errors: A list of :class:`errors.ValidationError` instances.
        :param dp_items: A list of integers, pointing at the nodes to drop from
                         the :attr:`document_path`.
        :param sp_items: Alike ``dp_items``, but for :attr:`schema_path`.
        T)�reverseN)rYrCrD�sortedrZchild_errors�_drop_nodes_from_errorpaths)rr=Zdp_itemsZsp_itemsZdp_basedepthZsp_basedepthrpr\rrrr�~s	

��z)BareValidator._drop_nodes_from_errorpathscCsn|�d�r.|dd�}|�d�r&|jn|j}n|j}|�d�}|D]}||krTdS|�|i�}qB|d|fS)a�
        Searches for a field as defined by path. This method is used by the
        ``dependency`` evaluation logic.

        :param path: Path elements are separated by a ``.``. A leading ``^``
                     indicates that the path relates to the document root,
                     otherwise it relates to the currently evaluated document,
                     which is possibly a subdocument.
                     The sequence ``^^`` at the start will be interpreted as a
                     literal ``^``.
        :type path: :class:`str`
        :returns: Either the found field name and its value or :obj:`None` for
                  both.
        :rtype: A two-value :class:`tuple`.
        �^rcN�.)NN���)�
startswithr;rv�splitrI)r�path�context�parts�partrrr�
_lookup_field�s

zBareValidator._lookup_fieldcCs(t|t�r|St|t�r$|j�|�SdS�N)rRrr
rrI)rrrrrrrn�s


z BareValidator._resolve_rules_setcCs(t|t�r|St|t�r$|j�|�SdSr�)rRrr
rrI�rr8rrrro�s


zBareValidator._resolve_schemacCs|j�dd�S)a2
        If ``True`` unknown fields that are not defined in the schema will be ignored.
        If a mapping with a validation schema is given, any undefined field will be
        validated against its rules. Also see :ref:`allowing-the-unknown`.
        Type: :class:`bool` or any :term:`mapping`
        r9F�r[rI�rrrrr9�szBareValidator.allow_unknowncCs0|js"t|ttf�s"t|d|i�||jd<dS)Nr9)rsrR�boolrr[�rrrrrr9�scCs|j�dd�S)zw
        If ``True`` known fields that are defined in the schema will be required.
        Type: :class:`bool`
        r:Fr�r�rrrr:�szBareValidator.require_allcCs||jd<dS)Nr:�r[r�rrrr:�scCs|�|j�S)z�
        The errors of the last processing formatted by the handler that is bound to
        :attr:`~cerberus.Validator.error_handler`.
        )rGr=r�rrrr�szBareValidator.errorscCs|j�dd�S)zm
        Whether to not process :obj:`None`-values in a document or not.
        Type: :class:`bool`
        rUFr�r�rrrrU�sz BareValidator.ignore_none_valuescCs||jd<dS)NrUr�r�rrrrU�scCs|j�dd�S)z�
        ``True`` for child-validators obtained with
        :meth:`~cerberus.Validator._get_child_validator`.
        Type: :class:`bool`
        rsFr�r�rrrrs�szBareValidator.is_childcCs|j�dd�S)z/``True`` if the document is already normalized.�_is_normalizedFr�r�rrrr��szBareValidator._is_normalizedcCs||jd<dS)Nr�r�r�rrrr�scCs|j�dd�S)z�
        If ``True``, unknown fields will be deleted from the document unless a
        validation is called with disabled normalization. Also see
        :ref:`purging-unknown-fields`.
        Type: :class:`bool`
        rVFr�r�rrrrVszBareValidator.purge_unknowncCs||jd<dS)NrVr�r�rrrrVscCs|j�dd�S)z�
        If ``True``, fields declared as readonly will be deleted from the document
        unless a validation is called with disabled normalization.
        Type: :class:`bool`
        rWFr�r�rrrrWszBareValidator.purge_readonlycCs||jd<dS)NrWr�r�rrrrWscCs|j�d|j�S)z�
        The :attr:`~cerberus.Validator.allow_unknown` attribute of the first level
        ancestor of a child validator.
        rt)r[rIr9r�rrrrt sz BareValidator.root_allow_unknowncCs|j�d|j�S)z�
        The :attr:`~cerberus.Validator.require_all` attribute of the first level
        ancestor of a child validator.
        ru)r[rIr:r�rrrru(szBareValidator.root_require_allcCs|j�d|j�S)z~
        The :attr:`~cerberus.Validator.document` attribute of the first level ancestor
        of a child validator.
        rv)r[rIr;r�rrrrv0szBareValidator.root_documentcCs|j�dt�S)zj
        The registry that holds referenced rules sets.
        Type: :class:`~cerberus.Registry`
        r)r[rIrr�rrrr8sz BareValidator.rules_set_registrycCs||jd<dS)Nrr��r�registryrrrr@scCs|j�d|j�S)z|
        The :attr:`~cerberus.Validator.schema` attribute of the first level ancestor of
        a child validator.
        rw)r[rIr8r�rrrrwDszBareValidator.root_schemacCs|jS)z�
        The validation schema of a validator. When a schema is passed to a method, it
        replaces this attribute.
        Type: any :term:`mapping` or :obj:`None`
        )�_schemar�rrrr8LszBareValidator.schemacCs8|dkrd|_n$|js t|t�r(||_nt||�|_dSr�)r�rsrRrr�rrrr8Us
cCs|j�dt�S)zg
        The registry that holds referenced schemas.
        Type: :class:`~cerberus.Registry`
        r)r[rIrr�rrrr^szBareValidator.schema_registrycCs||jd<dS)Nrr�r�rrrrfscCs4t|j�t|j�@}|r$td|�t|j�|jS)zi
        The constraints that can be used for the 'type' rule.
        Type: A tuple of strings.
        zcThese types are defined both with a method and in the'types_mapping' property of this validator: %s)r6�
types_mapping�_types_from_methodsrrS)raZredundant_typesrrr�typesls��zBareValidator.typescCs�t��|_d|_t��|_t��|_t|�|_	|j
s:d|_|dk	rPt||�|_
n(|j
dkrxt|jt�rni|_n
ttj��|dkr�ttj��t|t�s�ttj�|���|j�|�dS)NF)rr<r=r>r?r@rArBrr;rsr�rr8rRr9rr�rZSCHEMA_ERROR_MISSINGr#ZDOCUMENT_MISSINGZDOCUMENT_FORMATr~rG�start)rr;r8rrrZ__init_processing}s$







zBareValidator.__init_processingc	Gs@|r6|D]*}z|j�|�Wqtk
r0YqXqng|_dS)z�
        Drops rules from the queue of the rules that still need to be evaluated for the
        currently processed field. If no arguments are given, the whole queue is
        emptied.
        N)rJ�remove�
ValueError)r�rulesrlrrr�_drop_remaining_rules�s
z#BareValidator._drop_remaining_rulesFcCs@|�||�|�|j|j�|j�|�|jr6|s6dS|jSdS)a
        Returns the document normalized according to the specified rules of a schema.

        :param document: The document to normalize.
        :type document: any :term:`mapping`
        :param schema: The validation schema. Defaults to :obj:`None`. If not
                       provided here, the schema must have been provided at
                       class instantiation.
        :type schema: any :term:`mapping`
        :param always_return_document: Return the document, even if an error
                                       occurred. Defaults to: ``False``.
        :type always_return_document: :class:`bool`
        :return: A normalized copy of the provided mapping or :obj:`None` if an
                 error occurred during normalization.
        N)�_BareValidator__init_processing�!_BareValidator__normalize_mappingr;r8rG�endr=)rr;r8�always_return_documentrrr�
normalized�s
zBareValidator.normalizedcCs�t|t�r|�|�}|��}|D]}|�||�||<q |�||�|jr\|js\|�||�|j	rn|�
||�|�||�|�||�|�
||�|�||�d|_|S)NT)rRr
rorrn�'_BareValidator__normalize_rename_fieldsrVr9�_normalize_purge_unknownrW�(_BareValidator__normalize_purge_readonly�(_BareValidator__validate_readonly_fields�(_BareValidator__normalize_default_fields�_normalize_coerce�$_BareValidator__normalize_containersr��r�mappingr8rrrrZ__normalize_mapping�s 

z!BareValidator.__normalize_mappingc
Cs�tj}|D]�}||krRd||krR|�||d|||||�dd�|�||<q
t|jt�r
d|jkr
|�|jd||||j�dd�|�||<q
dS)��
        {'oneof': [
            {'type': 'callable'},
            {'type': 'list',
             'schema': {'oneof': [{'type': 'callable'},
                                  {'type': 'string'}]}},
            {'type': 'string'}
        ]}
        �coercer*FN)r�COERCION_FAILED� _BareValidator__normalize_coercerIrRr9r)rr�r8rprrrrr��s*
�

���zBareValidator._normalize_coercec	
Cs�t|t�r|�d|�}nLt|t�rd|}|D]4}|�|||||�}tj|j�|j	|f�kr*q`q*|Sz
||�WSt
k
r�}z*|r�|dks�|�||t|��|WY�Sd}~XYnXdS)NZnormalize_coerce)
rRr
� _BareValidator__get_rule_handlerr
r�rr�r@�fetch_errors_fromrC�	Exceptionrj�str)	rZ	processorrrr*rpr�r]�errrZ__normalize_coerce�s(


���
z BareValidator.__normalize_coercec	Cs�|D]�}t|�|d��}t||t�r�d|krD|�||||d�d|krb|�||||d�|td�@szt|jt�r�z|�|||�Wq�tk
r�Yq�Xqt||t	�r�qqt||t
�rd|kr�|�|||�qd|kr|�|||�qdS)Nr�	keysrules�valuesrules)r9rVr8r8�items)
r6rIrRr�/_BareValidator__normalize_mapping_per_keysrules�1_BareValidator__normalize_mapping_per_valuesrulesr9�,_BareValidator__normalize_mapping_per_schemar(r
r�-_BareValidator__normalize_sequence_per_schema�,_BareValidator__normalize_sequence_per_items)rr�r8rr�rrrZ__normalize_containerss>
�
��
�z$BareValidator.__normalize_containersc	s
t�fdd�||D��}tdd�||D��}|j||df|d�}|j|dd�}|jrx|�|jgdd	g�|�|j�|D]�}|||kr�q|||||kr�td
jd�dd�|j	|fD��|d
��|||||||<q||||||||<|||=q|dS)Nc3s|]}|�fVqdSr�r��.0�k��property_rulesrr�	<genexpr>+szBBareValidator.__normalize_mapping_per_keysrules.<locals>.<genexpr>css|]}||fVqdSr�rr�rrrr�,sr��ryrzr8T�r�rd�zHNormalizing keys of {path}: {key} already exists, its value is replaced.r�css|]}t|�VqdSr�)r��r��xrrrr�;s)r��key)
r1r{r�r=r�rjrr~�joinrC)	rrr�r�r8r;�	validatorr�r�rr�rZ!__normalize_mapping_per_keysrules*s0���z/BareValidator.__normalize_mapping_per_keysrulescslt�fdd�||D��}|j||df|d�}|j||dd�||<|jrh|�|jgdg�|�|j�dS)Nc3s|]}|�fVqdSr�rr���value_rulesrrr�EszDBareValidator.__normalize_mapping_per_valuesrules.<locals>.<genexpr>r�r�Tr�rd)r1r{r�r=r�rj)rrr�r�r8r�rr�rZ#__normalize_mapping_per_valuesrulesDs��
z1BareValidator.__normalize_mapping_per_valuesrulesc
Cs�|�|i�}|s"t|jt�r"|j}|j||df|�di�|�d|j�|�d|j�|�d|j�d�}t||�}|j||dd�}||�||<|j	r�|�
|j	�dS)Nr8r9rVr:)ryrzr8r9rVr:Tr�)rIrRr9rr{rVr:r,r�r=rj)rrr�r8r�r��
value_typeZresult_valuerrrZ__normalize_mapping_per_schemaPs 
�z,BareValidator.__normalize_mapping_per_schemacs�t��fdd�tt|���D���tdd�t|��D��}|j��df�d�}t|��}|j|dd�}||���|�<|jr�|�	|jgdg�|�
|j�dS)	Nc3s|]}|��dfVqdS)r8Nrr��rr8rrr�dsz@BareValidator.__normalize_sequence_per_schema.<locals>.<genexpr>css|]\}}||fVqdSr�r�r�r��vrrrr�fsr8r�Tr�rd)r1�rangerYrXr{r,r��valuesr=r�rj)rrr�r8r;r�r�r�rr�rZ__normalize_sequence_per_schemabs��z-BareValidator.__normalize_sequence_per_schemac
Cs�||d||}}t|�t|�kr*dStdd�t|�D��}tdd�t|�D��}|j||df|d�}t||�}|j|dd�}	||	���||<|jr�|�|jgdg�|�	|j�dS)	Nr�css|]\}}||fVqdSr�rr�rrrr�usz?BareValidator.__normalize_sequence_per_items.<locals>.<genexpr>css|]\}}||fVqdSr�rr�rrrr�vsr�Tr�rd)
rYr1rXr{r,r�r�r=r�rj)
rrr�r8r�r�r;r�r�r�rrrZ__normalize_sequence_per_itemsqs �z,BareValidator.__normalize_sequence_per_itemscs&�fdd�|D�D]}|�|�q|S)Ncs$g|]}��|i��dd�r|�qS)r+F�rIr��r8rr�
<listcomp>�sz<BareValidator.__normalize_purge_readonly.<locals>.<listcomp>�rQ�r�r8rrr�rZ__normalize_purge_readonly�sz(BareValidator.__normalize_purge_readonlycs&�fdd�|D�D]}|�|�q|S)�{'type': 'boolean'}csg|]}|�kr|�qSrrr�r�rrr��sz:BareValidator._normalize_purge_unknown.<locals>.<listcomp>r�r�rr�rr��sz&BareValidator._normalize_purge_unknowncCsbt|�D]T}||kr2|�|||�|�|||�qt|jt�rd|jkr|�|||ji|�q|S)N�rename_handler)rS�_normalize_rename�_normalize_rename_handlerrRr9rr�rrrZ__normalize_rename_fields�s
���z'BareValidator.__normalize_rename_fieldscCs*d||kr&|||||d<||=dS)z{'type': 'hashable'}�renameNrr�rrrr��szBareValidator._normalize_renamecCsJd||krdS|�||d||dtj�}||krF||||<||=dS)r�r�NF)r�rZRENAMING_FAILED)rr�r8r�new_namerrrr��s

�z'BareValidator._normalize_rename_handlercs:���fdd��D�D]}���|d|�|�qdS)Nc3s.|]&}|�kr���|��d�r|VqdS)r+N)rnrIr��r�r8rrrr��s�z;BareValidator.__validate_readonly_fields.<locals>.<genexpr>r+)�_validate_readonlyr�rr�rZ__validate_readonly_fields�s�
z(BareValidator.__validate_readonly_fieldsc

s2��fdd��D�}z�fdd�|D�}Wntk
rBt�YnX|D]}|���|�qHt�}�fdd�|D�}|�r.|�d�}z|���|�WnRtk
r�|�|�Yn6tk
r�}z|�	|t
jt|��W5d}~XYnXt
t|��}	|	|k�r"|D]}|�	|t
jd��q�q.qt|�|	�qtdS)Ncs4g|],}|�ks,�|dkr�|�dd�s|�qS)Nr*Fr�r��r�r8rrr��s
�z<BareValidator.__normalize_default_fields.<locals>.<listcomp>csg|]}d�|kr|�qS)�defaultrr�r�rrr��scsg|]}d�|kr|�qS)�default_setterrr�r�rrr��srz)Circular dependencies of default setters.)rZr(�_normalize_defaultr6rQ�_normalize_default_setter�KeyError�appendr�rjrZSETTING_DEFAULT_FAILEDr��hashrSrh)
rr�r8Zempty_fieldsZfields_with_defaultrZknown_fields_statesZfields_with_default_setterr�Zfields_processing_staterr�rZ__normalize_default_fields�s>�


�
&
�z(BareValidator.__normalize_default_fieldscCs||d||<dS)z{'nullable': True}r�Nrr�rrrr��sz BareValidator._normalize_defaultcCs>d||kr:||d}t|t�r.|�d|�}||�||<dS)zi
        {'oneof': [
            {'type': 'callable'},
            {'type': 'string'}
        ]}
        r�Znormalize_default_setterN)rRr
r�)rr�r8r�setterrrrr��s

z'BareValidator._normalize_default_setterTcCs�||_t�|_|�||�|r.|�|j|j�|jD]F}|jrN|j|dkrNq4|j�|�}|dk	rp|�	||�q4|�
|�q4|js�|�|j�|j�
|�t|j�S)aO
        Normalizes and validates a mapping against a validation-schema of defined rules.

        :param document: The document to normalize.
        :type document: any :term:`mapping`
        :param schema: The validation schema. Defaults to :obj:`None`. If not
                       provided here, the schema must have been provided at
                       class instantiation.
        :type schema: any :term:`mapping`
        :param update: If ``True``, required fields won't be checked.
        :type update: :class:`bool`
        :param normalize: If ``True``, normalize the document before validation.
        :type normalize: :class:`bool`

        :return: ``True`` if validation succeeds, otherwise ``False``. Check
                 the :func:`errors` property for a list of processing errors.
        :rtype: :class:`bool`
        N)rEr6�_unrequired_by_excludesr�r�r;r8rUrI�$_BareValidator__validate_definitions�'_BareValidator__validate_unknown_fields�(_BareValidator__validate_required_fieldsrGr�r�r=)rr;r8rE�	normalizer�definitionsrrr�validate�s 
zBareValidator.validatecOs0|�dd�}|j||�|jr&|s&dS|jSdS)z�
        Wrapper around :meth:`~cerberus.Validator.validate` that returns the normalized
        and validated document or :obj:`None` if validation failed.
        r�FN)rQr�r=r;)rrMrNr�rrr�	validated's

zBareValidator.validatedcCsr|jr`|j|}t|jttf�rn|jr*dnd}|j|||jid�}|||idd�sn|�|j�n|�|t	j
�dS)Nr9Z__allow_unknown__)rzr8F�r�)r9r;rRrr
rsr{rjr=rrm)rrrrzr�rrrZ__validate_unknown_fields3s
�z'BareValidator.__validate_unknown_fieldscs�����fdd�}������j����fdd��jD�����fdd��jD������fdd��D����_�jr��j�d�}z||�}|r�Wq�Wqvtk
r�Yq�YqvXqv���d	S)
z3Validate a field's value against its defined rules.cs ��d|�}|��|d����S)Nr�)r�rI)rlr�)r�rrrrr�
validate_ruleEsz;BareValidator.__validate_definitions.<locals>.validate_rulecs"g|]}|�ks|�jkr|�qSr)�mandatory_validationsr�)r�rrrr�Ls
�z8BareValidator.__validate_definitions.<locals>.<listcomp>c3s|]}|�kr|VqdSr�rr�)�rules_queuerrr�Qsz7BareValidator.__validate_definitions.<locals>.<genexpr>c3s,|]$}|�kr|�jkr|dkr|VqdS))r9r:�metareN)�normalization_rulesr�)r�rrrr�Ts

�rN)	rnr;�priority_validationsrfr�rJrQr(r�)rr�rr�rlr�r)r�rr�rrrZ__validate_definitionsBs,

���z$BareValidator.__validate_definitionsz� {'oneof': [{'type': 'boolean'},
                       {'type': ['dict', 'string'],
                        'check_with': 'bulk_schema'}]} cs\t|t�r@t|t�s@t�fdd�|D��}|rX|�|tj|�n|�krX|�|tj|�dS)z{'type': 'container'}c3s|]}|�kr|VqdSr�rr���allowed_valuesrrr�usz2BareValidator._validate_allowed.<locals>.<genexpr>N)rRr
r
rSrjrZUNALLOWED_VALUESZUNALLOWED_VALUE)rr�rrZ	unallowedrr�r�_validate_allowedrszBareValidator._validate_allowedcCs�t|t�rRz|�d|�}Wn*tk
rD|�d|�}tdt�YnX|||�n2t|t�rv|D]}|�|||�q`n||||j�dS)r��
check_withr�ziThe 'validator' rule was renamed to 'check_with'. Please update your schema and method names accordingly.N)	rRr
r�rr�DeprecationWarningr
�_validate_check_withrj)rZchecksrrZ
value_checkerr�rrrr|s

�

z"BareValidator._validate_check_withcCsZt|t�sdSt|t�r"t|t�r.t|f�}nt|�}|t|�}|rV|�|tj|�dS)z{'empty': False }N)rRr
r
r6rjrZMISSING_MEMBERS)rZexpected_valuesrrZmissing_valuesrrr�_validate_contains�s
�z BareValidator._validate_containscCsnt|t�st|ttf�s|f}t|t�r6|�||�nt|t�rL|�||�|j�|j	|df�dk	rjdSdS)zD{'type': ('dict', 'hashable', 'list'), 'check_with': 'dependencies'}�dependenciesNT)
rRr
r
rr�._BareValidator__validate_dependencies_sequence�-_BareValidator__validate_dependencies_mappingr@Zfetch_node_fromrD)rrrrrrr�_validate_dependencies�s �

���z$BareValidator._validate_dependenciesc	Cs�d}i}|��D]P\}}t|t�r,t|t�r2|g}|�|�\}}||krR|d7}q|�||i�q|t|�kr~|�|tj	|�dS)Nrrc)
r�rRrr
r�rErYrjrZDEPENDENCIES_FIELD_VALUE)	rrrZvalidated_dependencies_counterZ
error_infoZdependency_nameZdependency_valuesZwanted_fieldZwanted_field_valuerrrZ__validate_dependencies_mapping�s�
z-BareValidator.__validate_dependencies_mappingcCs0|D]&}|�|�ddkr|�|tj|�qdS)Nr)r�rjrZDEPENDENCIES_FIELD)rrrZ
dependencyrrrZ __validate_dependencies_sequence�sz.BareValidator.__validate_dependencies_sequencec	CsBt|t�r>t|�dkr>|�ddddddd�|s>|�|tj�d	S)
r�r�allowed�	forbiddenr��	minlength�	maxlength�regexr�N)rRrrYr�rjrZEMPTY_NOT_ALLOWED)rr-rrrrr�_validate_empty�s�	zBareValidator._validate_emptycs�t|t�r|g}�j|�d�j�r0�j�|�|D].}|�jkr4�j|�d�j�r4�j�|�q4t�fdd�|D��r�d�dd�|D��}��	|t
j|�dS)z>{'type': ('hashable', 'list'), 'schema': {'type': 'hashable'}}rec3s|]}|�jkVqdSr��r;)r��excluded_fieldr�rrr��sz3BareValidator._validate_excludes.<locals>.<genexpr>z, css|]}d�|�VqdS)z'{0}'N)r~�r�rrrrr��sN)rRrr8rIr:r�rh�anyr�rjrZEXCLUDES_FIELD)rZexcluded_fieldsrrrZ
exclusion_strrr�r�_validate_excludes�s
�
�z BareValidator._validate_excludescCsZt|t�r>t|t�s>t|�t|�@}|rV|�|tjt|��n||krV|�|tj|�dS)z{'type': 'list'}N)	rRrr
r6rjrZFORBIDDEN_VALUESr4ZFORBIDDEN_VALUE)rZforbidden_valuesrrrrrr�_validate_forbidden�sz!BareValidator._validate_forbiddencCs�t|�t|�kr,|�|tjt|�t|��n^tdd�t|�D��}|j||df|d�}|tdd�t|�D��|jdd�s�|�|tj|j	�dS)	z'{'type': 'list', 'check_with': 'items'}css|]\}}||fVqdSr�r)r�r\�
definitionrrrr�sz0BareValidator._validate_items.<locals>.<genexpr>r�r�css|]\}}||fVqdSr�r)r�r\rrrrr�sF�rEr�N)
rYrjrZITEMS_LENGTHr1rXr{rEZ	BAD_ITEMSr=)rr�rr�r8r�rrr�_validate_itemss ���zBareValidator._validate_itemscCs�d}t��}t|�D]�\}}||��i}	dD]4}
|
|	|kr,|
|j|kr,|j||
|	||
<q,d|	|kr||j|	|d<|j|||f|	dd�}||j|jdd�r�|d7}q|�	|j
gd	g�|�|j
�q||fS)
zl
        Validates value against all definitions and logs errors according to the
        operator.
        r)r9r,r9T)rzr8r9Frrc�)rr<rXrr8r9r{r;rEr�r=rf)r�operatorr�rrZ
valid_counterr=r\rr8rlr�rrrZ__validate_logicals&�
z BareValidator.__validate_logicalcCs8|�d|||�\}}|dkr4|�|tj||t|��dS)z${'type': 'list', 'logical': 'anyof'}ZanyofrcN)� _BareValidator__validate_logicalrjrZANYOFrY�rr�rrZvalidsr=rrr�_validate_anyof2szBareValidator._validate_anyofcCs<|�d|||�\}}|t|�kr8|�|tj||t|��dS)z${'type': 'list', 'logical': 'allof'}ZallofN)rrYrjrZALLOFrrrr�_validate_allof8szBareValidator._validate_allofcCs8|�d|||�\}}|dkr4|�|tj||t|��dS)z%{'type': 'list', 'logical': 'noneof'}ZnoneofrN)rrjrZNONEOFrYrrrr�_validate_noneof>szBareValidator._validate_noneofcCs8|�d|||�\}}|dkr4|�|tj||t|��dS)z${'type': 'list', 'logical': 'oneof'}�oneofrcN)rrjrZONEOFrYrrrr�_validate_oneofDszBareValidator._validate_oneofcCs4z||kr|�|tj�Wntk
r.YnXdS�z{'nullable': False }N)rjrZ	MAX_VALUErZ)rZ	max_valuerrrrr�
_validate_maxJs
zBareValidator._validate_maxcCs4z||kr|�|tj�Wntk
r.YnXdSr)rjrZ	MIN_VALUErZ)rZ	min_valuerrrrr�
_validate_minRs
zBareValidator._validate_mincCs.t|t�r*t|�|kr*|�|tjt|��dS�z{'type': 'integer'}N)rRr
rYrjrZ
MAX_LENGTH)rZ
max_lengthrrrrr�_validate_maxlengthZsz!BareValidator._validate_maxlength�cCs.t|t�r*t|�|kr*|�|tjt|��dSr")rRr
rYrjrZ
MIN_LENGTH)rZ
min_lengthrrrrr�_validate_minlengthasz!BareValidator._validate_minlengthcCs@|dkr<|s|�|tj�|�dddddddd	d
ddd
d�
dS)r�Nrr-rr�r��min�maxr	r
rr8r,r�)rjrZNOT_NULLABLEr�)rr*rrrrr�_validate_nullablefs$�z BareValidator._validate_nullablecs|t|t�rx|j||dft�fdd�|��D��d�}|tdd�|��D��dd�sx|�|jgdd	g�|�|tj	|j�d
S)��
        {'type': ['dict', 'string'],
         'check_with': 'bulk_schema',
         'forbidden': ['rename', 'rename_handler']}
        r�c3s|]}|�fVqdSr�rr�r�rrr��sz4BareValidator._validate_keysrules.<locals>.<genexpr>r�css|]}||fVqdSr�rr�rrrr��sFr�rdr�N)
rRrr{r1�keysr�r=rjrZ	KEYSRULES)rr8rrr�rr�r�_validate_keysrules{s
�z!BareValidator._validate_keysrulescCsH|rD|js|�|tj�tj|j�|j|f�k}|jrD|rD|��dS)r�N)r�rjrZREADONLY_FIELDr@r�rCr�)rr+rrZ	has_errorrrrr��s
���
z BareValidator._validate_readonlycCsFt|t�sdS|�d�s |d7}t�|�}|�|�sB|�|tj�dS)z{'type': 'string'}N�$)	rRr
�endswith�re�compile�matchrjrZREGEX_MISMATCH)r�patternrrZre_objrrr�_validate_regex�s



zBareValidator._validate_regexz {'type': 'boolean'} cs�z t�fdd��j��D��}Wn0tk
rP�jrJ�jddkrJt�n�YnX|�j8}|t��fdd��D��}|D]}��|t	j
�q|�jr�t�fdd��D��}�j�|�rֈj|D]}��|t	j
�q�dS)zy
        Validates that required fields are not missing.

        :param document: The document being validated.
        c3s.|]&\}}��|��d�j�dkr|VqdS)reTN)rnrIr:)r�rrr�rrr��s
��z;BareValidator.__validate_required_fields.<locals>.<genexpr>r�r8c3s&|]}��|�dk	s�js|VqdSr�)rIrUr�r;rrrr��s�c3s |]}��|�dk	r|VqdSr�r�rr
rrr��sN)r6r8r��AttributeErrorrsrDr(r�rjrZREQUIRED_FIELD�
isdisjoint)rr;reZmissingrZfieldsrr3rZ__validate_required_fields�s&�
�
z(BareValidator.__validate_required_fieldscCsL|dkrdSt|t�r0t|t�s0|�|||�nt|t�rH|�|||�dS)z�
        {'type': ['dict', 'string'],
         'anyof': [{'check_with': 'schema'},
                   {'check_with': 'bulk_schema'}]}
        N)rRrr
�(_BareValidator__validate_schema_sequencer�'_BareValidator__validate_schema_mapping)rr8rrrrr�_validate_schema�s
zBareValidator._validate_schemacCs�|�|�}|j|�d|j�}|j|�d|j�}|j||df|||d�}z&|||jdd�sn|�|tj	|j
�Wn$tk
r�|�|tj��YnXdS)Nr9r:r8)ryrzr8r9r:Fr)
ror8rIr9r:r{rErjrZMAPPING_SCHEMAr=r(ZBAD_TYPE_FOR_SCHEMA)rrr8rr9r:r�rrrZ__validate_schema_mapping�s 
�z'BareValidator.__validate_schema_mappingcs�t�fdd�tt|��D���|j||df�|jd�}|tdd�t|�D��|jdd�|jr�|�|jgdg�|�	|t
j|j�dS)	Nc3s|]}|�fVqdSr�r)r�r\r�rrr��sz;BareValidator.__validate_schema_sequence.<locals>.<genexpr>r8)ryrzr8r9css|]\}}||fVqdSr�r)r�r\r�rrrr��sFrrd)r1r�rYr{r9rXrEr=r�rjrZSEQUENCE_SCHEMA)rrr8rr�rr�rZ__validate_schema_sequence�s��z(BareValidator.__validate_schema_sequencec	Cs�|sdSt|t�r|fn|}|D]R}|j�|�}|dk	rTt||j�oPt||j�}n|�d|�}||�}|r dSq |�|tj	�|�
�dS)zM
        {'type': ['string', 'list'],
         'check_with': 'type'}
        NZ
validate_type)rRr
r�rIZincluded_typesZexcluded_typesr�rjrZBAD_TYPEr�)	rZ	data_typerrr�Z_typeZtype_definitionZmatchedZtype_handlerrrr�_validate_types$��	zBareValidator._validate_typecsr|df}t|t�rn|j||t�fdd�|D��d�}|||jdd�|jrn|�|jgdg�|�|tj	|j�dS)	r)r�c3s|]}|�fVqdSr�rr�r�rrr�-sz6BareValidator._validate_valuesrules.<locals>.<genexpr>r�FrrdN)
rRrr{r1rEr=r�rjrZVALUESRULES)rr8rrrzr�rr�r�_validate_valuesrules"s
�z#BareValidator._validate_valuesrules)NN)N)NF)NFT)rr%r&r'r r�r�r�bytes�	bytearrayr�rr
rrrr2r	rr6r�r^rL�staticmethodrFrH�classmethodrbrjr{r�r�r�rnro�propertyr9r�r:rrUrsr�rVrWrtrurvrrwr8rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��__call__r�r�r�r"Z_validate_allow_unknownr�rrrrrrrrrrrrrrr r!r#�_validate_metar%r(r+r�r2Z_validate_requiredZ_validate_require_allr�r8r7r6r9r:�
__classcell__rrrOrr)Es/�3

Q
/
	
	









	















!

+
**�


$"r)z7The rule's arguments are validated against this schema:cs4eZdZdZ�fdd�Z�fdd�Zdd�Z�ZS)�InspectedValidatorzMetaclass for all validatorscs>d|dkr(|d�d|ddji�tt|�j|f|��S)Nr rdrcr)rEr rKrC�__new__)rarMrOrrrD;szInspectedValidator.__new__cs�fdd�}tt��j|�di�_�_|d�D]@}|�d�r^�j|td�d�f7_q2��d|��j|<q2�jr�tdt	�t
dd	�|d
�D��t
dd	�|d�D���_�jd
d}�j|d
ddd
d<|dd<dd	��jD�D]}d�j|d<q�ddi�_
�_�_|d�D]n}|�d��rV�j
|td�d�f7_
n>|�d��r��j|td�d�f7_n��d|��j|<�q(dD]:}�j|d}�j
|d
ddd
d<|dd<�q��j�jddd
d<i�_�j��j��j��j�dS)Ncst�fdd�t��D��S)Nc3s4|],}|�d�d�r|t��dd�VqdS)r}rdN)r�rYr���prefixrrr�Bs�zNInspectedValidator.__init__.<locals>.attributes_with_prefix.<locals>.<genexpr>)rS�dirrEr`rEr�attributes_with_prefixAs�z;InspectedValidator.__init__.<locals>.attributes_with_prefixrr�Ztype_Z
_validate_z}Methods for type testing are deprecated, use TypeDefinition and the 'types_mapping'-property of a Validator-instance instead.css|]
}|VqdSr�rr�rrrr�^sz.InspectedValidator.__init__.<locals>.<genexpr>r�r�rrcr8rrdcss|]}|dkr|VqdS)r*Nrr�rrrr�dsTrer�Zcoerce_Zdefault_setter_Z_normalize_)r�r�r�)rKrCrLr�Zvalidation_rulesr�rY�$_InspectedValidator__get_rule_schemarrrSZcheckersr�ZcoercersZdefault_settersr�r�rE)rarMrHZ	attributer�rlrOr`rrL@sP
���&�*��zInspectedValidator.__init__cCs�t||�j}|dkri}n@t|kr0|�t�d}zt|���}Wntk
rXi}YnX|s~|dkr~td|�dd�d�|S)NrcrAz>No validation schema is defined for the arguments of rule '%s'r}rdr�)r�r �RULE_SCHEMA_SEPARATORr�r�stripr�r)raZmethod_nameZ	docstringr�rrrZ__get_rule_schema}s 
��z$InspectedValidator.__get_rule_schema)r%r&r'r rDrLrIrBrrrOrrC8s=rC�	Validator)+r Z
__future__rZastrrrrr.�warningsrZcerberusrZcerberus.platformr	r
rrr
rrrZcerberus.schemarrrrZcerberus.utilsrrrZToyErrorHandlerrxr"r�r#r(�objectr)rJr,rCrLrrrr�<module>s:
(

	{Z

Filemanager

Name Type Size Permission Actions
__init__.cpython-38.opt-1.pyc File 826 B 0644
__init__.cpython-38.pyc File 826 B 0644
errors.cpython-38.opt-1.pyc File 20.44 KB 0644
errors.cpython-38.pyc File 20.44 KB 0644
platform.cpython-38.opt-1.pyc File 793 B 0644
platform.cpython-38.pyc File 793 B 0644
schema.cpython-38.opt-1.pyc File 17.55 KB 0644
schema.cpython-38.pyc File 17.55 KB 0644
utils.cpython-38.opt-1.pyc File 3.76 KB 0644
utils.cpython-38.pyc File 3.76 KB 0644
validator.cpython-38.opt-1.pyc File 50.99 KB 0644
validator.cpython-38.pyc File 50.99 KB 0644