a
    ø£BeØ
  ã                   @  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   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_events/schema_registry.pyr   	   s   r   c                   @  s¢   e Zd ZdZd$ddœdd„Zddd	œd
d„Zddœdd„Zdddœdd„Zeddœdd„ƒZ	dddœdd„Z
dddœdd„Zdddœdd„Zdd dd!œd"d#„ZdS )%ÚSchemaRegistryz>A convenient API for storing and searching a group of schemas.Nzdict[str, EventSchema] | None)Úschemasc                 C  s   |pi | _ dS )zInitialize the registry.N©Ú_schemas)Úselfr   r   r   r   Ú__init__   s    zSchemaRegistry.__init__ÚstrÚbool)Ú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__   s    zSchemaRegistry.__contains__)r   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>   ó    z+SchemaRegistry.__repr__.<locals>.<listcomp>)Újoinr   Úvalues©r   r   r   r   Ú__repr__   s    zSchemaRegistry.__repr__r   ÚNone)Ú
schema_objr   c                 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._addz	list[str]c                 C  s   t | j ¡ ƒS )N)Úlistr   Úkeysr   r   r   r   Ú
schema_ids%   s    zSchemaRegistry.schema_idsz$dict[str, Any] | (str | EventSchema))Úschemar   c                 C  s    t |tƒst|ƒ}|  |¡ |S )zŠAdd 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_r   c                 C  s:   z| j | W S  ty4   d|› d�}t|ƒd‚Y n0 dS )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  s:   z| j |= W n( ty4   d|› d�}t|ƒd‚Y n0 dS )z_Remove a given schema. If the schema is not found,
        this will raise a KeyError.
        r,   r-   Nr.   r0   r   r   r   ÚremoveA   s    
ÿzSchemaRegistry.removezdict[str, Any])r+   Údatar   c                 C  s   |   |¡}| |¡ dS )zIValidate an event against a schema within this
        registry.
        N)r1   Úvalidate)r   r+   r3   r(   r   r   r   Úvalidate_eventN   s    
zSchemaRegistry.validate_event)N)r   r   r	   r
   r   r   r   r$   Úpropertyr'   r*   r1   r2   r5   r   r   r   r   r      s   	r   N)
r
   Ú
__future__r   Útypingr   r(   r   Ú	Exceptionr   r   r   r   r   r   Ú<module>   s
   