
    Mh
                    d    d Z ddlmZ ddlmZ ddlmZ  G d de          Z G d d	          Z	d
S )z"An event schema registry.    )annotations)Any   )EventSchemac                      e Zd ZdZdS )SchemaRegistryExceptionz:Exception class for Jupyter Events Schema Registry Errors.N)__name__
__module____qualname____doc__     ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_events/schema_registry.pyr   r   	   s        DDDDr   r   c                  l    e Zd ZdZdddZdd
ZddZddZed d            Z	d!dZ
d"dZd#dZd$dZdS )%SchemaRegistryz>A convenient API for storing and searching a group of schemas.Nschemasdict[str, EventSchema] | Nonec                    |pi | _         dS )zInitialize the registry.N_schemas)selfr   s     r   __init__zSchemaRegistry.__init__   s    072r   keystrreturnboolc                    || j         v S )z:Syntax sugar to check if a schema is found in the registryr   )r   r   s     r   __contains__zSchemaRegistry.__contains__   s    dm##r   c                n    d                     d | j                                        D                       S )zThe str repr of the registry.z,
c                ,    g | ]}t          |          S r   )r   ).0ss     r   
<listcomp>z+SchemaRegistry.__repr__.<locals>.<listcomp>   s    BBBa3q66BBBr   )joinr   valuesr   s    r   __repr__zSchemaRegistry.__repr__   s1    zzBB4=+?+?+A+ABBBCCCr   
schema_objr   Nonec                t    |j         | j        v rd|j          d}t          |          || j        |j         <   d S )NzThe schema, zB, is already registered. Try removing it and registering it again.)idr   r   )r   r(   msgs      r   _addzSchemaRegistry._add   sV    =DM))Hz} H H H  *#...'1jm$$$r   	list[str]c                N    t          | j                                                  S N)listr   keysr&   s    r   
schema_idszSchemaRegistry.schema_ids%   s    DM&&(()))r   schema$dict[str, Any] | (str | EventSchema)c                x    t          |t                    st          |          }|                     |           |S )zAdd a valid schema to the registry.

        All schemas are validated against the Jupyter Events meta-schema
        found here:
        )
isinstancer   r-   )r   r4   s     r   registerzSchemaRegistry.register)   s:     &+.. 	) ((F		&r   id_c                f    	 | j         |         S # t          $ r d| d}t          |          dw xY w)z^Fetch a given schema. If the schema is not found,
        this will raise a KeyError.
        The requested schema, R, was not found in the schema registry. Are you sure it was previously registered?Nr   KeyErrorr   r9   r,   s      r   getzSchemaRegistry.get4   s^    	*=%% 	* 	* 	*N N N N  3--T)	*s    !0c                `    	 | j         |= dS # t          $ r d| d}t          |          dw xY w)z_Remove a given schema. If the schema is not found,
        this will raise a KeyError.
        r;   r<   Nr=   r?   s      r   removezSchemaRegistry.removeA   sa    	*c""" 	* 	* 	*N N N N  3--T)	*s    !-datadict[str, Any]c                Z    |                      |          }|                    |           dS )zIValidate an event against a schema within this
        registry.
        N)r@   validate)r   r9   rC   r4   s       r   validate_eventzSchemaRegistry.validate_eventN   s+     #r   r0   )r   r   )r   r   r   r   )r   r   )r(   r   r   r)   )r   r.   )r4   r5   r   r   )r9   r   r   r   )r9   r   r   r)   )r9   r   rC   rD   r   r)   )r	   r
   r   r   r   r   r'   r-   propertyr3   r8   r@   rB   rG   r   r   r   r   r      s        HH> > > > >$ $ $ $D D D D2 2 2 2 * * * X*	 	 	 	* * * ** * * *     r   r   N)
r   
__future__r   typingr   r4   r   	Exceptionr   r   r   r   r   <module>rL      s        " " " " " "            E E E E Ei E E EF F F F F F F F F Fr   