o
    im
                     @   sB   d Z ddlmZ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.    )OptionalUnion   )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   Y/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyter_events/schema_registry.pyr      s    r   c                   @   s   e Zd ZdZddee fddZdedefdd	Z	defd
dZ
deddfddZedd Zdeeeef defddZdedefddZdeddfddZdededdfddZdS )SchemaRegistryz>A convenient API for storing and searching a group of schemas.Nschemasc                 C   s   |pi | _ dS )zInitialize the registry.N_schemas)selfr   r   r   r   __init__   s   zSchemaRegistry.__init__keyreturnc                 C   s
   || j v S )z:Syntax sugar to check if a schema is found in the registryr   )r   r   r   r   r   __contains__      
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   )str).0sr   r   r   
<listcomp>   s    z+SchemaRegistry.__repr__.<locals>.<listcomp>)joinr   valuesr   r   r   r   __repr__   s   zSchemaRegistry.__repr__
schema_objc                 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._addc                 C   s
   | j  S N)r   keysr   r   r   r   
schema_ids#   r   zSchemaRegistry.schema_idsschemac                 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.registerr    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   get2   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.
        r)   r*   Nr+   r-   r   r   r   remove?   s   

zSchemaRegistry.removedatac                 C   s   |  |}|| dS )zIValidate an event against a schema within this
        registry.
        N)r.   validate)r   r    r0   r&   r   r   r   validate_eventL   s   
zSchemaRegistry.validate_eventr#   )r   r   r	   r
   r   dictr   r   boolr   r   r   r"   propertyr%   r   r(   r.   r/   r2   r   r   r   r   r      s    	
r   N)	r
   typingr   r   r&   r   	Exceptionr   r   r   r   r   r   <module>   s
    