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

B

���`�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)rZflatten)r!r"r)r!r�gen_type_checkIs
z4_generate_legacy_type_checks.<locals>.gen_type_check)�dictr)�typesr#Zdefinitions�typenamer!rrr�_generate_legacy_type_checks9sr')ZarrayZbooleanZintegerZnullZnumber�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)r0r1r)r0r�	validatesisr2cCs$|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)rrrrr7�s
r7c@seZdZee�ZdS)�!_DefaultTypesDeprecatingMetaClassN)rrr�propertyr7�
DEFAULT_TYPESrrrrr8�sr8cCs |dks|dkrdS|�dd�S)NTF�z$id)�get)�schemarrr�_id_of�sr>cs��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.r3)r4)r*Fcs�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.r3)r4)�id_of)
rr6�TYPE_CHECKERZ
redefine_manyr'�RefResolver�from_schema�resolver�format_checkerr=)rr=r%rCrD)r?rr�__init__sz"create.<locals>.Validator.__init__cSs*x$||j��|�D]}tj�|��qWdS)N)r-�iter_errorsr	ZSchemaErrorZcreate_from)r/r=�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 r=z$refr)r=r	ZValidationErrorrC�
push_scoper<r�
VALIDATORSZ_set�schema_path�
appendleft�	pop_scope)rr �_schema�scope�refr+�k�vrI�errorsrG)r?rrrF(sH


z%create.<locals>.Validator.iter_errorscssHxB|�||�D]2}|dk	r&|j�|�|dk	r:|j�|�|VqWdS)N)rF�pathrMrL)rr r=rUrLrGrrr�descendWsz!create.<locals>.Validator.descendc_sx|j||�D]}|�qWdS)N)rF)r�args�kwargsrGrrr�validate_sz"create.<locals>.Validator.validatecSs:y|j�||�Stjk
r4t�|||j��YnXdS)N)r@�is_typer	ZUndefinedTypeCheckZUnknownTyper=)rr �typerrrrZcsz!create.<locals>.Validator.is_typecSst|�||�d�}|dkS)N)�nextrF)rr rOrGrrr�is_validisz"create.<locals>.Validator.is_valid)rNN)N)NN)N)rrrr$rKr-r@�staticmethodr,r9r7r:r5rE�classmethodrHrFrVrYrZr]r)�_created_with_default_types�
default_typesr?�meta_schema�type_checkerr+rr�	Validator�s /
rd� r;)�	TypeErrorrr6r�TypeCheckerr'�_DEPRECATED_DEFAULT_TYPES�*_TYPE_CHECKER_FOR_DEPRECATED_DEFAULT_TYPESrr8r(r2�title�replacer)rbr+r0rarcr?rdr)r`rar?rbrcr+r�create�s0@rrlcCsHt|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.)rbr+r0rcr?)	r$rK�updater@r5rfrlr-r,)rIr+r0rcZall_validatorsrrr�extendts5

rnZdraft3)z$ref�additionalItems�additionalProperties�dependenciesZdisallowZdivisibleBy�enumZextends�format�items�maxItems�	maxLength�maximum�minItems�	minLength�minimum�pattern�patternProperties�
propertiesr[�uniqueItemscCs|�dd�S)N�idr;)r<)r=rrr�<lambda>��r�)rbr+rcr0r?Zdraft4)z$refrorp�allOf�anyOfrqrrrsrtrurv�
maxPropertiesrwrxry�
minPropertiesrz�
multipleOf�not�oneOfr{r|r}�requiredr[r~cCs|�dd�S)Nrr;)r<)r=rrrr��r�Zdraft6)z$refrorpr�r��const�containsrqrr�exclusiveMaximum�exclusiveMinimumrsrtrurvr�rwrxryr�rzr�r�r�r{r|r}�
propertyNamesr�r[r~)rbr+rcr0Zdraft7) z$refrorpr�r�r�r�rqrrr�r�rs�ifrtrurvr�rwrxryr�rzr�r�r�r{r|r}r�r�r[r~c@s�eZdZdZddd�Zeefdd��Zd	d
�Zdd�Z	e
d
d��Ze
dd��Ze
jdd��Ze
jdd��Zdd�Zdd�Zdd�Zdd�ZdS)rAa�
    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)r-)�.0rrIrrr�	<genexpr>�sz'RefResolver.__init__.<locals>.<genexpr>)r
r�resolve_from_url�referrer�cache_remoter$�handlers�
_scopes_stackr�URIDictrr.�storerm�_urljoin_cache�
_remote_cache)r�base_urir�r�r�r�Z
urljoin_cacheZremote_cacherrrrE|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)r/r=r?rWrXrrrrB�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)rrPrrrrJ�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)rrrrrN�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)rJrN)rrPrrr�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)�resolverJrN)rrQ�urlZresolvedrrr�	resolving�s


zRefResolver.resolvingcCs|�|j|�}||�|�fS)z.
        Resolve the given reference.
        )r�r�r�)rrQr�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�splitrkrr
�int�
ValueErrorrf�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)ZhttpZhttpszutf-8)
�requests�ImportErrorr�schemer�r<�jsonr�loads�read�decoder�r�)rr�r�r��resultr�rrrr�3s




zRefResolver.resolve_remote)rTrNN)rrrrrEr_r>rBrJrNr9r�r��
contextlib�contextmanagerr�r�r�r�r�r�rrrrrAPs$*
$rAcOsJ|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_forrHr	Z
best_matchrF)r r=r/rWrXrIrGrrrrYgs8
rYcCsF|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.r3)r4)r.rr6r<�_LATEST_VERSION)r=�defaultrrrr��sr�)r)rNN)N)frZ
__future__r�warningsrr�r�ZnumbersZsixrZ
jsonschemarrrrr	Zjsonschema.compatr
rrr
rrrrrrZjsonschema.exceptionsrr�rr+r�r.r'�listrr[�Numberr$rhrgrir2r7r8r>rlrnZload_schemarQrorpZdependencies_draft3Zdisallow_draft3r�rrZextends_draft3rsZitems_draft3_draft4rurvZmaximum_draft3_draft4rxryZminimum_draft3_draft4r{r|Zproperties_draft3Ztype_draft3r~Zdraft3_type_checkerZDraft3Validatorr�r�rqr�r��not_r�r}r�Zdraft4_type_checkerZDraft4Validatorr�r�r�r�rtrwrzr�Zdraft6_type_checkerZDraft6ValidatorZif_Zdraft7_type_checkerZDraft7Validatorr�r(rArYr�rrrr�<module>sP0

#P
I
B

Zerion Mini Shell 1.0