
    e(                     N   d dl Z d dlmZ d dlZd dlmZ d dlmZmZ d dlm	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dlmZ ddlmZ ddlmZmZmZmZ ddlmZ ddge_         d Z! G d de          Z" G d de          Z#e#$                    ej%                   d Z&d Z'dS )    N)SkipTest)IPCompleter)HTMLpublish_display_data)ipython   )LabelledData)Store)AttrTree)ComparisonTestCase)Renderer)	extension   )displaypng_displaypprint_displaysvg_display)load_magics_repr_'_ipython_canary_method_should_not_existc                  0    ddl m}  t          |            dS )zQ
    Display the full traceback after an abbreviated traceback has occurred.
    r   FULL_TRACEBACKN)display_hooksr   printr   s    :lib/python3.11/site-packages/holoviews/ipython/__init__.pyshow_tracebackr      s*     .-----	.    c                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )
IPTestCasez
    This class extends ComparisonTestCase to handle IPython specific
    objects and support the execution of cells and magic.
    c                    t                                                       	 dd l}ddlm}m} |                                | _        | j        t                      n"# t          $ r}t          d          |d }~ww xY wd | j        j        _        |                     || j                   |                     || j                   d S )Nr   )r   SVGzIPython could not be startedc                      d S N r%   r   r   <lambda>z"IPTestCase.setUp.<locals>.<lambda>/   s    D r   )supersetUpIPythonIPython.displayr   r"   InteractiveShellip	TypeError	Exceptionr   displayhookflushaddTypeEqualityFuncskip_comparison)selfr)   r   r"   e	__class__s        r   r(   zIPTestCase.setUp$   s    	BNNN11111111..00DGwkk!  	B 	B 	B9::A	B %1L!  t';<<<  t';<<<<<s   :A 
A=(A88A=c                     d S r$   r%   )r3   obj1obj2msgs       r   r2   zIPTestCase.skip_comparison3   s      r   c                 x    | j                             |          j        }||                     d|           |S )NzCould not find object )r,   _object_findobjfailureException)r3   namer<   s      r   
get_objectzIPTestCase.get_object5   sA    g""4((,;''(G(G(GHHH
r   c                 >    | j                             |d           dS )zRun an IPython cellT)silentN)r,   run_cell)r3   lines     r   cellzIPTestCase.cell<   s#    d+++++r   c                 *     | j         j        |i | dS )zRun an IPython cell magicN)r,   run_cell_magicr3   argskwargss      r   
cell_magiczIPTestCase.cell_magic@   "    //////r   c                 *     | j         j        |i | dS )zRun an IPython line magicN)r,   run_line_magicrG   s      r   
line_magiczIPTestCase.line_magicE   rK   r   )__name__
__module____qualname____doc__r(   r2   r?   rD   rJ   rN   __classcell__r5   s   @r   r    r       s         
= = = = = 544  , , ,0 0 0
0 0 0 0 0 0 0r   r    c                   ~    e Zd ZdZ ej        dd          Z ej        dd          Z ej        dd          Z	 ej
        d	d
d          Z ej        dgd          Z ej        dd          Z ej        dd          Z ej        dd          ZdZ fdZed             Zd Zedd            Z xZS )notebook_extensionzw
    Notebook specific extension to hv.extension that offers options for
    controlling the notebook environment.
     z/Optional CSS rule set to apply to the notebook.)defaultdocTz!Toggles display of HoloViews logoFzx
        Whether to inline JS and CSS resources.
        If disabled, resources are loaded from CDN if one is available.N)r   d   zR
        Width of the notebook as a percentage of the browser screen window width.)rX   boundsrY   htmla  
        A list of formats that are rendered to the notebook where
        multiple formats may be selected at once (although only one
        format will be displayed).

        Although the 'html' format is supported across backends, other
        formats supported by the current backend (e.g. 'png' and 'svg'
        using the matplotlib backend) may be used. This may be useful to
        export figures to other formats such as PDF with nbconvert.z
       Whether to allow jedi tab-completion to be enabled in IPython.
       Disabled by default because many HoloViews features rely on
       tab-completion machinery not supported when using jedi.z[
       Whether to monkey patch IPython to use the correct tab-completion
       behavior. z>
        Whether to load bokeh-mathjax bundle in the notebook.c                 N	   |                     dd           } t                      j        |i | 	 |                     dd           pt                      }n# t          $ r Y d S w xY w	 dd l}	 ddlm} |t          _        n+# t          $ r}t          |          dk    r Y d }~nd }~ww xY wn# t          $ r Y nw xY wdt          j        v rWt          j        sKt          j        d                             d d	          }|gt          j        j        z   t          j        _        t%          j        | d
 |                                D                       }	|	j        rddlm}
 | j        |
_        |	j        s+t5          t6          d          r|                    dd           |                     ||          }|	j        t          _        d|	j        vrAt?          |	j                  dk    r)d|	j        z  }tA          tC          d|                      t          j        }|dk    rtE          j#        |d           tI          |           t          j%        &                    tO          t          j        (                                                     t          j)        dtT          tV                     t          j)        dtT          tX                     t          j)        dtT          tZ                     dt          _        d}|	j.        |d|	j.        z  z  }|	j/        r|d|	j/         dz  }|rtA          tC          |                     tO          |          }t?          |          dk    rd S ddl0m1}m2} t5          |d          r	|r||_3        ti          | dd          x}}d |D             D ]-}t          j        |         5                    |	j6                   .to          j5        |	j6        ||	j8                   |s$t5          |d           r|9                                 t5          |d!          r,|s*tn          j:        ;                    t          j<        d"           |sI|	j=        rD| >                    |	j=        |	j=        od#|v |	j=        o
d|v p|d$gk    |	j=        od%|v &           d S d S d S )'Ncommsr,   r   r   )notebook_archivez4module 'tornado.web' has no attribute 'asynchronous'
matplotlibsvg)holomapfigc                 &    i | ]\  }}|d k    ||S )configr%   ).0kvs      r   
<dictcomp>z/notebook_extension.__call__.<locals>.<dictcomp>   s#    'U'U'U!H!r   )	completeruse_jedire   zIPCompleter.use_jedi = Falser\   zdOutput magic unable to control displayed format as IPython notebook uses fixed precedence between %rz<b>Warning</b>: F)verbosezhtml+jspngTrW   z,<style>div.container { width: %s%% }</style>z<style>z</style>)re   r   _repeat_execution_in_cellc                     g | ]
}|d k    |S )	holoviewsr%   )rf   rs     r   
<listcomp>z/notebook_extension.__call__.<locals>.<listcomp>   s"    ;;;!{*:*:!*:*:*:r   )inline)rs   	reloadingenable_mathjax_display_globalskernelzhv-extension-commbokehrp   plotlylogo
bokeh_logompl_logoplotly_logo)?popr'   __call__get_ipythonr.   nbformatarchiver_   hvAttributeErrorstrImportErrorr
   	renderersrV   _loadedinstance	exportersparamParamOverridesitemscase_sensitive_completionIPython.corerj   completions_sorting_keyallow_jedi_completionhasattrr   rM   _get_resourcesdisplay_formatslenr   r   	param_extload_ipython_extensionr   output_settings
initializelistkeysset_display_hookr	   r   r   r   widthcsspanelre   r   r^   getattrload_nbrs   r   ru   rv   comm_managerget_client_comm_process_comm_msgr{   	load_logo)r3   rH   paramsr^   r,   r   r_   r4   svg_exporterprj   	resourcesr9   loadedr   re   panel_extensionsame_cell_execution	publishedrq   r5   s                       r   r   znotebook_extension.__call__s   s6   

7D))$)&)))	D$''8;==BB 	 	 	FF		OOO555555-

!   q66SSS TSSSS  	 	 	D	 5?**3E3M* ?<8AA$SXAYYL$0>BJ4H#HBJ  'U'Uv||~~'U'U'UVV& 	M......040LI-& 	H7;
+K+K 	Hh(FGGG''f55	 ! 1***s13D/E/E/I/I "#"34C D1C1122333#+U??,R????OOO!,,T%/2F2F2H2H-I-IJJJ"9lNKKK"5,DDD"5,DDD)-&7AAGKKC5 	-,QU,,,,C 	DIIOO	y>>Q>>>>>>>>67## 	! 	! FL*1$8SUZ*[*[[i;;Y;;; 	8 	8AOA&&ah&77774GXYXhiiii 	/W_6HII 	/,,...2x   	G 	G!112D2V2EG G G # 	Lqv 	LNN()(IGy4H() )Q\Y5N 5P7@;-7O()(JH	4I	  L L L L L	L 	L 	L 	LsM   $A 
A%$A%)B- .B  B- 
B)B$B- $B))B- -
B:9B:c                 X   d\  }}|                     d          rd}n|                     d          rd}|                    d          rd}|                     d          rd	|dd
         vr|dd
         d}}n-|                     d	          rd	|dd
         vr|dd
         d}}|||fS )z9Fixed version of IPyton.completer.completions_sorting_key)r   r   __r   _r   =z%%%N)
startswithendswith)clswordprio1prio2s       r   r   z*notebook_extension.completions_sorting_key   s     u??4   	-155__S!!,15==-25??4   	*$qrr("""122he__S!! 	*$qrr("""122hedE!!r   c                 .   g }g dgt          t          j                                                  z   D ]p}||v r|                    |           ||v rQ|                    |          }|du r|dk    r||vr|                    |           |du r                    |           qt          |          t          |          z
  }|r2t          t          dd	                    |          z                       fd|D             }dvr
d|vrdg|z   }|S )z}
        Finds the list of resources from the keyword parameters and pops
        them out of the params dictionary.
        rp   Tr`   Fz+<b>Warning:</b> Unrecognized resources '%s'z', 'c                     g | ]}|v|	S r%   r%   )rf   rq   disableds     r   rr   z5notebook_extension._get_resources.<locals>.<listcomp>   s#    ???1Qh->->Q->->->r   )
r   r
   r   r   appendr   setr   r   join)r3   rH   r   r   resourcesettingunmatched_argsr   s          @r   r   z!notebook_extension._get_resources   s\   
 	$U_-A-A-C-C(D(DD 
	. 
	.H4  ***6!! **X..d??x<'?'?y00!((222e##OOH---TS^^3 	9DF!;;~667 8 8 9 9 9 @???	???	x''k.J.J$	1Ir   c                 d   ddl }|                    t          j                            t          j                            t                                        }|                    |          }|                    d          }|	                    ||||d          }	t          d|	i           dS )zU
        Allow to display Holoviews' logo and the plotting extensions' logo.
        r   N)loaderzload_notebook.htmlrz   z	text/html)data)jinja2FileSystemLoaderospathdirnameabspath__file__Environmentget_templaterenderr   )
r   r{   r|   r}   r~   r   templateLoaderjinjaEnvtemplater\   s
             r   r   znotebook_extension.load_logo   s    
 	00QYAZAZ1[1[\\%%^%<<(()=>>t/9/7/: <  < = = 	;"5666666r   )FFFF)rO   rP   rQ   rR   r   Stringr   Booleanr{   rs   Numberr   Listr   r   r   ru   r   r   classmethodr   r   r   rS   rT   s   @r   rV   rV   J   s        
 %,r'X
Y
Y
YC5=+NOOODU]5 /K L L LF ELh =U V V VE !ej& 8G H H HO *EM$ =B C C C
 !.e B ! ! ! #U]5 7A B B BN GXL XL XL XL XLt " " ["  : 7 7 7 [7 7 7 7 7r   rV   c                 &    t          |            d S )Nr,   )rV   r   s    r   r   r     s    "r   c                     dt           _        d S )NF)rV   r   r   s    r   unload_ipython_extensionr     s    !&r   )(r   unittestr   r   IPython.core.completerr   r*   r   r   r   r   rp   r   core.dimensionr	   core.optionsr
   	core.treer   element.comparisonr   plotting.rendererr   utilr   r   r   r   r   r   magicsr   _disabled_prefixesr   r    rV   add_delete_action_delete_plotr   r   r%   r   r   <module>r      s   				        . . . . . . 6 6 6 6 6 6 6 6 & & & & & &     ) ) ) ) ) )                         3 3 3 3 3 3 ( ( ( ( ( (       L L L L L L L L L L L L      '(QR   )0 )0 )0 )0 )0# )0 )0 )0X~7 ~7 ~7 ~7 ~7 ~7 ~7 ~7B  $ $X%: ; ; ;  ' ' ' ' 'r   