AlkantarClanX12

Your IP : 18.222.163.134


Current Path : /opt/alt/python37/lib/python3.7/site-packages/jsonschema/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jsonschema/__pycache__/exceptions.cpython-37.pyc

B

�pSe�(�@sdZddlmZmZddlZddlZddlZddlZddlm	Z	ddl
mZmZe
ddg�Ze
�Ze	��ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Zejdd�Gdd�de��ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zeefdd�Ze�Zefdd�ZdS)z2
Validation errors, and some surrounding helpers.
�)�defaultdict�dequeN)�_utils)�PY3�	iteritemsZanyOf�oneOfc	s�eZdZedddeeeddf	�fdd�	Zdd�Zdd�ZerBeZnd	d
�Ze	dd��Z
ed
d��Zedd��Z
dd�Zdd�Z�ZS)�_Error�Ncs�tt|��|||||||||	|
�
||_t|�|_|_t|	�|_|_t	|�|_
||_|_||_
||_||_||_|
|_x|D]
}||_q�WdS)N)�superr�__init__�messager�path�
relative_path�schema_path�relative_schema_path�list�context�cause�	__cause__�	validator�validator_value�instance�schema�parent)�selfrrr
rrrrrrr�error)�	__class__r	�F/opt/alt/python37/lib/python3.7/site-packages/jsonschema/exceptions.pyrs.


z_Error.__init__cCsd|jj|jfS)Nz<%s: %r>)r�__name__r)rr	r	r�__repr__=sz_Error.__repr__cCs�|j|j|j|jf}tdd�|D��r,|jStj|jdd�}tj|jdd�}|jt�	d�
��|j|jt�
t|j�dd��t�|�|jt�
|j�t�|�fS)Ncss|]}|tkVqdS)N)�_unset)�.0�mr	r	r�	<genexpr>Dsz%_Error.__unicode__.<locals>.<genexpr>�H)�widthzl

            Failed validating %r in %s%s:
            %s

            On %s%s:
            %s
            ���)rrrr�anyr�pprint�pformat�textwrap�dedent�rstrip�!_word_for_schema_in_error_messagerZformat_as_indexrr�indent�#_word_for_instance_in_error_messager)rZessential_for_verbose�pschema�	pinstancer	r	r�__unicode__@s
z_Error.__unicode__cCst|��d�S)Nzutf-8)�unicode�encode)rr	r	r�__str__^sz_Error.__str__cCs|f|���S)N)�	_contents)�cls�otherr	r	r�create_fromasz_Error.create_fromcCs2|j}|dkr|jSt|j�}|�t|j��|S)N)rrr�
extendleft�reversed�
absolute_path)rrr
r	r	rr<es
z_Error.absolute_pathcCs2|j}|dkr|jSt|j�}|�t|j��|S)N)rrrr:r;�absolute_schema_path)rrr
r	r	rr=os
z_Error.absolute_schema_pathcKs4x.t|�D]"\}}t||�tkr
t|||�q
WdS)N)r�getattrr �setattr)r�kwargs�k�vr	r	r�_setysz_Error._setcsd}t�fdd�|D��S)N)
rrrrrr
rrrrc3s|]}|t�|�fVqdS)N)r>)r!�attr)rr	rr#�sz#_Error._contents.<locals>.<genexpr>)�dict)r�attrsr	)rrr6~sz_Error._contents)r�
__module__�__qualname__r rrr2rr5�classmethodr9�propertyr<r=rCr6�
__classcell__r	r	)rrrs&

rc@seZdZdZdZdZdS)�ValidationErrorz:
    An instance was invalid under a provided schema.
    rrN)rrGrH�__doc__r-r/r	r	r	rrL�srLc@seZdZdZdZdZdS)�SchemaErrorzB
    A schema was invalid under its corresponding metaschema.
    Z
metaschemarN)rrGrHrMr-r/r	r	r	rrN�srNT)�hashc@s eZdZdZe��Zdd�ZdS)�RefResolutionErrorz&
    A ref could not be resolved.
    cCs
t|j�S)N)�str�_cause)rr	r	rr5�szRefResolutionError.__str__N)rrGrHrMrDZibrRr5r	r	r	rrP�srPc@s2eZdZdZdd�Zdd�Zer&eZndd�ZdS)	�UndefinedTypeCheckzN
    A type checker was asked to check a type it did not have registered.
    cCs
||_dS)N)�type)rrTr	r	rr�szUndefinedTypeCheck.__init__cCs
d|jS)Nz'Type %r is unknown to this type checker)rT)rr	r	rr2�szUndefinedTypeCheck.__unicode__cCst|��d�S)Nzutf-8)r3r4)rr	r	rr5�szUndefinedTypeCheck.__str__N)rrGrHrMrr2rr5r	r	r	rrS�srSc@s2eZdZdZdd�Zdd�Zer&eZndd�ZdS)	�UnknownTypezP
    A validator was asked to validate an instance against an unknown type.
    cCs||_||_||_dS)N)rTrr)rrTrrr	r	rr�szUnknownType.__init__cCsFtj|jdd�}tj|jdd�}t�d���|jt�	|�t�	|�fS)Nr$)r%z�
            Unknown type %r for validator with schema:
            %s

            While checking instance:
            %s
            )
r(r)rrr*r+r,rTrr.)rr0r1r	r	rr2�s
zUnknownType.__unicode__cCst|��d�S)Nzutf-8)r3r4)rr	r	rr5�szUnknownType.__str__N)rrGrHrMrr2rr5r	r	r	rrU�srUcs<eZdZdZd	�fdd�	Zdd�Zer,eZndd�Z�ZS)
�FormatErrorz%
    Validating a format failed.
    Ncs(tt|��||�||_||_|_dS)N)r
rVrrrr)rrr)rr	rr�szFormatError.__init__cCs|jS)N)r)rr	r	rr2�szFormatError.__unicode__cCs|j�d�S)Nzutf-8)rr4)rr	r	rr5�szFormatError.__str__)N)	rrGrHrMrr2rr5rKr	r	)rrrV�srVc@sZeZdZdZeZddd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Ze
dd��ZdS)�	ErrorTreezF
    ErrorTrees make it easier to check which validations failed.
    r	cCsTi|_t|j�|_x<|D]4}|}x|jD]}||}q(W||j|j<|j|_qWdS)N)�errorsrrr6r
rr�	_instance)rrXrZ	container�elementr	r	rr�s
zErrorTree.__init__cCs
||jkS)zC
        Check whether ``instance[index]`` has any errors.
        )r6)r�indexr	r	r�__contains__�szErrorTree.__contains__cCs&|jtk	r||kr|j||j|S)a\
        Retrieve the child tree one level down at the given ``index``.

        If the index is not in the instance that this tree corresponds to and
        is not known by this tree, whatever error would be raised by
        ``instance.__getitem__`` will be propagated (usually this is some
        subclass of `exceptions.LookupError`.
        )rYr r6)rr[r	r	r�__getitem__s

zErrorTree.__getitem__cCs||j|<dS)zB
        Add an error to the tree at the given ``index``.
        N)r6)rr[�valuer	r	r�__setitem__szErrorTree.__setitem__cCs
t|j�S)zY
        Iterate (non-recursively) over the indices in the instance with errors.
        )�iterr6)rr	r	r�__iter__szErrorTree.__iter__cCs|jS)z,
        Return the `total_errors`.
        )�total_errors)rr	r	r�__len__szErrorTree.__len__cCsd|jjt|�fS)Nz<%s (%s total errors)>)rr�len)rr	r	rr"szErrorTree.__repr__cCs&tdd�t|j�D��}t|j�|S)zT
        The total number of errors in the entire tree, including children.
        css|]\}}t|�VqdS)N)rd)r!�_�treer	r	rr#+sz)ErrorTree.total_errors.<locals>.<genexpr>)�sumrr6rdrX)rZchild_errorsr	r	rrb%szErrorTree.total_errorsN)r	)rrGrHrMr rYrr\r]r_rarcrrJrbr	r	r	rrW�s
rWcs��fdd�}|S)aq
    Create a key function that can be used to sort errors by relevance.

    Arguments:
        weak (set):
            a collection of validator names to consider to be "weak".
            If there are two errors at the same level of the instance
            and one is in the set of weak validator names, the other
            error will take priority. By default, :validator:`anyOf` and
            :validator:`oneOf` are considered weak validators and will
            be superseded by other same-level validation errors.

        strong (set):
            a collection of validator names to consider to be "strong"
    cs |j}t|j�|�k|�kfS)N)rrdr
)rr)�strong�weakr	r�	relevance?szby_relevance.<locals>.relevancer	)rirhrjr	)rhrir�by_relevance/srkcCsRt|�}t|d�}|dkrdStt�|g|�|d�}x|jrLt|j|d�}q6W|S)a�
    Try to find an error that appears to be the best match among given errors.

    In general, errors that are higher up in the instance (i.e. for which
    `ValidationError.path` is shorter) are considered better matches,
    since they indicate "more" is wrong with the instance.

    If the resulting match is either :validator:`oneOf` or :validator:`anyOf`,
    the *opposite* assumption is made -- i.e. the deepest error is picked,
    since these validators only need to match once, and any other errors may
    not be relevant.

    Arguments:
        errors (collections.Iterable):

            the errors to select from. Do not provide a mixture of
            errors from different validation attempts (i.e. from
            different instances or schemas), since it won't produce
            sensical output.

        key (collections.Callable):

            the key to use when sorting errors. See `relevance` and
            transitively `by_relevance` for more details (the default is
            to sort with the defaults of that function). Changing the
            default is only useful if you want to change the function
            that rates errors but still want the error context descent
            done by this function.

    Returns:
        the best matching error, or ``None`` if the iterable was empty

    .. note::

        This function is a heuristic. Its return value may change for a given
        set of inputs from version to version if better heuristics are added.
    N)�key)r`�next�max�	itertools�chainr�min)rXrl�bestr	r	r�
best_matchHs&
rs) rM�collectionsrrror(r*rDZ
jsonschemarZjsonschema.compatrr�	frozensetZWEAK_MATCHESZSTRONG_MATCHESZUnsetr �	ExceptionrrLrN�srPrSrUrV�objectrWrkrjrsr	r	r	r�<module>s,q		H