o
    tf|                     @  s   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	m
Z
mZ ddlmZmZ ejr1d dlmZ eG dd	 d	eZdddZdS )    )annotationsN)Magics
cell_magic
line_magicmagics_class)argumentmagic_argumentsparse_argstring   )_VIRTUAL_FILESVirtualFileContents)InteractiveShellc                      sR   e Zd ZdZd fddZe eded	d
edddZ	e
dddZ  ZS )AnyWidgetMagicsz7A set of IPython magics for working with virtual files.shellr   returnNonec                   s   t  | i | _dS )zInitialize the magics.N)super__init___files)selfr   	__class__ ]/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/anywidget/_cellmagic.pyr      s   
zAnyWidgetMagics.__init__	file_namezThe name of the virtual file.)typehelplinestrcellc                 C  sp   t tj|}dtt|j }td| j}||}|| j	v r)|| j	| _
dS t|}|| j	|< |t|< dS )z4Create a virtual file with the contents of the cell.zvfile:r   N)r	   r   vfiletypingcastr   r   r   Ztransform_cellr   contentsr   r   )r   r   r   argsnamer   coder    r   r   r   r       s   


zAnyWidgetMagics.vfilec                 C  s   | j   dS )zClear all virtual files.N)r   clear)r   r   r   r   r   clear_vfiles(   s   zAnyWidgetMagics.clear_vfiles)r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   r   r   r   r   r    r   r(   __classcell__r   r   r   r   r      s    r   ipythonr   r   r   c                 C  s   |  t dS )zLoad the IPython extension.

    Parameters
    ----------
    ipython : IPython.core.interactiveshell.InteractiveShell
        The IPython shell instance.
    N)Zregister_magicsr   )r.   r   r   r   load_ipython_extension.   s   r/   )r.   r   r   r   )
__future__r   r!   ZIPython.core.magicr   r   r   r   ZIPython.core.magic_argumentsr   r   r	   Z_file_contentsr   r   TYPE_CHECKINGZIPython.core.interactiveshellr   r   r/   r   r   r   r   <module>   s    