
    -e<                        d Z ddlmZ ddlZ ej        e          ZddlZddlm	Z	 ddl
mZ ddlmZ dd	lmZ d
Z G d de          ZdS )a   Provide a Bokeh Application Handler to build up documents by running
the code from Jupyter notebook (``.ipynb``) files.

This handler is configured with the filename of a Jupyter notebook. When a
Bokeh application calls ``modify_doc``, the code from all the notebook cells
is collected and executed to process a new Document for a session. When the
notebook code is executed, the Document being modified will be available as
``curdoc``, and any optionally provided ``args`` will be available as
``sys.argv``.

    )annotationsN)
ModuleType   )PathLike)import_required   )CodeHandler)NotebookHandlerc                  4     e Zd ZdZdZdZg ddd fdZ xZS )r
   zX A Handler that uses code in a Jupyter notebook for modifying Bokeh
    Documents.

    zI%s: call to %s() ignored when running notebooks with the 'bokeh' command.NotebookN)argvpackagefilenamer   r   	list[str]r   ModuleType | NonereturnNonec               D   t          dd          }t          dd          } G d d|j        j                  } |            g}t          |d          5 }|                    ||j                  }	|                                }
|D ]}|
                    |           |
                    |	          \  }}|	                    dd	          }|	                    d
d	          }ddd           n# 1 swxY w Y   t                                          ||||           dS )zg

        Keywords:
            filename (str) : a path to a Jupyter notebook (".ipynb") file

        nbformatzQThe Bokeh notebook application handler requires Jupyter Notebook to be installed.	nbconvertc                  F    e Zd ZdZ ej        d          Zd
dZd Zd Z	d	S )6NotebookHandler.__init__.<locals>.StripMagicsProcessorz
            Preprocessor to convert notebooks to Python source while stripping
            out all magics (i.e IPython specific syntax).
            z^\s*(?P<magic>%%\w\w+)($|(\s+))sourcestrr   c                X   g }|                                 D ]}| j                            |          }||                    |           4d}|                    | j        |                    d                    }t                              |           d	                    |          S )zb
                Given the source of a cell, filter out all cell and line magics.
                Nz7Stripping out IPython magic {magic} in code cell {cell}magic)cellr   
)

splitlines_magic_patternmatchappendformat_cell_countergrouplogwarningjoin)selfr   filteredliner!   msgmessages          Clib/python3.11/site-packages/bokeh/application/handlers/notebook.pystrip_magicszCNotebookHandler.__init__.<locals>.StripMagicsProcessor.strip_magicsT   s     ')"--// - -D /55d;;E} ----W"%**$2DEKKX_L`L`*"a"aG,,,,yy***    c                ~    |d         dk    r.| xj         dz  c_         |                     |d                   |d<   ||fS )N	cell_typecoder   r   )r$   r/   )r)   r   	resourcesindexs       r.   preprocess_cellzFNotebookHandler.__init__.<locals>.StripMagicsProcessor.preprocess_cellc   sK    $..&&!+&&%)%6%6tH~%F%FDNY&r0   c                <    d| _         |                     ||          S )Nr   )r$   
preprocess)r)   nbr4   s      r.   __call__z?NotebookHandler.__init__.<locals>.StripMagicsProcessor.__call__i   s    %&"r)444r0   N)r   r   r   r   )
__name__
__module____qualname____doc__recompiler    r/   r6   r:    r0   r.   StripMagicsProcessorr   L   sd         
 (RZ(JKKN+ + + +' ' '5 5 5 5 5r0   rB   zutf-8)encodingzget_ipython().run_line_magic zget_ipython().magicN)r   r   r   r   )r   preprocessorsPreprocessoropenread
NO_CONVERTPythonExporterregister_preprocessorfrom_notebook_nodereplacesuper__init__)r)   r   r   r   r   r   rB   rE   fr9   exporterpreprocessorr   _	__class__s                 r.   rO   zNotebookHandler.__init__B   s    #:  0C  D  D#K  2E  F  F		5 	5 	5 	5 	59#:#G 	5 	5 	5B .-//0(W--- 		?q("566B //11H - = =..|<<<< 33B77IFA^^$BBGGF^^$92>>F		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 		? 	gVVVVVs   BC00C47C4)r   r   r   r   r   r   r   r   )r;   r<   r=   r>   _logger_text_originrO   __classcell__)rT   s   @r.   r
   r
   8   sp         
 _LG@Bae 8W 8W 8W 8W 8W 8W 8W 8W 8W 8W 8W 8Wr0   r
   )r>   
__future__r   logging	getLoggerr;   r&   r?   typesr   
core.typesr   util.dependenciesr   r3   r	   __all__r
   rA   r0   r.   <module>r_      s   
 
 # " " " " " g!! 
			       # " " " " " 0 0 0 0 0 0      BW BW BW BW BWk BW BW BW BW BWr0   