Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/jsonschema/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/jsonschema/__pycache__/validators.cpython-35.pyc



�$�]ho�D@s�ddlmZddlmZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
mZddlmZmZmZmZmZmZmZmZmZmZddlmZeGdd	�d	e�ZiZej�Z fd
d�Z!de"d
e#dede$d�dej%de&deiZ'ej(de!e'��Z)dd�Z*dd�Z+Gdd�de$�Z,dd�Z-fddde-dd�Z.fdddd�Z/e.d ej0d!�d"d#e
j1d$e
j2d%e
j3d&e
j4d'e
j5d(e
j6d)e
j7d*e
j8d+e
j9d,e
j:d-e
j;d.e
j<d/e
j=d0e
j>d1e
j?d2e
j@d3e
jAd4e
jBd5e
jCd6e
jDd7e
jEid8ejFd9d!d:d;d<��ZGe.d ej0d=�d"d#e
j1d$e
j2d%e
j3d>e
jHd?e
jId&e
jJd)e
j7d+e
j9d,e
j:d-e
j;d.e
j<d@e
jKd/e
j=d0e
j>d1e
j?dAe
jLd2e
j@dBe
j6dCe
jMdDe
jNd3e
jAd4e
jBd5e
jOdEe
jPd6e
j$d7e
jEid8ejQd9d=d:dFd<��ZRe.d ej0dG�d"d#e
j1d$e
j2d%e
j3d>e
jSd?e
jTdHe
jUdIe
jVd&e
jJd)e
j7dJe
jWdKe
jXd+e
j9d,e
jYd-e
j;d.e
j<d@e
jKd/e
jZd0e
j>d1e
j?dAe
jLd2e
j[dBe
j6dCe
jMdDe
j\d3e
jAd4e
jBd5e
jOdLe
j]dEe
jPd6e
j$d7e
jEid8ej^d9dG�Z_e.d ej0dM�d"d#e
j1d$e
j2d%e
j3d>e
jSd?e
jTdHe
jUdIe
jVd&e
jJd)e
j7dJe
jWdKe
jXd+e
j9dNe
j`d,e
jYd-e
j;d.e
j<d@e
jKd/e
jZd0e
j>d1e
j?dAe
jLd2e
j[dBe
j6dDe
j\dCe
jMd3e
jAd4e
jBd5e
jOdLe
j]dEe
jPd6e
j$d7e
jEi d8ejad9dM�ZbebZcGdOdP�dPed�ZeddQdR�ZfecdSdT�ZgdS)U�)�division)�warnN)�
add_metaclass)�_legacy_validators�_types�_utils�_validators�
exceptions)
�Sequence�	int_types�	iteritems�	lru_cache�	str_types�unquote�	urldefrag�urljoin�urlopen�urlsplit)�	ErrorTreec@s"eZdZdZdd�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/python35/lib/python3.5/site-packages/jsonschema/validators.py�__str__.sz_DontDoThat.__str__N)�__name__�
__module__�__qualname__�__doc__rrrrrr%srcCsOt|�}dd�}i}x*t|�D]\}}||�||<q+W|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`
    cs%tj����fdd�}|S)Ncs,t|t�rt�krdSt|��S)NF)�
isinstance�bool)Zchecker�instance)�pytypesrr�
type_checkIszH_generate_legacy_type_checks.<locals>.gen_type_check.<locals>.type_check)r�flatten)r!r"r)r!r�gen_type_checkFsz4_generate_legacy_type_checks.<locals>.gen_type_check)�dictr)�typesr$�definitions�typenamer!rrr�_generate_legacy_type_checks6sr)�arrayZboolean�integerZnull�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:

        callable: a class decorator to decorate the validator with the version
    cs0|t�<|j|j�}|r,|t|<|S)N)�
validators�ID_OF�META_SCHEMA�meta_schemas)�clsZmeta_schema_id)�versionrr�
_validatesxs


zvalidates.<locals>._validatesr)r5r6r)r5r�	validatesfsr7cCs2|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=�sr=cCs,|dks|dkrdS|jdd�S)NTF�z$id)�get)�schemarrr�_id_of�srCcs�dk	rX�dk	r$td��d�tdtdd�tjdt����n<t��dkryd�t�n�tkr�d�nd�tt	�G������fd	d
�d
t
��}|dk	rt|�|�}|j�j
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 (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.r8r9r/Fcs�eZdZe��Ze��Z�Ze��Ze	e
�Ze��Z
�Zfdd�fdd�Z
edd��Zd�fdd�Zdddd	�Zd
d�Zdd
�Zddd�ZdS)zcreate.<locals>.ValidatorNcst|r4tdtdd�|jjt|��|_|dkrUtj|d��}||_||_||_	dS)NzaThe types argument is deprecated. Provide a type_checker to jsonschema.validators.extend instead.r8r9�id_of)
rr;�TYPE_CHECKERZ
redefine_manyr)�RefResolver�from_schema�resolver�format_checkerrB)rrBr&rHrI)rDrr�__init__s			z"create.<locals>.Validator.__init__cSs9x2||j�j|�D]}tjj|��qWdS)N)r2�iter_errorsr	ZSchemaErrorZcreate_from)r4rB�errorrrr�check_schemasz&create.<locals>.Validator.check_schemac3s�|dkr|j}|dkr%dS|dkrbtjd|fddddd|d|�VdS�|�}|r�|jj|�z�|jd�}|dk	r�d|fg}nt|�}x�|D]�\}}|jj|�}|dkr�q�|||||�pf}	xQ|	D]I}
|
jd|d|d|d|�|dkrZ|
j	j
|�|
VqWq�WWd|r~|jj�XdS)	NTFzFalse schema does not allow %r�	validatorZvalidator_valuer rBz$ref)rBr	ZValidationErrorrH�
push_scoperAr�
VALIDATORSZ_set�schema_path�
appendleft�	pop_scope)rr �_schema�scope�refr0�k�vrN�errorsrL)rDrrrK#sH	

	z%create.<locals>.Validator.iter_errorscss^xW|j||�D]C}|dk	r5|jj|�|dk	rQ|jj|�|VqWdS)N)rK�pathrRrQ)rr rBrZrQrLrrr�descendRsz!create.<locals>.Validator.descendc_s'x |j||�D]}|�qWdS)N)rK)r�args�kwargsrLrrr�validateZsz"create.<locals>.Validator.validatecSsKy|jj||�SWn-tjk
rFtj|||j��YnXdS)N)rE�is_typer	ZUndefinedTypeCheckZUnknownTyperB)rr �typerrrr_^sz!create.<locals>.Validator.is_typecSs%t|j||�d�}|dkS)N)�nextrK)rr rTrLrrr�is_validdsz"create.<locals>.Validator.is_valid)rrrr%rPr2rE�staticmethodr1r>r<r?r:rJ�classmethodrMrKr[r^r_rbr)�_created_with_default_types�
default_typesrD�meta_schema�type_checkerr0rr�	Validator�s /ri� r@)�	TypeErrorrr;r�TypeCheckerr)�_DEPRECATED_DEFAULT_TYPES�*_TYPE_CHECKER_FOR_DEPRECATED_DEFAULT_TYPESrr=r-r7�title�replacer)rgr0r5rfrhrDrir)rerfrDrgrhr0r�create�s0@				+rrqcCstt|j�}|j|�|dkr4|j}n|jrItd��td|jd|d|d|d|j�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.rgr0r5rhrD)	r%rP�updaterEr:rkrqr2r1)rNr0r5rhZall_validatorsrrr�extendos5
			rsrgZdraft3r0z$ref�additionalItems�additionalProperties�dependenciesZdisallowZdivisibleBy�enumZextends�format�items�maxItems�	maxLength�maximum�minItems�	minLength�minimum�pattern�patternProperties�
propertiesr`�uniqueItemsrhr5rDcCs|jdd�S)N�idr@)rA)rBrrr�<lambda>�sr�Zdraft4�allOf�anyOf�
maxProperties�
minProperties�
multipleOf�not�oneOf�requiredcCs|jdd�S)Nr�r@)rA)rBrrrr��sZdraft6�const�contains�exclusiveMaximum�exclusiveMinimum�
propertyNamesZdraft7�ifc@s�eZdZdZfdfdddd�Zeedd��Zdd	�Zd
d�Z	e
dd
��Ze
dd��Ze
jdd��Ze
jdd��Zdd�Zdd�Zdd�Zdd�ZdS)rFa�
    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 (functools.lru_cache):

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

        remote_cache (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
    TNcCs�|dkrtd�t�}|dkr?td�|j�}||_||_t|�|_|g|_tj	dd�t
t�D��|_|jj
|�||j|<||_||_dS)Nicss$|]\}}||jfVqdS)N)r2)�.0r�rNrrr�	<genexpr>�sz'RefResolver.__init__.<locals>.<genexpr>)r
r�resolve_from_url�referrer�cache_remoter%�handlers�
_scopes_stackr�URIDictrr3�storerr�_urljoin_cache�
_remote_cache)r�base_urir�r�r�r�Z
urljoin_cacheZremote_cacherrrrJws
			
	zRefResolver.__init__cOs||d||�d||�S)z�
        Construct a resolver from a JSON schema object.

        Arguments:

            schema:

                the referring schema

        Returns:

            `RefResolver`
        r�r�r)r4rBrDr\r]rrrrG�szRefResolver.from_schemacCs#|jj|j|j|��dS)N)r��appendr��resolution_scope)rrUrrrrO�s	zRefResolver.push_scopecCs9y|jj�Wn!tk
r4tjd��YnXdS)NznFailed to pop the scope from an empty stack. `pop_scope()` should only be called once for every `push_scope()`)r��pop�
IndexErrorr	�RefResolutionError)rrrrrS�s

zRefResolver.pop_scopecCs|jdS)N����)r�)rrrrr��szRefResolver.resolution_scopecCst|j�\}}|S)N)rr�)r�uri�_rrrr��szRefResolver.base_uric
cs(|j|�z	dVWd|j�XdS)N)rOrS)rrUrrr�in_scope�s
	zRefResolver.in_scopec
cs=|j|�\}}|j|�z	|VWd|j�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)�resolverOrS)rrV�urlZresolvedrrr�	resolving�s

	zRefResolver.resolvingcCs(|j|j|�}||j|�fS)N)r�r�r�)rrVr�rrrr��szRefResolver.resolvecCs�t|�\}}y|j|}Wn\tk
r�y|j|�}Wn4tk
r|}ztj|��WYdd}~XnXYnX|j||�S)N)rr��KeyError�resolve_remote�	Exceptionr	r��resolve_fragment)rr��fragment�document�excrrrr��s
'zRefResolver.resolve_from_urlcCs�|jd�}|r*t|�jd�ng}x�|D]�}|jdd�jdd�}t|t�r�yt|�}Wntk
r�YnXy||}Wq7tt	fk
r�t
jd|��Yq7Xq7W|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�splitrprr
�int�
ValueErrorrk�LookupErrorr	r�)rr�r��parts�partrrrr��s!

zRefResolver.resolve_fragmentcCs�yddl}Wntk
r*d}YnXt|�j}||jkr_|j||�}n^|dkr�|r�|j|�j�}n4t|��%}tj|j	�j
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)r�r�)
�requests�ImportErrorr�schemer�rA�jsonr�loads�read�decoder�r�)rr�r�r��resultr�rrrr�s
%	
zRefResolver.resolve_remote)rrrrrJrdrCrGrOrSr>r�r��
contextlib�contextmanagerr�r�r�r�r�r�rrrrrFKs$*
$rFcOse|dkrt|�}|j|�||||�}tj|j|��}|dk	ra|�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_forrMr	�
best_matchrK)r rBr4r\r]rNrLrrrr^Ds8
r^cCs_|dks$|dks$d|kr(|S|dtkrKtdtdd�tj|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.r8r9)r3rr;rA�_LATEST_VERSION)rB�defaultrrrr��s$r�)h�
__future__r�warningsrr�r��numbers�sixrZ
jsonschemarrrrr	Zjsonschema.compatr
rrr
rrrrrrZjsonschema.exceptionsrr�rr0r�r3r)�listrr`�Numberr%rmrlrnr7r<r=rCrqrsZload_schemarVrtruZdependencies_draft3Zdisallow_draft3r�rwZextends_draft3rxZitems_draft3_draft4rzr{Zmaximum_draft3_draft4r}r~Zminimum_draft3_draft4r�r�Zproperties_draft3Ztype_draft3r�Zdraft3_type_checkerZDraft3ValidatorZallOf_draft4ZanyOf_draft4rvr�r��not_ZoneOf_draft4r�r�Zdraft4_type_checkerZDraft4Validatorr�r�r�r�r�r�ryr|rr�r�Zdraft6_type_checkerZDraft6ValidatorZif_Zdraft7_type_checkerZDraft7Validatorr�r-rFr^r�rrrr�<module>sH(F
#		�I																																																																																																																�B