o
    tf
                     @  sJ   d Z ddlmZ ddlmZ ddlmZ G dd deZG dd	 d	Z	d
S )z"An event schema registry.    )annotations)Any   )EventSchemac                   @  s   e Zd ZdZdS )SchemaRegistryExceptionz:Exception class for Jupyter Events Schema Registry Errors.N)__name__
__module____qualname____doc__ r   r   g/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/jupyter_events/schema_registry.pyr   	   s    r   c                   @  sp   e Zd ZdZd$d%ddZd&ddZd'ddZd(ddZed)ddZ	d*ddZ
d+ddZd,ddZd-d"d#ZdS ).SchemaRegistryz>A convenient API for storing and searching a group of schemas.Nschemasdict[str, EventSchema] | Nonec                 C  s   |pi | _ dS )zInitialize the registry.N_schemas)selfr   r   r   r   __init__      zSchemaRegistry.__init__keystrreturnboolc                 C  s
   || j v S )z:Syntax sugar to check if a schema is found in the registryr   )r   r   r   r   r   __contains__   s   
zSchemaRegistry.__contains__c                 C  s   d dd | j D S )zThe str repr of the registry.z,
c                 S  s   g | ]}t |qS r   )r   ).0sr   r   r   
<listcomp>   s    z+SchemaRegistry.__repr__.<locals>.<listcomp>)joinr   valuesr   r   r   r   __repr__   s   zSchemaRegistry.__repr__
schema_objr   Nonec                 C  s2   |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!   msgr   r   r   _add   s
   zSchemaRegistry._add	list[str]c                 C  s   t | j S N)listr   keysr   r   r   r   
schema_ids%   r   zSchemaRegistry.schema_idsschema$dict[str, Any] | (str | EventSchema)c                 C  s    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   r+   r   r   r   register)   s   

zSchemaRegistry.registerid_c                 C  s2   z| j | W S  ty   d| d}t|d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   r/   r$   r   r   r   get4   s   

zSchemaRegistry.getc                 C  s4   z| j |= W dS  ty   d| d}t|dw )z_Remove a given schema. If the schema is not found,
        this will raise a KeyError.
        r0   r1   Nr2   r4   r   r   r   removeA   s   

zSchemaRegistry.removedatadict[str, Any]c                 C  s   |  |}|| dS )zIValidate an event against a schema within this
        registry.
        N)r5   validate)r   r/   r7   r+   r   r   r   validate_eventN   s   
zSchemaRegistry.validate_eventr'   )r   r   )r   r   r   r   )r   r   )r!   r   r   r"   )r   r&   )r+   r,   r   r   )r/   r   r   r   )r/   r   r   r"   )r/   r   r7   r8   r   r"   )r   r   r	   r
   r   r   r    r%   propertyr*   r.   r5   r6   r:   r   r   r   r   r      s    


	


r   N)
r
   
__future__r   typingr   r+   r   	Exceptionr   r   r   r   r   r   <module>   s    