ok

Mini Shell

Direktori : /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

���`�(�@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�	iteritemsZanyOfZoneOfc	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)�selfrrrrrrrrrr�error)�	__class__r�F/opt/alt/python37/lib/python3.7/site-packages/jsonschema/exceptions.pyr
s.


z_Error.__init__cCsd|jj|jfS)Nz<%s: %r>)r�__name__r)rrrr�__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�mrrr�	<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�	pinstancerrr�__unicode__@s
z_Error.__unicode__cCst|��d�S)Nzutf-8)�unicode�encode)rrrr�__str__^sz_Error.__str__cCs|f|���S)N)�	_contents)�cls�otherrrr�create_fromasz_Error.create_fromcCs2|j}|dkr|jSt|j�}|�t|j��|S)N)rr
r�
extendleft�reversed�
absolute_path)rrrrrrr;es
z_Error.absolute_pathcCs2|j}|dkr|jSt|j�}|�t|j��|S)N)rrrr9r:�absolute_schema_path)rrrrrrr<os
z_Error.absolute_schema_pathcKs4x.t|�D]"\}}t||�tkr
t|||�q
WdS)N)r�getattrr�setattr)r�kwargs�k�vrrr�_setysz_Error._setcsd}t�fdd�|D��S)N)
rrrrrrrrrrc3s|]}|t�|�fVqdS)N)r=)r �attr)rrrr"�sz#_Error._contents.<locals>.<genexpr>)�dict)rZattrsr)rrr5~sz_Error._contents)r�
__module__�__qualname__rr
rr1rr4�classmethodr8�propertyr;r<rBr5�
__classcell__rr)rrrs&

rc@seZdZdZdZdZdS)�ValidationErrorz:
    An instance was invalid under a provided schema.
    rrN)rrErF�__doc__r,r.rrrrrJ�srJc@seZdZdZdZdZdS)�SchemaErrorzB
    A schema was invalid under its corresponding metaschema.
    Z
metaschemarN)rrErFrKr,r.rrrrrL�srLT)�hashc@s eZdZdZe��Zdd�ZdS)�RefResolutionErrorz&
    A ref could not be resolved.
    cCs
t|j�S)N)�str�_cause)rrrrr4�szRefResolutionError.__str__N)rrErFrKrCZibrPr4rrrrrN�srNc@s2eZdZdZdd�Zdd�Zer&eZndd�ZdS)	�UndefinedTypeCheckzN
    A type checker was asked to check a type it did not have registered.
    cCs
||_dS)N)�type)rrRrrrr
�szUndefinedTypeCheck.__init__cCs
d|jS)Nz'Type %r is unknown to this type checker)rR)rrrrr1�szUndefinedTypeCheck.__unicode__cCst|��d�S)Nzutf-8)r2r3)rrrrr4�szUndefinedTypeCheck.__str__N)rrErFrKr
r1rr4rrrrrQ�srQc@s2eZdZdZdd�Zdd�Zer&eZndd�ZdS)	�UnknownTypezP
    A validator was asked to validate an instance against an unknown type.
    cCs||_||_||_dS)N)rRrr)rrRrrrrrr
�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+rRrr-)rr/r0rrrr1�s
zUnknownType.__unicode__cCst|��d�S)Nzutf-8)r2r3)rrrrr4�szUnknownType.__str__N)rrErFrKr
r1rr4rrrrrS�srScs<eZdZdZd	�fdd�	Zdd�Zer,eZndd�Z�ZS)
�FormatErrorz%
    Validating a format failed.
    Ncs(tt|��||�||_||_|_dS)N)r	rTr
rrr)rrr)rrrr
�szFormatError.__init__cCs|jS)N)r)rrrrr1�szFormatError.__unicode__cCs|j�d�S)Nzutf-8)rr3)rrrrr4�szFormatError.__str__)N)	rrErFrKr
r1rr4rIrr)rrrT�srTc@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.
    rcCsTi|_t|j�|_x<|D]4}|}x|jD]}||}q(W||j|j<|j|_qWdS)N)�errorsrrr5rrr�	_instance)rrVrZ	containerZelementrrrr
�s
zErrorTree.__init__cCs
||jkS)zC
        Check whether ``instance[index]`` has any errors.
        )r5)r�indexrrr�__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`.
        )rWrr5)rrXrrr�__getitem__s

zErrorTree.__getitem__cCs||j|<dS)zB
        Add an error to the tree at the given ``index``.
        N)r5)rrX�valuerrr�__setitem__szErrorTree.__setitem__cCs
t|j�S)zY
        Iterate (non-recursively) over the indices in the instance with errors.
        )�iterr5)rrrr�__iter__szErrorTree.__iter__cCs|jS)z,
        Return the `total_errors`.
        )�total_errors)rrrr�__len__szErrorTree.__len__cCsd|jjt|�fS)Nz<%s (%s total errors)>)rr�len)rrrrr"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)ra)r �_Ztreerrrr"+sz)ErrorTree.total_errors.<locals>.<genexpr>)�sumrr5rarV)rZchild_errorsrrrr_%szErrorTree.total_errorsN)r)rrErFrKrrWr
rYrZr\r^r`rrHr_rrrrrU�s
rUcs��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)rrar)rr)�strong�weakrr�	relevance?szby_relevance.<locals>.relevancer)rerdrfr)rdrer�by_relevance/srgcCsRt|�}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)rVrhZbestrrr�
best_matchHs&
rn) rK�collectionsrrrkr'r)rCZ
jsonschemarZjsonschema.compatrr�	frozensetZWEAK_MATCHESZSTRONG_MATCHESZUnsetr�	ExceptionrrJrL�srNrQrSrT�objectrUrgrfrnrrrr�<module>s,q		H

Zerion Mini Shell 1.0