
    Mh                    @   d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 ddl
mZmZ ddlmZ ddlmZ 	 dd	lmZ n# e$ r eZY nw xY wd
dlmZ d
dlmZmZ  G d de          Z G d de          Z G d de          Ze	eeef         eef         Z G d d          ZdS )zEvent schema objects.    )annotationsN)PathPurePath)AnyUnion)FormatChecker
validators)Registry)DRAFT7)	Validator   )yaml)draft7_format_checkervalidate_schemac                      e Zd ZdZdS )EventSchemaUnrecognizedz*An error for an unrecognized event schema.N__name__
__module____qualname____doc__     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_events/schema.pyr   r      s        4444r   r   c                      e Zd ZdZdS )EventSchemaLoadingErrorz+An error for an event schema loading error.Nr   r   r   r   r   r      s        5555r   r   c                      e Zd ZdZdS )EventSchemaFileAbsentz)An error for an absent event schema file.Nr   r   r   r   r   r      s        3333r   r   c                      e Zd ZdZej        edfddZddZe	ddd            Z
e	d d            Zedd            Zed!d            Zed"d            Zd#dZdS )$EventSchemaau  A validated schema that can be used.

    On instantiation, validate the schema against
    Jupyter Event's metaschema.

    Parameters
    ----------
    schema: dict or str
        JSON schema to validate against Jupyter Events.

    validator_class: jsonschema.validators
        The validator class from jsonschema used to validate instances
        of this event schema. The schema itself will be validated
        against Jupyter Event's metaschema to ensure that
        any schema registered here follows the expected form
        of Jupyter Events.

    registry:
        Registry for nested JSON schema references.
    Nschema
SchemaTypevalidator_classtype[Validator]format_checkerr   registryRegistry[Any] | Nonec                    |                      |          }t          |           |#t          j        |          t	                      z  } ||||          | _        || _        dS )zInitialize an event schema.N)r&   r%   )_load_schemar   r   create_resourcer
   
_validator_schema)selfr!   r#   r%   r&   r,   s         r   __init__zEventSchema.__init__:   sj     ##F++   -g66CH */'HUcdddr   returnstrc                8    t          j        | j        d          S )z"A string repr for an event schema.   )indent)jsondumpsr,   r-   s    r   __repr__zEventSchema.__repr__M   s    z$,q1111r   Fwas_strboolNonec                    t          | t                    rdS d}d
d}|r ||           r|dz  }n|d	z  }t          |          )zhEnsures schema was correctly loaded into a dictionary. Raises
        EventSchemaLoadingError otherwise.Nz/Could not deserialize schema into a dictionary.r!   r0   r/   r9   c                    t          |           }|                    d          p)|                    d          p|                    d          S )Nz*.ymlz*.yamlz*.json)r   match)r!   paths     r   intended_as_pathz9EventSchema._ensure_yaml_loaded.<locals>.intended_as_pathZ   sA    <<D::g&&V$**X*>*>V$**XBVBVVr   zF Paths to schema files must be explicitly wrapped in a Pathlib object.z= Double check the schema and ensure it is in the proper form.)r!   r0   r/   r9   )
isinstancedictr   )r!   r8   	error_msgr?   s       r   _ensure_yaml_loadedzEventSchema._ensure_yaml_loadedQ   s}     fd## 	FE		W 	W 	W 	W  	Y''// 	YaaIIXXI%i000r   dict[str, Any]c                   t          | t                    r| S t          | t                    rft          |                                           sd|  d}t          |          t          j        |           }t          	                    |           |S t          | t                    r2t          j        |           }t          	                    |d           |S d| j        j         d}t          |          )a
  Load a JSON schema from different sources/data types.

        `schema` could be a dictionary or serialized string representing the
        schema itself or a Pathlib object representing a schema file on disk.

        Returns a dictionary with schema data.
        z!Schema file not present at path "z".T)r8   zAExpected a dictionary, string, or PurePath, but instead received .)r@   rA   r   r   existsr   r   loadr    rC   r0   loads	__class__r   r   )r!   msgloaded_schemas      r   r)   zEventSchema._load_schemag   s     fd## 	M fh'' 	!<<&&(( 1D&DDD+C000 If--M++M:::   fc"" 	! Jv..M++M4+HHH  nRXRbRknnn%c***r   c                    | j         d         S )zSchema $id field.z$idr,   r6   s    r   idzEventSchema.id   s     |E""r   intc                    | j         d         S )zSchema's version.versionrN   r6   s    r   rR   zEventSchema.version   s     |I&&r   c                    | j         d         S )N
propertiesrN   r6   s    r   rT   zEventSchema.properties   s    |L))r   datac                :    | j                             |           dS )z3Validate an incoming instance of this event schema.N)r+   validate)r-   rU   s     r   rW   zEventSchema.validate   s      &&&&&r   )r!   r"   r#   r$   r%   r   r&   r'   )r/   r0   )F)r!   r"   r8   r9   r/   r:   )r!   r"   r/   rD   )r/   rP   )r/   rD   )rU   rD   r/   r:   )r   r   r   r   r	   Draft7Validatorr   r.   r7   staticmethodrC   r)   propertyrO   rR   rT   rW   r   r   r   r    r    $   s        0 ,6+E(=)-    &2 2 2 2 1 1 1 1 \1* + + + \+B # # # X# ' ' ' X' * * * X*' ' ' ' ' 'r   r    ) r   
__future__r   r4   pathlibr   r   typingr   r   
jsonschemar   r	   referencingr
   referencing.jsonschemar   jsonschema.protocolsr   ImportError r   r   r   	Exceptionr   r   r   rA   r0   r"   r    r   r   r   <module>re      s     " " " " " "  " " " " " " " "         0 0 0 0 0 0 0 0             ) ) ) ) ) ).......   III       > > > > > > > >5 5 5 5 5i 5 5 56 6 6 6 6i 6 6 64 4 4 4 4I 4 4 4 4S>301
u' u' u' u' u' u' u' u' u' u's   9 AA