AlkantarClanX12

Your IP : 3.145.56.150


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__/validators.cpython-37.pyc

B

�pSe�r�#@s�dZddlmZddlmZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZddlmZmZmZmZmZmZmZmZmZmZddlmZeGd	d
�d
e�ZiZe
� �Z!d/dd
�Z"e#e$ee%d�ej&e'ed�Z(ej)e"e(�d�Z*dd�Z+dd�Z,Gdd�de%�Z-dd�Z.dddde.fdd�Z/d0dd�Z0e/e
�1d�ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFd�ejGddd�d �ZHe/e
�1d!�ej2ej3ej4ejIejJejKej8ej:ej;ej<ej=ejLej>ej?ej@ejMejAej7ejNejOejBejCejPejQej%ejFd"�ejRd!d#d�d �ZSe/e
�1d$�ej2ej3ej4ejIejJejTejUejKej8ejVejWej:ejXej<ej=ejLejYej?ej@ejMejZej7ejNejOejBejCejPej[ejQej%ejFd%�ej\d$d&�Z]e/e
�1d'�ej2ej3ej4ejIejJejTejUejKej8ejVejWej:ej^ejXej<ej=ejLejYej?ej@ejMejZej7ejOejNejBejCejPej[ejQej%ejFd(� ej_d'd&�Z`e`ZaGd)d*�d*eb�Zcd1d+d,�Zdeafd-d.�ZedS)2zQ
Creation and extension of validators, with implementations for existing drafts.
�)�division)�warnN)�
add_metaclass)�_legacy_validators�_types�_utils�_validators�
exceptions)
�Sequence�	int_types�	iteritems�	lru_cache�	str_types�unquote�	urldefrag�urljoin�urlopen�urlsplit)�	ErrorTreec@seZdZdZdd�ZdS)�_DontDoThatz�
    Raised when a Validators with non-default type checker is misused.

    Asking one for DEFAULT_TYPES doesn't make sense, since type checkers
    exist for the unrepresentable cases where DEFAULT_TYPES can't
    represent the type relationship.
    cCsdS)Nz=DEFAULT_TYPES cannot be used on Validators using TypeCheckers�)�selfrr�F/opt/alt/python37/lib/python3.7/site-packages/jsonschema/validators.py�__str__1sz_DontDoThat.__str__N)�__name__�
__module__�__qualname__�__doc__rrrrrr(srrcCs:t|�}dd�}i}x t|�D]\}}||�||<qW|S)a
    Generate newer-style type checks out of JSON-type-name-to-type mappings.

    Arguments:

        types (dict):

            A mapping of type names to their Python types

    Returns:

        A dictionary of definitions to pass to `TypeChecker`
    cst�����fdd�}|S)Ncs t|t�rt�krdSt|��S)NF)�
isinstance�bool)Zchecker�instance)�pytypesrr�
type_checkLs
zH_generate_legacy_type_checks.<locals>.gen_type_check.<locals>.type_check)r�flatten)r!r"r)r!r�gen_type_checkIs
z4_generate_legacy_type_checks.<locals>.gen_type_check)�dictr)�typesr$�definitions�typenamer!rrr�_generate_legacy_type_checks9sr))�arrayZboolean�integer�null�number�object�string)�
type_checkerscs�fdd�}|S)a�
    Register the decorated validator for a ``version`` of the specification.

    Registered validators and their meta schemas will be considered when
    parsing ``$schema`` properties' URIs.

    Arguments:

        version (str):

            An identifier to use as the version's name

    Returns:

        collections.Callable:

            a class decorator to decorate the validator with the version
    cs$|t�<|�|j�}|r |t|<|S)N)�
validators�ID_OF�META_SCHEMA�meta_schemas)�clsZmeta_schema_id)�versionrr�
_validates}s
zvalidates.<locals>._validatesr)r6r7r)r6r�	validatesisr8cCs$|jdkrt��tdtdd�|jS)NzcThe DEFAULT_TYPES attribute is deprecated. See the type checker attached to this validator instead.�)�
stacklevel)�_CREATED_WITH_DEFAULT_TYPESrr�DeprecationWarning�_DEFAULT_TYPES)rrrrr=�s
r=c@seZdZee�ZdS)�!_DefaultTypesDeprecatingMetaClassN)rrr�propertyr=�
DEFAULT_TYPESrrrrr>�sr>cCs |dks|dkrdS|�dd�S)NTF�z$id)�get)�schemarrr�_id_of�srDcs��dk	r<�dk	rtd��d�tdtdd�tjt��d��n(t��dkrRd�t�n�tkr`d�nd�tt	�G������fd	d
�d
t
��}|dk	r�t|�|�}|���
dd�d
|_|S)
a�
    Create a new validator class.

    Arguments:

        meta_schema (collections.Mapping):

            the meta schema for the new validator class

        validators (collections.Mapping):

            a mapping from names to callables, where each callable will
            validate the schema property with the given name.

            Each callable should take 4 arguments:

                1. a validator instance,
                2. the value of the property being validated within the
                   instance
                3. the instance
                4. the schema

        version (str):

            an identifier for the version that this validator class will
            validate. If provided, the returned validator class will
            have its ``__name__`` set to include the version, and also
            will have `jsonschema.validators.validates` automatically
            called for the given version.

        type_checker (jsonschema.TypeChecker):

            a type checker, used when applying the :validator:`type` validator.

            If unprovided, a `jsonschema.TypeChecker` will be created
            with a set of default types typical of JSON Schema drafts.

        default_types (collections.Mapping):

            .. deprecated:: 3.0.0

                Please use the type_checker argument instead.

            If set, it provides mappings of JSON types to Python types
            that will be converted to functions and redefined in this
            object's `jsonschema.TypeChecker`.

        id_of (collections.Callable):

            A function that given a schema, returns its ID.

    Returns:

        a new `jsonschema.IValidator` class
    Nz;Do not specify default_types when providing a type checker.TzPThe default_types argument is deprecated. Use the type_checker argument instead.r9)r:)r0Fcs�eZdZe��Ze��Z�Ze��Ze	e
�Ze��Z
�Zd�fdd�	Z
edd��Zd�fdd�	Zdd	d
�Zdd�Zd
d�Zddd�ZdS)zcreate.<locals>.ValidatorrNcsP|r$tdtdd�|j�t|��|_|dkr:tj|�d�}||_||_||_	dS)NzaThe types argument is deprecated. Provide a type_checker to jsonschema.validators.extend instead.r9)r:)�id_of)
rr<�TYPE_CHECKERZ
redefine_manyr)�RefResolver�from_schema�resolver�format_checkerrC)rrCr&rIrJ)rErr�__init__sz"create.<locals>.Validator.__init__cSs*x$||j��|�D]}tj�|��qWdS)N)r3�iter_errorsr	ZSchemaErrorZcreate_from)r5rC�errorrrr�check_schema#sz&create.<locals>.Validator.check_schemac3s|dkr|j}|dkrdS|dkrBtjd|fdd||d�VdS�|�}|rZ|j�|�z�|�d�}|dk	rzd|fg}nt|�}xr|D]j\}}|j�|�}|dkr�q�|||||�p�d}	x8|	D]0}
|
j||||d�|dkr�|
j	�
|�|
Vq�Wq�WWd|�r
|j��XdS)NTFzFalse schema does not allow %r)�	validatorZvalidator_valuer rCz$refr)rCr	ZValidationErrorrI�
push_scoperBr�
VALIDATORSZ_set�schema_path�
appendleft�	pop_scope)rr �_schema�scope�refr1�k�vrO�errorsrM)rErrrL(sH


z%create.<locals>.Validator.iter_errorscssHxB|�||�D]2}|dk	r&|j�|�|dk	r:|j�|�|VqWdS)N)rL�pathrSrR)rr rCr[rRrMrrr�descendWsz!create.<locals>.Validator.descendc_sx|j||�D]}|�qWdS)N)rL)r�args�kwargsrMrrr�validate_sz"create.<locals>.Validator.validatecSs:y|j�||�Stjk
r4t�|||j��YnXdS)N)rF�is_typer	ZUndefinedTypeCheckZUnknownTyperC)rr �typerrrr`csz!create.<locals>.Validator.is_typecSst|�||�d�}|dkS)N)�nextrL)rr rUrMrrr�is_validisz"create.<locals>.Validator.is_valid)rNN)N)NN)N)rrrr%rQr3rF�staticmethodr2r?r=r@r;rK�classmethodrNrLr\r_r`rcr)�_created_with_default_types�
default_typesrE�meta_schema�type_checkerr1rr�	Validator�s /
rj� rA)�	TypeErrorrr<r�TypeCheckerr)�_DEPRECATED_DEFAULT_TYPES�*_TYPE_CHECKER_FOR_DEPRECATED_DEFAULT_TYPESrr>r.r8�title�replacer)rhr1r6rgrirErjr)rfrgrErhrir1r�create�s0@rrrcCsHt|j�}|�|�|dkr$|j}n|jr2td��t|j||||jd�S)a�
    Create a new validator class by extending an existing one.

    Arguments:

        validator (jsonschema.IValidator):

            an existing validator class

        validators (collections.Mapping):

            a mapping of new validator callables to extend with, whose
            structure is as in `create`.

            .. note::

                Any validator callables with the same name as an
                existing one will (silently) replace the old validator
                callable entirely, effectively overriding any validation
                done in the "parent" validator class.

                If you wish to instead extend the behavior of a parent's
                validator callable, delegate and call it directly in
                the new validator function by retrieving it using
                ``OldValidator.VALIDATORS["validator_name"]``.

        version (str):

            a version for the new validator class

        type_checker (jsonschema.TypeChecker):

            a type checker, used when applying the :validator:`type` validator.

            If unprovided, the type checker of the extended
            `jsonschema.IValidator` will be carried along.`

    Returns:

        a new `jsonschema.IValidator` class extending the one provided

    .. note:: Meta Schemas

        The new validator class will have its parent's meta schema.

        If you wish to change or extend the meta schema in the new
        validator class, modify ``META_SCHEMA`` directly on the returned
        class. Note that no implicit copying is done, so a copy should
        likely be made before modifying it, in order to not affect the
        old validator.
    Nz�Cannot extend a validator created with default_types with a type_checker. Update the validator to use a type_checker when created.)rhr1r6rirE)	r%rQ�updaterFr;rlrrr3r2)rOr1r6riZall_validatorsrrr�extendts5

rtZdraft3)z$ref�additionalItems�additionalProperties�dependenciesZdisallowZdivisibleBy�enumZextends�format�items�maxItems�	maxLength�maximum�minItems�	minLength�minimum�pattern�patternProperties�
propertiesra�uniqueItemscCs|�dd�S)N�idrA)rB)rCrrr�<lambda>��r�)rhr1rir6rEZdraft4)z$refrurv�allOf�anyOfrwrxryrzr{r|�
maxPropertiesr}r~r�
minPropertiesr��
multipleOf�not�oneOfr�r�r��requiredrar�cCs|�dd�S)Nr�rA)rB)rCrrrr��r�Zdraft6)z$refrurvr�r��const�containsrwrx�exclusiveMaximum�exclusiveMinimumryrzr{r|r�r}r~rr�r�r�r�r�r�r�r��
propertyNamesr�rar�)rhr1rir6Zdraft7) z$refrurvr�r�r�r�rwrxr�r�ry�ifrzr{r|r�r}r~rr�r�r�r�r�r�r�r�r�r�rar�c@s�eZdZdZddd�Zeefdd��Zd	d
�Zdd�Z	e
d
d��Ze
dd��Ze
jdd��Ze
jdd��Zdd�Zdd�Zdd�Zdd�ZdS)rGa�
    Resolve JSON References.

    Arguments:

        base_uri (str):

            The URI of the referring document

        referrer:

            The actual referring document

        store (dict):

            A mapping from URIs to documents to cache

        cache_remote (bool):

            Whether remote refs should be cached after first resolution

        handlers (dict):

            A mapping from URI schemes to functions that should be used
            to retrieve them

        urljoin_cache (:func:`functools.lru_cache`):

            A cache that will be used for caching the results of joining
            the resolution scope to subscopes.

        remote_cache (:func:`functools.lru_cache`):

            A cache that will be used for caching the results of
            resolved remote URLs.

    Attributes:

        cache_remote (bool):

            Whether remote refs should be cached after first resolution
    rTNcCs�|dkrtd�t�}|dkr*td�|j�}||_||_t|�|_|g|_t�	dd�t
t�D��|_|j�
|�||j|<||_||_dS)Nicss|]\}}||jfVqdS)N)r3)�.0r�rOrrr�	<genexpr>�sz'RefResolver.__init__.<locals>.<genexpr>)r
r�resolve_from_url�referrer�cache_remoter%�handlers�
_scopes_stackr�URIDictrr4�storers�_urljoin_cache�
_remote_cache)r�base_urir�r�r�r�Z
urljoin_cacheZremote_cacherrrrK|s


zRefResolver.__init__cOs||||�|d�|��S)z�
        Construct a resolver from a JSON schema object.

        Arguments:

            schema:

                the referring schema

        Returns:

            `RefResolver`
        )r�r�r)r5rCrEr]r^rrrrH�szRefResolver.from_schemacCs|j�|�|j|��dS)z�
        Enter a given sub-scope.

        Treats further dereferences as being performed underneath the
        given scope.
        N)r��appendr��resolution_scope)rrVrrrrP�szRefResolver.push_scopecCs2y|j��Wntk
r,t�d��YnXdS)z�
        Exit the most recent entered scope.

        Treats further dereferences as being performed underneath the
        original scope.

        Don't call this method more times than `push_scope` has been
        called.
        znFailed to pop the scope from an empty stack. `pop_scope()` should only be called once for every `push_scope()`N)r��pop�
IndexErrorr	�RefResolutionError)rrrrrT�s

zRefResolver.pop_scopecCs
|jdS)z8
        Retrieve the current resolution scope.
        ���)r�)rrrrr��szRefResolver.resolution_scopecCst|j�\}}|S)zL
        Retrieve the current base URI, not including any fragment.
        )rr�)r�uri�_rrrr��szRefResolver.base_uriccs$|�|�z
dVWd|��XdS)zT
        Temporarily enter the given scope for the duration of the context.
        N)rPrT)rrVrrr�in_scope�s

zRefResolver.in_scopeccs2|�|�\}}|�|�z
|VWd|��XdS)z�
        Resolve the given ``ref`` and enter its resolution scope.

        Exits the scope on exit of this context manager.

        Arguments:

            ref (str):

                The reference to resolve
        N)�resolverPrT)rrW�urlZresolvedrrr�	resolving�s


zRefResolver.resolvingcCs|�|j|�}||�|�fS)z.
        Resolve the given reference.
        )r�r�r�)rrWr�rrrr��szRefResolver.resolvec
Csxt|�\}}y|j|}WnPtk
rjy|�|�}Wn,tk
rd}zt�|��Wdd}~XYnXYnX|�||�S)z/
        Resolve the given remote URL.
        N)rr��KeyError�resolve_remote�	Exceptionr	r��resolve_fragment)rr��fragment�document�excrrrr�s"zRefResolver.resolve_from_urlc
Cs�|�d�}|rt|��d�ng}x�|D]x}|�dd��dd�}t|t�rjyt|�}Wntk
rhYnXy||}Wq&tt	fk
r�t
�d|��Yq&Xq&W|S)z�
        Resolve a ``fragment`` within the referenced ``document``.

        Arguments:

            document:

                The referent document

            fragment (str):

                a URI fragment to resolve within it
        �/z~1z~0�~zUnresolvable JSON pointer: %r)�lstripr�splitrqrr
�int�
ValueErrorrl�LookupErrorr	r�)rr�r��parts�partrrrr�s


zRefResolver.resolve_fragmentc	Cs�yddl}Wntk
r$d}YnXt|�j}||jkrJ|j||�}nD|dkrf|rf|�|���}n(t|��}t�|�	��
d��}WdQRX|jr�||j|<|S)a�
        Resolve a remote ``uri``.

        If called directly, does not check the store first, but after
        retrieving the document at the specified URI it will be saved in
        the store if :attr:`cache_remote` is True.

        .. note::

            If the requests_ library is present, ``jsonschema`` will use it to
            request the remote ``uri``, so that the correct encoding is
            detected and used.

            If it isn't, or if the scheme of the ``uri`` is not ``http`` or
            ``https``, UTF-8 is assumed.

        Arguments:

            uri (str):

                The URI to resolve

        Returns:

            The retrieved document

        .. _requests: https://pypi.org/project/requests/
        rN)�http�httpszutf-8)
�requests�ImportErrorr�schemer�rB�jsonr�loads�read�decoder�r�)rr�r�r��resultr�rrrr�3s




zRefResolver.resolve_remote)rTrNN)rrrrrKrerDrHrPrTr?r�r��
contextlib�contextmanagerr�r�r�r�r�r�rrrrrGPs$*
$rGcOsJ|dkrt|�}|�|�||f|�|�}t�|�|��}|dk	rF|�dS)a
    Validate an instance under the given schema.

        >>> validate([2, 3, 4], {"maxItems": 2})
        Traceback (most recent call last):
            ...
        ValidationError: [2, 3, 4] is too long

    :func:`validate` will first verify that the provided schema is
    itself valid, since not doing so can lead to less obvious error
    messages and fail in less obvious or consistent ways.

    If you know you have a valid schema already, especially if you
    intend to validate multiple instances with the same schema, you
    likely would prefer using the `IValidator.validate` method directly
    on a specific validator (e.g. ``Draft7Validator.validate``).


    Arguments:

        instance:

            The instance to validate

        schema:

            The schema to validate with

        cls (IValidator):

            The class that will be used to validate the instance.

    If the ``cls`` argument is not provided, two things will happen
    in accordance with the specification. First, if the schema has a
    :validator:`$schema` property containing a known meta-schema [#]_
    then the proper validator will be used. The specification recommends
    that all schemas contain :validator:`$schema` properties for this
    reason. If no :validator:`$schema` property is found, the default
    validator class is the latest released draft.

    Any other provided positional and keyword arguments will be passed
    on when instantiating the ``cls``.

    Raises:

        `jsonschema.exceptions.ValidationError` if the instance
            is invalid

        `jsonschema.exceptions.SchemaError` if the schema itself
            is invalid

    .. rubric:: Footnotes
    .. [#] known by a validator registered with
        `jsonschema.validators.validates`
    N)�
validator_forrNr	�
best_matchrL)r rCr5r]r^rOrMrrrr_gs8
r_cCsF|dks|dksd|kr|S|dtkr6tdtdd�t�|dt�S)a
    Retrieve the validator class appropriate for validating the given schema.

    Uses the :validator:`$schema` property that should be present in the
    given schema to look up the appropriate validator class.

    Arguments:

        schema (collections.Mapping or bool):

            the schema to look at

        default:

            the default to return if the appropriate validator class
            cannot be determined.

            If unprovided, the default is to return the latest supported
            draft.
    TFz$schemaz�The metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.r9)r:)r4rr<rB�_LATEST_VERSION)rC�defaultrrrr��sr�)r)rNN)N)fr�
__future__r�warningsrr�r��numbersZsixrZ
jsonschemarrrrr	Zjsonschema.compatr
rrr
rrrrrrZjsonschema.exceptionsrr�rr1r�r4r)�listrra�Numberr%rnrmror8r=r>rDrrrtZload_schemarWrurvZdependencies_draft3Zdisallow_draft3r�rxZextends_draft3ryZitems_draft3_draft4r{r|Zmaximum_draft3_draft4r~rZminimum_draft3_draft4r�r�Zproperties_draft3Ztype_draft3r�Zdraft3_type_checkerZDraft3Validatorr�r�rwr�r��not_r�r�r�Zdraft4_type_checkerZDraft4Validatorr�r�r�r�rzr}r�r�Zdraft6_type_checkerZDraft6ValidatorZif_Zdraft7_type_checkerZDraft7Validatorr�r.rGr_r�rrrr�<module>sP0

#P
I
B