• File: exceptions.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/jsonschema/__pycache__/exceptions.cpython-37.pyc
  • Date Modified: 07/08/2021 10:56 AM
  • File size: 11.71 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

`(@sdZddlmZmZddlZddlZddlZddlZddlm	Z	ddl
mZmZe
ddgZe
Ze	ZGdd	d	eZGd
ddeZGdd
d
eZejddGdddeZGdddeZGdddeZGdddeZGdddeZeefddZeZefddZdS)z2
Validation errors, and some surrounding helpers.
)defaultdictdequeN)_utils)PY3	iteritemsZanyOfZoneOfc	seZdZedddeeeddf	fdd	ZddZddZerBeZnd	d
Ze	ddZ
ed
dZeddZ
ddZddZZS)_ErrorNcstt||||||||||	|

||_t||_|_t|	|_|_t	||_
||_|_||_
||_||_||_|
|_x|D]
}||_qWdS)N)superr__init__messagerpath
relative_pathschema_pathrelative_schema_pathlistcontextcause	__cause__	validatorvalidator_valueinstanceschemaparent)selfrrrrrrrrrrerror)	__class__rF/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|Dr,|jStj|jdd}tj|jdd}|jt	d
|j|jt
t|jddt||jt
|jt|fS)Ncss|]}|tkVqdS)N)_unset).0mrrr	<genexpr>Dsz%_Error.__unicode__.<locals>.<genexpr>H)widthzl

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

            On %s%s:
            %s
            )rrrranyrpprintpformattextwrapdedentrstrip!_word_for_schema_in_error_messagerZformat_as_indexrrindent#_word_for_instance_in_error_messager
)rZessential_for_verbosepschema	pinstancerrr__unicode__@s
z_Error.__unicode__cCst|dS)Nzutf-8)unicodeencode)rrrr__str__^sz_Error.__str__cCs|f|S)N)	_contents)clsotherrrrcreate_fromasz_Error.create_fromcCs2|j}|dkr|jSt|j}|t|j|S)N)rr
r
extendleftreversed
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)rgetattrrsetattr)rkwargskvrrr_setysz_Error._setcsd}tfdd|DS)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
rr1rr4classmethodr8propertyr;r<rBr5
__classcell__rr)rrrs&

rc@seZdZdZdZdZdS)ValidationErrorz:
    An instance was invalid under a provided schema.
    rrN)rrErF__doc__r,r.rrrrrJsrJc@seZdZdZdZdZdS)SchemaErrorzB
    A schema was invalid under its corresponding metaschema.
    Z
metaschemarN)rrErFrKr,r.rrrrrLsrLT)hashc@s eZdZdZeZddZdS)RefResolutionErrorz&
    A ref could not be resolved.
    cCs
t|jS)N)str_cause)rrrrr4szRefResolutionError.__str__N)rrErFrKrCZibrPr4rrrrrNsrNc@s2eZdZdZddZddZer&eZnddZdS)	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)rrrrr1szUndefinedTypeCheck.__unicode__cCst|dS)Nzutf-8)r2r3)rrrrr4szUndefinedTypeCheck.__str__N)rrErFrKr
r1rr4rrrrrQsrQc@s2eZdZdZddZddZer&eZnddZdS)	UnknownTypezP
    A validator was asked to validate an instance against an unknown type.
    cCs||_||_||_dS)N)rRrr)rrRrrrrrr
szUnknownType.__init__cCsFtj|jdd}tj|jdd}td|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/r0rrrr1s
zUnknownType.__unicode__cCst|dS)Nzutf-8)r2r3)rrrrr4szUnknownType.__str__N)rrErFrKr
r1rr4rrrrrSsrScs<eZdZdZd	fdd	ZddZer,eZnddZZS)
FormatErrorz%
    Validating a format failed.
    Ncs(tt|||||_||_|_dS)N)r	rTr
rrr)rrr)rrrr
szFormatError.__init__cCs|jS)N)r)rrrrr1szFormatError.__unicode__cCs|jdS)Nzutf-8)rr3)rrrrr4szFormatError.__str__)N)	rrErFrKr
r1rr4rIrr)rrrTsrTc@sZeZdZdZeZdddZddZddZd	d
Z	ddZ
d
dZddZe
ddZdS)	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)rindexrrr__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)rrXvaluerrr__setitem__szErrorTree.__setitem__cCs
t|jS)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)>)rrlen)rrrrr"szErrorTree.__repr__cCs&tddt|jD}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_rrrrrUs
rUcsfdd}|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)strongweakrr	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]nextmax	itertoolschainrmin)rVrhZbestrrr
best_matchHs&
rn) rKcollectionsrrrkr'r)rCZ
jsonschemarZjsonschema.compatrr	frozensetZWEAK_MATCHESZSTRONG_MATCHESZUnsetr	ExceptionrrJrLsrNrQrSrTobjectrUrgrfrnrrrr<module>s,q		H