관리-도구
편집 파일: validators.cpython-39.opt-1.pyc
a �����$�]�r�������������������#���@���s���d�Z�ddlmZ�ddlmZ�ddlZddlZddlZddlm Z �ddl mZmZm Z mZmZ�ddlmZmZmZmZmZmZmZmZmZmZ�ddlmZ�e�G�d d ��d e�Zi�Ze � ��Z!d/dd �Z"e#e$ee%d�ej&e'ed�Z(ej)e"e(�d�Z*dd��Z+dd��Z,G�dd��de%�Z-dd��Z.dddde.fdd�Z/d0dd�Z0e/e �1d�ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFd�ejGddd��d �ZHe/e �1d!�ej2ej3ej4ejIejJejKej8ej:ej;ej<ej=ejLej>ej?ej@ejMejAej7ejNejOejBejCejPejQej%ejFd"�ejRd!d#d��d �ZSe/e �1d$�ej2ej3ej4ejIejJejTejUejKej8ejVejWej:ejXej<ej=ejLejYej?ej@ejMejZej7ejNejOejBejCejPej[ejQej%ejFd%�ej\d$d&�Z]e/e �1d'�ej2ej3ej4ejIejJejTejUejKej8ejVejWej:ej^ejXej<ej=ejLejYej?ej@ejMejZej7ejOejNejBejCejPej[ejQej%ejFd(� ej_d'd&�Z`e`ZaG�d)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�������������������@���s���e�Zd�ZdZdd��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. c�����������������C���s���dS�)Nz=DEFAULT_TYPES cannot be used on Validators using TypeCheckers����selfr���r����9/usr/lib/python3.9/site-packages/jsonschema/validators.py�__str__1���s����z_DontDoThat.__str__N)�__name__� __module__�__qualname__�__doc__r���r���r���r���r���r���(���s���r���r���c�����������������C���s6���t�|��}�dd��}i�}t|��D�]\}}||�||<�q|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` c��������������������s���t���������fdd�}|S�)Nc��������������������s ���t�|t�rt��vrdS�t�|���S�)NF)� isinstance�bool)Zchecker�instance��pytypesr���r���� type_checkL���s���� zH_generate_legacy_type_checks.<locals>.gen_type_check.<locals>.type_check)r���Zflatten)r#���r$���r���r"���r����gen_type_checkI���s���� z4_generate_legacy_type_checks.<locals>.gen_type_check)�dictr���)�typesr%���Zdefinitions�typenamer#���r���r���r����_generate_legacy_type_checks9���s����r)���)ZarrayZbooleanZintegerZnullZnumber�object�string�Z type_checkersc��������������������s�����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 c��������������������s$���|�t���<�|��|�j�}|r |�t|<�|�S��N)� validators�ID_OF�META_SCHEMA�meta_schemas)�clsZmeta_schema_id��versionr���r���� _validates}���s ����zvalidates.<locals>._validatesr���)r4���r5���r���r3���r���� validatesi���s����r6���c�����������������C���s$���|�j�d�u�rt���tdtdd��|�jS�)NzcThe DEFAULT_TYPES attribute is deprecated. See the type checker attached to this validator instead.������ stacklevel)�_CREATED_WITH_DEFAULT_TYPESr���r����DeprecationWarning�_DEFAULT_TYPESr���r���r���r���r<�������s���� �r<���c�������������������@���s���e�Zd�Zee�ZdS�)�!_DefaultTypesDeprecatingMetaClassN)r���r���r����propertyr<���� DEFAULT_TYPESr���r���r���r���r=�������s���r=���c�����������������C���s ���|�du�s|�du�rdS�|���dd�S�)NTF��z$id��get��schemar���r���r����_id_of����s����rE���c��������������������s�����dur<�durt�d��d��tdtdd��tjt��d��n(t��du�rRd��t�n�tu�r`d��nd��tt �G��������fd d �d t ��}|dur�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.r7���r8���r,���Fc�����������������������s����e�Zd�Ze��Ze��Z�Ze��Ze e �Ze��Z ��Zd�fdd� Z edd���Zd�fdd� Zdd d �Zdd��Zd d��Zddd�ZdS�)zcreate.<locals>.Validatorr���Nc��������������������sP���|r$t�dtdd��|�j�t|��|�_|d�u�r:tj|��d�}||�_||�_||�_ d�S�)NzaThe types argument is deprecated. Provide a type_checker to jsonschema.validators.extend instead.r7���r8�����id_of) r���r;����TYPE_CHECKERZ redefine_manyr)����RefResolver�from_schema�resolver�format_checkerrD���)r���rD���r'���rK���rL���rF���r���r����__init__��s����� �z"create.<locals>.Validator.__init__c�����������������S���s&���|�|�j���|�D�]}tj�|��qd�S�r-���)r0����iter_errorsr ���ZSchemaErrorZcreate_from)r2���rD����errorr���r���r����check_schema#��s����z&create.<locals>.Validator.check_schemac�����������������3���s��|d�u�r|�j�}|du�rd�S�|du�rBtjd|f�d�d�||d�V��d�S���|�}|rZ|�j�|��z�|�d�}|d�urzd|fg}nt|�}|D�]f\}}|�j�|�}|d�u�r�q�||�|||�p�d} | D�]0} | j||||d��|dkr�| j � |��| V��q�q�W�|�r|�j����n|�r|�j����0�d�S�)NTFzFalse schema does not allow %r)� validatorZvalidator_valuer!���rD����$refr���)rD���r ���ZValidationErrorrK���� push_scoperB���r���� VALIDATORSZ_set�schema_path� appendleft� pop_scope)r���r!����_schema�scope�refr.����k�vrQ����errorsrO���rF���r���r���rN���(��sP����� ��z%create.<locals>.Validator.iter_errorsc�����������������s���sD���|���||�D�]2}|d�ur$|j�|��|d�ur8|j�|��|V��qd�S�r-���)rN����pathrV���rU���)r���r!���rD���r^���rU���rO���r���r���r����descendW��s����z!create.<locals>.Validator.descendc�����������������_���s���|�j�|i�|��D�]}|�qd�S�r-���)rN���)r����args�kwargsrO���r���r���r����validate_��s����z"create.<locals>.Validator.validatec�����������������S���s:���z|�j��||�W�S��tjy4���t�|||�j��Y�n0�d�S�r-���)rH����is_typer ���ZUndefinedTypeCheckZUnknownTyperD���)r���r!����typer���r���r���rc���c��s����z!create.<locals>.Validator.is_typec�����������������S���s���t�|��||�d��}|d�u�S�r-���)�nextrN���)r���r!���rX���rO���r���r���r����is_validi��s����z"create.<locals>.Validator.is_valid)r���NN)N)NN)N)r���r���r���r&���rT���r0���rH����staticmethodr/���r>���r<���r?���r:���rM����classmethodrP���rN���r_���rb���rc���rf���r����Z_created_with_default_types� default_typesrG����meta_schema�type_checkerr.���r���r���� Validator����s$������� / rm���� r@���)� TypeErrorr���r;���r����TypeCheckerr)����_DEPRECATED_DEFAULT_TYPES�*_TYPE_CHECKER_FOR_DEPRECATED_DEFAULT_TYPESr���r=���r*���r6����title�replacer���)rk���r.���r4���rj���rl���rG���rm���r���ri���r����create����s6����@��� rru���c�����������������C���sH���t�|�j�}|�|��|du�r$|�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.)rk���r.���r4���rl���rG���) r&���rT����updaterH���r:���ro���ru���r0���r/���)rQ���r.���r4���rl���Zall_validatorsr���r���r����extendt��s����5 ��rw���Zdraft3)rR����additionalItems�additionalProperties�dependenciesZdisallowZdivisibleBy�enumZextends�format�items�maxItems� maxLength�maximum�minItems� minLength�minimum�pattern�patternProperties� propertiesrd����uniqueItemsc�����������������C���s���|���dd�S��N�idr@���rA���rC���r���r���r����<lambda>��������r����)rk���r.���rl���r4���rG���Zdraft4)rR���rx���ry����allOf�anyOfrz���r{���r|���r}���r~���r���� maxPropertiesr����r����r����� minPropertiesr����� multipleOf�not�oneOfr����r����r�����requiredrd���r����c�����������������C���s���|���dd�S�r����rA���rC���r���r���r���r�������r����Zdraft6)rR���rx���ry���r����r�����const�containsrz���r{����exclusiveMaximum�exclusiveMinimumr|���r}���r~���r���r����r����r����r����r����r����r����r����r����r����r����r����� propertyNamesr����rd���r����)rk���r.���rl���r4���Zdraft7) rR���rx���ry���r����r����r����r����rz���r{���r����r����r|����ifr}���r~���r���r����r����r����r����r����r����r����r����r����r����r����r����r����r����rd���r����c�������������������@���s����e�Zd�ZdZddd�Zeefdd��Zd d ��Zdd��Z e d d���Ze dd���Ze jdd���Ze jdd���Zdd��Zdd��Zdd��Zdd��ZdS�)rI���a��� 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 r���TNc�����������������C���s����|d�u�rt�d�t�}|d�u�r*t�d�|�j�}||�_||�_t|�|�_|g|�_t� dd��t t�D���|�_|�j� |��||�j|<�||�_||�_d�S�)Ni���c�����������������s���s���|�]\}}||j�fV��qd�S�r-���)r0���)�.0r����rQ���r���r���r���� <genexpr>���s����z'RefResolver.__init__.<locals>.<genexpr>)r ���r����resolve_from_url�referrer�cache_remoter&����handlers� _scopes_stackr����URIDictr���r1����storerv����_urljoin_cache� _remote_cache)r����base_urir����r����r����r����Z urljoin_cacheZremote_cacher���r���r���rM���|��s���� � zRefResolver.__init__c�����������������O���s���|�|||�|d�|��S�)z� Construct a resolver from a JSON schema object. Arguments: schema: the referring schema Returns: `RefResolver` )r����r����r���)r2���rD���rG���r`���ra���r���r���r���rJ������s����zRefResolver.from_schemac�����������������C���s���|�j��|��|�j|���dS�)z� Enter a given sub-scope. Treats further dereferences as being performed underneath the given scope. N)r�����appendr�����resolution_scope�r���rY���r���r���r���rS������s�����zRefResolver.push_scopec�����������������C���s0���z|�j�����W�n�ty*���t�d��Y�n0�dS�)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 ����RefResolutionErrorr���r���r���r���rW������s���� �zRefResolver.pop_scopec�����������������C���s ���|�j�d�S�)z8 Retrieve the current resolution scope. ���)r����r���r���r���r���r�������s����zRefResolver.resolution_scopec�����������������C���s���t�|�j�\}}|S�)zL Retrieve the current base URI, not including any fragment. )r���r����)r����uri�_r���r���r���r�������s����zRefResolver.base_uric�����������������c���s,���|���|��zdV��W�|�����n |�����0�dS�)zT Temporarily enter the given scope for the duration of the context. N)rS���rW���r����r���r���r����in_scope���s���� zRefResolver.in_scopec�����������������c���s:���|���|�\}}|��|��z|V��W�|�����n |�����0�dS�)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)�resolverS���rW���)r���rZ����urlZresolvedr���r���r���� resolving���s ���� zRefResolver.resolvingc�����������������C���s���|���|�j|�}||��|�fS�)z. Resolve the given reference. )r����r����r����)r���rZ���r����r���r���r���r�������s����zRefResolver.resolvec�������������� ���C���sx���t�|�\}}z|�j|�}W�nP�tyj���z|��|�}W�n.�tyd�}�zt�|��W�Y�d}~n d}~0�0�Y�n0�|��||�S�)z/ Resolve the given remote URL. N)r���r�����KeyError�resolve_remote� Exceptionr ���r�����resolve_fragment)r���r�����fragment�document�excr���r���r���r�������s����&zRefResolver.resolve_from_urlc�������������� ���C���s����|��d�}|rt|��d�ng�}|D�]t}|�dd��dd�}t|t�rfzt|�}W�n�tyd���Y�n0�z||�}W�q$�tt fy����t �d|���Y�q$0�q$|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����splitrt���r���r ����int� ValueErrorro����LookupErrorr ���r����)r���r����r�����parts�partr���r���r���r������s ���� �zRefResolver.resolve_fragmentc�����������������C���s����zddl�}W�n�ty"���d}Y�n0�t|�j}||�jv�rH|�j|�|�}nX|dv�rd|rd|�|����}n<t|��$}t�|� ��� d��}W�d����n1�s�0����Y��|�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/ r���N)�http�httpszutf-8) �requests�ImportErrorr����schemer����rB����jsonr����loads�read�decoder����r����)r���r����r����r�����resultr����r���r���r���r����3��s���� 2 zRefResolver.resolve_remote)r���Tr���NN)r���r���r���r���rM���rh���rE���rJ���rS���rW���r>���r����r����� contextlib�contextmanagerr����r����r����r����r����r����r���r���r���r���rI���P��s.���/������ $rI���c�����������������O���sP���|du�rt�|�}|�|��||g|�R�i�|��}t�|�|���}|durL|�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_forrP���r ���Z best_matchrN���)r!���rD���r2���r`���ra���rQ���rO���r���r���r���rb���g��s����8 rb���c�����������������C���sF���|�du�s|�du�sd|�vr|S�|�d�t�vr6tdtdd��t��|�d�t�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.r7���r8���)r1���r���r;���rB����_LATEST_VERSION)rD����defaultr���r���r���r�������s����� r����)r���)r���NN)N)fr���Z __future__r����warningsr���r����r����ZnumbersZsixr���Z jsonschemar���r���r���r���r ���Zjsonschema.compatr ���r���r���r ���r���r���r���r���r���r���Zjsonschema.exceptionsr���r����r���r.���r����r1���r)����listr ���rd����Numberr&���rq���rp���rr���r6���r<���r=���rE���ru���rw���Zload_schemarZ���rx���ry���Zdependencies_draft3Zdisallow_draft3r����r{���Zextends_draft3r|���Zitems_draft3_draft4r~���r���Zmaximum_draft3_draft4r����r����Zminimum_draft3_draft4r����r����Zproperties_draft3Ztype_draft3r����Zdraft3_type_checkerZDraft3Validatorr����r����rz���r����r�����not_r����r����r����Zdraft4_type_checkerZDraft4Validatorr����r����r����r����r}���r����r����r����Zdraft6_type_checkerZDraft6ValidatorZif_Zdraft7_type_checkerZDraft7Validatorr����r*���rI���rb���r����r���r���r���r����<module>���sf��0 #� �� �V I����#�!�'�"�(�� B