
    -PhY                     r   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddl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Zdd	lmZmZ dd
lmZm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG ejH        jI        J                    d          ZK G d d          ZLdZMdZNdZOdZPdZQdZRdZSdZTdZUdZVd ZWd!ZXdOd#ZYd$ ZZd% Z[d& Z\dPd(Z]d) Z^dQd+Z_d, Z`d- Za	 dQd.Zbd/ ZcdRd0Zdeje        d1             Zf G d2 d3          Zgd4 Zhd5 Zid6 Zjd7 Zkd8 Zld9 Zmd: Znd; Zod< ZpdSd=Zqd> Zrd? Zsd@ ZtdA ZudB ZvdCZwdDZxd"dEdFZyd"dEdGZzdSdHZ{dI Z|dJdKdLZ}dM Z~ e            dN             ZdS )TzreST file generator.

Generate the rst files for the examples by iterating over the python
example files.

Files that generate images should start with 'plot'.
    N)	lru_cache)StringIO)Path)copyfile)indent)time)ConfigErrorExtensionError)blueboldred   )glr_path_staticpy_source_parser)THUMBNAIL_PARENT_DIVTHUMBNAIL_PARENT_DIV_CLOSE_make_ref_regex_thumbnail_div_write_backreferencesidentify_names)BlockParser)_add_jupyterlite_badge_logogen_binder_rstgen_jupyterlite_rst)jupyter_notebooksave_notebook)ImagePathIterator_find_image_ext_reset_dict_scraper_dictclean_modulessave_figures)_W_KW_collect_gallery_files_combine_backreferences_format_toctree_replace_md5_write_json
get_md5sumoptipngscale_imagestatus_iterator	zip_fileszsphinx-galleryc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zed             Zed             Zd Zd ZdS )_LoggingTeez/A tee object to redirect streams to the logger.c                 ~    t           | _         || _        d| _        |                                  d| _        d| _        d S )N Futf-8)loggersrc_filenamelogger_bufferset_std_and_reset_positionclosedencoding)selfr4   s     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/gen_rst.py__init__z_LoggingTee.__init__R   s?    ('')))     c                     t          t          j        t                    st          j        t          j        f| _        | xt          _        t          _        d| _        t                      | _        | S NT)	
isinstancesysstdoutr/   stderrorigsfirst_writer   outputr9   s    r:   r6   z&_LoggingTee.set_std_and_reset_position\   sL    #*k22 	2*cj1DJ"&&
SZjjr<   c                     t           j                                         t           j                                         | j        \  t           _        t           _        d S N)r@   rA   flushrB   rC   rF   s    r:   restore_stdz_LoggingTee.restore_stdd   s>    

!%
CJJJr<   c                 l   | j                             |           | j        r)| j                            d| j        d           d| _        | j        |z   }|                                }|r"|d         dvr|d         | _        |d d         }nd| _        |D ]}| j                            d|           d S )	NzOutput from %sbrown)colorFz
r1   %s)rE   writerD   r3   verboser4   r5   
splitlines)r9   datalineslines       r:   rP   z_LoggingTee.writei   s    $ 	%K 0$2C7SSS$D!D(!! 	$DHF** "'rD#2#JEE!#D 	, 	,DKd++++	, 	,r<   c                     | j                                          | j        r)| j                            d| j                   d| _        d S d S )NrO   r1   )rE   rI   r5   r3   rQ   rF   s    r:   rI   z_LoggingTee.flush}   sT     	$Kd&8999!#D	$ 	$r<   c                     d S rH    rF   s    r:   closez_LoggingTee.close   s    r<   c                 4    | j                                         S rH   )rE   filenorF   s    r:   r[   z_LoggingTee.fileno       {!!###r<   c                 4    | j                                         S rH   )rE   isattyrF   s    r:   r^   z_LoggingTee.isatty   r\   r<   c                     dS NFrX   rF   s    r:   readablez_LoggingTee.readable       ur<   c                     dS r`   rX   rF   s    r:   seekablez_LoggingTee.seekable   rb   r<   c                 4    | j                                         S rH   )rE   tellrF   s    r:   rf   z_LoggingTee.tell   s    {!!!r<   c                     dS r>   rX   rF   s    r:   writablez_LoggingTee.writable   s    tr<   c                     | j         j        S rH   )rE   errorsrF   s    r:   rj   z_LoggingTee.errors   s    {!!r<   c                     | j         j        S rH   )rE   newlinesrF   s    r:   rl   z_LoggingTee.newlines   s    {##r<   c                     | S rH   rX   rF   s    r:   	__enter__z_LoggingTee.__enter__   s    r<   c                 .    |                                   d S rH   )rJ   )r9   type_valuetbs       r:   __exit__z_LoggingTee.__exit__   s    r<   N)__name__
__module____qualname____doc__r;   r6   rJ   rP   rI   rY   r[   r^   ra   rd   rf   rh   propertyrj   rl   rn   rs   rX   r<   r:   r/   r/   O   s"       99       , , ,
, , ,($ $ $  $ $ $$ $ $    " " "   " " X" $ $ X$      r<   r/   z%
.. rst-class:: sphx-glr-horizontal

zD
    *

      .. image:: /%s
            :class: sphx-glr-multi-img
z0
.. image:: /%s
    :class: sphx-glr-single-img
z?.. rst-class:: sphx-glr-script-out

 .. code-block:: none

{0}
zm
.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ({0:.0f} minutes {1:.3f} seconds)

z

.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
z|.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
{0}
    </div>
    <br />
    <br />zf
.. _sphx_glr_download_{0}:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example
zv
    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download {1} source code: {0} <{0}>`
zx
    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: {0} <{0}>`
zj
    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: {0} <{0}>`
z#

.. include:: {0}.recommendations
pythonc                 4   |A|                      ddt          |                                                      }d||z    d}nd}d}|                                 D ]}|r|                    d          sd} nd| d| | d}t          | d	          }||z   S )
z4Return reStructuredText code block from code string.N
r   z   :lineno-start: r1   z   :dedent: 1
) 	z.. code-block::     )countlenlstriprR   
startswithr   )codestrlanglinenoblank_linesdedentrU   code_directiveindented_blocks           r:   codestr2rstr      s    mmD!c'..2B2B.C.C-CDD>f{&:>>>F""$$   	44 	FEBBBBBBBNGW--NN**r<   c                     |                                  } | d         | d                             d          d         z   | d         z   S )Nr   r   .rN      )groupssplit)xs    r:   _regroupr     s:    	

AQ4!A$**S//"%%!,,r<   c                 T   d\  }}t          j        |dz   |z   d|           } t          j        |dz   |z   t          |           } t          j        |dz   |z   d|           } d}t          j        |dz   |z   d|           } t          j        |dz   |z   t          |           } t          j        |dz   |z   d|           } t          j        d	d
|           } t          j        dd
|           } t          j        dd
|           } t          j        dd
|           } |                     dd          } | S )z4Use regex to remove at least some sphinx directives.)z(\s|^):[^:\s]+:`z`(\W|$)z\S+\s*<([^>`]+)>z\1\2\3z~([^`]+)z([^`]+)z(\s|^)`z	`([^`]+)`z
\.?([^`]+)z\*\*([^\*]*)\*\*z\1z\*([^\*]*)\*z`([^`<>]+) <[^`<>]+>`\_\_?z :[a-z]+:`([^`<>]+)( <[^`<>]+>)?`z\\\)resubr   replace)stringpes      r:   _sanitize_rstr     s/    +DAqVA++a/FCCFVAOa'6::FVA
NQ&	6::F 	AVA$q()V<<FVAOa'6::F VA%)9f==F V'77FVOUF33FV15&AAF V7GGF ^^FD))FMr<   c                 B   |                                                     d          }d |D             }t          |          dk    r"t          d                    |                     |d         }t          j        d|t
          j                  }|t          d|           |                    d          	                                }t          |          dk     r|n|d	         }t          j
        d
d|          }t          |          }t          |          }||fS )z@Extract and clean the first paragraph of module-level docstring.

c                 b    g | ],}|                     d           t          |          dk    *|-S )z.. r   )r   r   ).0r   s     r:   
<listcomp>z+extract_intro_and_title.<locals>.<listcomp><  s5    RRRq||E/B/BRs1vvPQzz!zzzr<   r   zaExample docstring should have a header for the example title. Please check the example file:
 {}
z^(?!([\W _])\1{3,})(.+)Nz+Could not find a title in first paragraph:
r   r   r{   r|   )r   r   r   r
   formatr   search	MULTILINEgroupstripr   r   )filename	docstring
paragraphstitle_paragraphmatchtitleintro_paragraphintros           r:   extract_intro_and_titler   7  s    !!##))&11JRRZRRRJ
:!44:F84D4D
 
 	
 !mOI0/2<PPE}L?LL
 
 	
 KKNN  ""E":22ee
1OF4o..E%  E%  E%<r<   bc                    t          | |          }t          |           dz   }t          j                            |          sdS t          |          5 }|                                }ddd           n# 1 swxY w Y   ||k    S )zAChecks whether src_file has the same md5 hash as the one on disk.mode.md5FN)r)   strospathexistsopenread)src_filer   src_md5src_md5_filefile_csref_md5s         r:   md5sum_is_currentr   X  s    ---Gx==6)L7>>,'' u	l		 !w,,..! ! ! ! ! ! ! ! ! ! ! ! ! ! ! gs   A55A9<A9c                 &   t           j                            t           j                            |           d          }t          j        |d           |                    dd          }|                    dd          }||d}|'t           j                            |d         |          }n]t          |t                    st          d	|          |d
k     r|t          |d                   dz   z  }| 
                    |          }~~~ t          |          \  }	}
t           j                            t           j                            |                    d
         }t           j                            |d| d|
           }d|v rC|                    dd          r-t           j                            t                      d          }nt           j                            |	          r|	}njt           j                            |          sI|d         }|,t           j                            t                      d          }t          |          \  }}
ndS t           j                            |          d
          d|
 }|
dv rt!          ||           n4t#          ||g|d         R   d|d         v rt%          ||d                    t           j                            |          d
         dd          |
 }t'          ||           dS )a  Generate and Save the thumbnail image.

    Parameters
    ----------
    image_path_template : str
        holds the template where to save and how to name the image
    src_file : str
        path to source python file
    script_vars : dict
        Configuration and run time variables
    file_conf : dict
        File-specific settings given in source file comments as:
        ``# sphinx_gallery_<name> = <value>``
    gallery_conf : dict
        Sphinx-Gallery configuration dictionary
    thumbTexist_okthumbnail_numberNthumbnail_pathr   src_dirz=sphinx_gallery_thumbnail_number setting is not a number, got r   image_path_iterator	sphx_glr_z_thumb.formatted_exceptionfailing_thumbnailzbroken_example.pngdefault_thumb_fileno_image.pngz.new.)svggifthumbnail_size
thumbnailscompress_imagescompress_images_args)	fname_old)r   r   joindirnamemakedirsgetr?   intr
   r   r   r   splitextbasenamer   r   r   r+   r*   r'   )image_path_templater   script_vars	file_confgallery_conf	thumb_dirr   r   
image_paththumbnail_image_pathextbase_image_name
thumb_fileimgdefault_thumb_pathr   s                   r:   save_thumbnailr   f  s   " RW__-@AA7KKIK	D)))) !}}%7>>]]#3T::NN$:W\\,y"9>JJ

*C00 	 ,', ,  
 aK0E$F G G! KK(//0@AA
.*= /
 ; ;#g&&rw'7'7'A'ABB1EOi)R_)R)RS)R)RSSJ++	T1 1+ gll?,,.BCC	,	-	- "W^^J'' 
)*>?%!#!!" " ##566SS G$$Z003??#??J
nj!!!!CEl3C&DEEEE<(9:::J-C DEEE7##J//23B37>>>Iy111111r<   Tc                    t          j        |d         d          rAt          j                            | d          }t          j                            |          rdS dgt          |d                   z   }|D ]O}dD ]J}t          j                            | ||z             }t          j                            |          r|c c S KP|r#t          d                    | |                    dS )zGet gallery header from GALLERY_HEADER.[ext] or README.[ext] file.

    Returns `None` if user supplied an index.rst or no gallery header file
    found and `raise_error=False`.
    copyfile_regexz	index.rstNz.txtsource_suffix)GALLERY_HEADERREADMEreadmezExample directory {} does not have a GALLERY_HEADER file with one of the expected file extensions {}. Please write one to introduce your gallery.)	r   r   r   r   r   isfilesortedr
   r   )dir_r   raise_errorfpth
extensionsr   fnames          r:   _get_gallery_headerr     s    
x-.<< w||D+..7>>$ 	4F<#@AAAJ  ; 	 	E7<<eck22Dw~~d## 	  
&&,fT:&>&>
 
 	

 4r<   c           	      .   d}| d         r	|s|rt           j                            |d          }t           j                            || d                   }t	          |dfi t
          5 }|                    d                    |                    t           j	        d                               |                    |           t          |          dk    r$t          |          }	|                    |	           ddd           n# 1 swxY w Y   |S )	zWrite `index.rst` file for subsection if user has not provided index file.

    Returns path to index file written or `None` if no index file written as user
    provided one.
    Nnested_sectionszindex.rst.newr   wz

.. _sphx_glr_{}:

_r   )r   r   r   relpathr   r#   rP   r   r   sepr   r&   )
r   user_index_rstis_subsection
target_dirindex_contenttoctree_filenames
index_pathhead_reffindexsubsection_index_toctrees
             r:   _write_subsection_indexr    sI    J%& 7~ 7- 7W\\*o>>
7??:|I/FGG*c++U++ 	7vLL*11(2B2B2632O2OPP   LL'''$%%))+:;L+M+M(5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 s   +BD

DDc                 j   | d         rfdt          j        |          D             }rfd|D             }|D ]s}t           j                            t           j                            ||                    }t           j                            ||          }t          ||d           rdS dS )z'Copy non-example files to `target_dir`.r   c                 >    g | ]}t          j        |          |S rX   )r   r   )r   r   	copyregexs     r:   r   z+_copy_non_example_files.<locals>.<listcomp>  s+    XXXURXiQV=W=WX5XXXr<   c                 D    g | ]}|t                    j        k    |S rX   )r   name)r   r   header_fnames     r:   r   z+_copy_non_example_files.<locals>.<listcomp>  s.    VVVUd<>P>P>U5U5Uu5U5U5Ur<   copy)r   methodN)r   listdirr   normpathr   r'   )	r   r   r  r   r  r   r   target_filer  s	     `     @r:   _copy_non_example_filesr    s    -.I IXXXXbj&9&9XXX 	WVVVV'VVVG 	I 	IEw''We(D(DEEH',,z599K[HHHHHI I
	I 	Ir<   c                    # d}t                     }d}|rEd}t          |dd          5 }|                                }	||	z  }ddd           n# 1 swxY w Y   |dz  }t          j        d	           t          j                            d
          }
t          j        |
d	           t          j                            |
d          }t          j        |d	           d         t          |
           t           g          }t          |t          d           d                   }|t          z  }g }g }t          j                            d                   }t          |d| dt          |                    }i }t          }t           #d         r-ddlm}m}  |t                     # |d         ddd          } |# fd|D                       }t)          |          D ]\  }\  }}\  }}}||         }t          j                            t          j                             |                    }|d         |<   d|v rd|vsJ d|vsJ |d         d         |<   nKd|v r"d|vsJ d                              |           n%d|v r!d!                             |d                    |                    t/          |||"                     t1          |          |z                      d                                          }t7          d         |||          } || z  }|                    d#|z              d$|v r,t9          |d$         | |||          }!t;          ||!           |t<          z  }t?          ||||          }"|rd}tA           |           |"||||fS )%a  Generate output example reST files for one gallery (sub)directory.

    Parameters
    ----------
    src_dir: str,
        Path to root or sub gallery directory containing example files
    target_dir: str,
        Path where parsed examples (rst, python files, etc) will be outputted
    gallery_conf : Dict[str, Any]
        Gallery configurations.
    seen_backrefs: set,
        Back references encountered when parsing this gallery
        will be stored in this set.
    is_subsection: bool,
        Weather `src_dir` is a subsection dir. If subsection dir, we write
        a `index.rst` file with toctree listing every example file.
        Default=True.

    Returns
    -------
    index_path: str or None
        Path to index rst file for the `src_dir`. None if user provided
        own index.
    index_content: str or None
        Gallery header content. `None` when user provided own index.rst.
    costs: List[Dict]
        List of dicts of costs for building each element of the gallery
         with keys "t", "mem", "src_file", and "target_dir".
    toctree_items: list,
        List of example file names we generated ReST for.
    backrefs_dir : dict[str, tuple]
        Dictionary where value is the backreference object and value
        is a tuple containing: example filename, full path to example source directory,
        full path to example target directory, intro, title.

    r1   TFrr2   )r8   Nr   r   imagesr   jupyterlitewithin_subsection_orderr   )keyr   zgenerating gallery for z... )lengthparallel)Paralleldelayedn_jobsr   loky)r  pre_dispatch
batch_sizebackendc              3   4   K   | ]} |          V  d S rH   rX   )r   r   r   p_funr   r   s     r:   	<genexpr>z#generate_dir_rst.<locals>.<genexpr>^  sD        <AeZ,77     r<   titlesr   passingstalefailing_examplespassing_examplesstale_examples)tmemr   r   /backrefs)!r   r   r   r   r   r   r   r   r$   r   _get_callablesr   r   r,   r   listgenerate_file_rstjoblibr  r  	enumerater  appenddictr   with_suffixas_posixr   r   r%   r   r  r  )$r   r   r   seen_backrefsr   r   r  r   fidheader_content	image_dirr   r  sorted_listdircostsr   build_target_diriteratorbackrefs_dirr  r  r  resultsfir   r   r*  r+  out_varsr   r   gallery_item_filename
this_entrybackrefs_exampler  r"  s$   ```                                @r:   generate_dir_rstrF    s   V M&w==LN ,,g666 	,# XXZZN^+M	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,
 VM K
T****Z22IK	D))))Y00IK	D))))M".#I... %gY==G^L2KWUUVWX  N ))MEwz<	3JKK8"2888>""  H LHEJ 	
,,,,,,,,)**8
+!	
 
 
 h       EM    G 3<G2D2D %D %D..UE8AsXr"7##BGLL%$@$@AA+0Xx( !H,,H,,,,(****9ABW9XL+,X66(""(****+,33H====  )*11(72CDDDTA3jQQQRRR"##e+88<<EEGG 	 $Y/u
 

 	#  '<!<=== !!4$	  	  $L2BCCC //M ) J   L'<LLL 	 s   AAAc           
         ddl m} | \  }}}t          j        |          }d}	t	          |          }
t
          j                            t                    t
          j	        z   }t          |d          D ]\  }}|j                            d          rt          ||	          }	0|j                            |dz             rm|j        dk    r#d|j        v s	d|j        v rt          ||	          }	{|j        d	k    rt          ||	          }	|j        d
k    r|t	          |          k    r|dz
  }
||	|
         }dd                    t          j        |          t          j        ||          z             z   }| ||          v }t
          j                            ||d                   }|rt(          j        t,          d}}}nt(          j        t0          d}}} |dt3           |d                     d| d| |t5          |d                               t7          |d          }|d         r ||d<   d|d<   d|z   }|S )z2Trim and format exception, maybe raise error, etc.r   )_expected_failing_examplesr   _sg_call_memoryz
gen_rst.pyexecute_code_blockzcompile(r"   __call___check_inputz#Traceback (most recent call last):
r1   r   
expectedlyunexpectedlyr{   rO   r|   z! failed to execute correctly:

%sr~   pytb)r   abort_on_example_errorr   Fexecute_scriptz$.. rst-class:: sphx-glr-script-out

)gen_galleryrH  	traceback
extract_tbr   r   r   r   __file__r   r2  r
  r   maxr   rU   r   format_listformat_exception_onlyr   r3   infor   warningr   r   r   r   )exc_infor   r   r   rH  etypeexcrr   stackstartstoprootiisr   expectedsrc_file_relfuncrM   kind
except_rsts                        r:   handle_exceptionri    s   777777NE3 $$E" Eu::D7??8$$rv-D5!$$  A6.// 	ENNEEZ""4,#677 	v---af$$!&(@(@B:%%B>))bCJJ.>.>Av%*E@277e$$y'Fuc'R'RRD D  55lCCCH7??8\)-DEEL @"K|Te"NCTeDJT%%++JJJJJf(&1122   0v>>>J ,- )<K%&$)K ! :JFJr<   c                     |t           j        }|d S t          j        | ||||          }	 |                    |           d S # t
          $ r Y d S w xY wrH   )r@   rB   warningsformatwarningrP   OSError)messagecategoryr   r   filerU   texts          r:   _showwarningrr    sq    |z< F!'8XvtLLD

4   s   A 
AAc               #      K   t           j        } 	 t          t           _        dV  | t           _        dS # | t           _        w xY w)z=Patch warnings.showwarning to actually write out the warning.N)rk  showwarningrr  )orig_showwarnings    r:   patch_warningsrv    sJ      
  +0+//////s	   3 Ac                       e Zd ZdZd Zd ZdS )
_exec_oncez?Deal with memory_usage calling functions more than once (argh).c                 0    || _         || _        d| _        d S r`   )code	fake_mainrun)r9   rz  r{  s      r:   r;   z_exec_once.__init__  s    	"r<   c                 l   | j         sd| _         t          j                            dd           }t	                      5  | j        t          j        d<   	 t          | j        | j        j                   ||t          j        d<   n# ||t          j        d<   w xY wd d d            d S # 1 swxY w Y   d S d S )NT__main__)	r|  r@   modulesr   rv  r{  execrz  __dict__)r9   old_mains     r:   rK  z_exec_once.__call__  s    x 		;DH{z488H!! ; ;*..J';DN$;<<<+2:J/  +2:J/::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;		; 		;s)   B'B2B'BB''B+.B+N)rt   ru   rv   rw   r;   rK  rX   r<   r:   rx  rx    s8        II  

; 
; 
; 
; 
;r<   rx  c                  *    ddl m}   | d          }|S )zAGet the base amount of memory used by the current Python process.r   memory_usageT)	max_usage)memory_profilerr  )r  memory_bases     r:   _get_memory_baser     s,    ,,,,,,,...Kr<   c                 v    |                      d          r
t          }d}nt          | |          }|j        }||fS )zGet parser and language.z.pyPython)endswithr   r   language)r   r   parserr  s       r:   _get_parserr  (  sC    ~~e #!UL11?8r<   c                     t          t          j        t                    rt          j        }nt          |           }|                                 |S rH   )r?   r@   rA   r/   r6   )r   logging_tees     r:   _check_reset_logging_teer  3  sF     #*k** ,j!(++**,,,r<   c          	         |d         }d}t          |          \  }}t          |j                  rt          |j        d         t          j                  rd}|j                                        j        } |t           | ||d          |d                             \  }	}t	          j	        t	          j
        dt	          j                              g|	          g}
t	          j        |
g 
          }t	          j        |            |t           | ||d          |d                             \  }}t          |	|          }n- |t           | ||d          |d                             \  }}||fS )a<  Execute ast, capturing output if last line expression and get max mem usage.

    Parameters
    ----------
    compiler : codeop.Compile
        Compiler to compile AST of code block.
    code_ast : ast.Module
        AST parsed code to execute.
    gallery_conf : Dict[str, Any]
        Gallery configurations.
    script_vars : Dict[str, Any]
        Configuration and runtime variables.

    Returns
    -------
    is_last_expr : bool
        Whether the last expression in `code_ast` is an ast.Expr.
    mem_max : float
        Max memory used during execution.
    r   FrN   Tr  r{  ___)idctx)targetsrq   )bodytype_ignores)_get_call_memory_and_baser   r  r?   astExprpoprq   rx  AssignNameStoreModulefix_missing_locationsrV  )compilercode_astr   r   r   is_last_exprcall_memoryr   last_valmem_bodyr  last_val_astmem_lastmem_maxs                 r:   _exec_and_get_memoryr  >  s   * :&HL.|<<NK
8= 
jr):CHEE 
=$$&&,!kxx(F;;[=UVV
 
!
 JEsy{{ C C CDHUUU
 zt"===!,///!kx88+k:R 
 
!
 h)) [xx(F;;[=UVV
 

   r<   c                     | D ]S}	  t          ||                      }||dk    rd}n|}t          |t                    r n@# t          $ r d}d}Y Pw xY w||fS )zLGet repr of last expression, using first method in 'capture_repr' available.NNone)getattrr?   r   	Exception)capture_reprr  meth	last_repr	repr_meths        r:   _get_last_reprr  r  s      	*T**,,I I$7$7 		 	
 )S)) 	  	 	 	IIII	 is   %AAAc                    d}d}| rb|d         }d}	|d         r5t          j        |d         t          t          |                              }	|dk    r|	st	          ||          \  }}|j                                                                        }
|dv r	|r|
 d| }
|
r=|
                                s)t          
                    t          |
d                    }
nd	}
t          j        d
          }|                    d	|
          }
|dk    r)t          
                    t          |d                    }nd	}d| d|
 d| d}|S )a  Obtain standard output and html output in reST.

    Parameters
    ----------
    is_last_expr : bool
        Whether the last expression in executed code is an ast.Expr.
    example_globals: Dict[str, Any]
        Global variables for examples.
    logging_tee : _LoggingTee
        Logging tee.
    images_rst : str
        rst code to embed the images in the document.
    gallery_conf : Dict[str, Any]
        Gallery configurations.
    file_conf : Dict[str, Any]
        File-specific settings given in source file comments as:
        ``# sphinx_gallery_<name> = <value>``.

    Returns
    -------
    code_output : str
        reST of output of executed code block, including images and captured output.
    Nr  Fignore_repr_typesrX   )__repr____str__r{   r~   r1   z%\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])_repr_html_r   )r   r   r   typer  rE   getvalue
expandtabsisspaceCODE_OUTPUTr   r   compiler   HTML_HEADER)r  example_globalsr   r  
images_rstr  r  r  r  ignore_reprcaptured_stdansi_escapecaptured_htmlcode_outputs                 r:   _get_code_outputr    s|   4 II Ee$+, 	W)L1D$Es4PS99~~VVK2k#1,#D#D Iy%..00;;==L+++	+&55)55 L0022 "))&w*G*GHH *EFFK??2|44L M!!#**6)W+E+EFFJzJJ|JJ}JJJKr<   c                 F    t          j        |            |t          _        dS )zReset cwd and sys.path.N)r   chdirr@   r   )cwdsys_paths     r:   _reset_cwd_syspathr    s    HSMMMCHHHr<   c                    ||d         j         }|d         r|j        dk    rdS t          j                    }|d         }t	          |          }t          |t                    sJ t          j        t          j        	                    |                     t          j        t          j                  }	t          j                            t          j                               t          j        d|j        t          j                  }
|
du }t%          j        |j                  }|                    d          |d	<   |                    d
|                    d|d                             }||d<   	 t+          d|j        dz
  z  |j        z   |dt.          j        | j        z  d          }t5          | |||          \  }}|d                             |           |                                 |rd}t9          |||          }nd}t;          ||	           t=          ||||||          }n`# t>          $ rS |                                 tA          t          j!                    |||          }d| d}|rt9          |||           Y nw xY wt;          ||	           |                                 n)# t;          ||	           |                                 w xY w|S )a  Execute the code block of the example file.

    Parameters
    ----------
    compiler : codeop.Compile
        Compiler to compile AST of code block.
    block : sphinx_gallery.py_source_parser.Block
        The code block to be executed.
    example_globals: Dict[str, Any]
        Global variables for examples.
    script_vars : Dict[str, Any]
        Configuration and runtime variables.
    gallery_conf : Dict[str, Any]
        Gallery configurations.
    file_conf : Dict[str, Any]
        File-specific settings given in source file comments as:
        ``# sphinx_gallery_<name> = <value>``.

    Returns
    -------
    code_output : str
        Output of executing code in reST.
    Nr{  rQ  rq  r1   r   z2^[\ \t]*#\s*sphinx_gallery_defer_figures[\ \t]*\n?multi_image_blockmulti_imagecapture_repr_blockr  r   r{   r   r  )flagsdont_inherit)r  r   r   memory_deltaFz



)"r  r  r   getcwdr  r?   r/   r  r   r   r  deepcopyr@   r3  r   r   contentr   r   extract_file_configr   r  r   r  PyCF_ONLY_ASTr  r  rJ   r"   r  r  r  ri  r[  )r  blockr  r   r   r   r  r   r  r  defer_figs_matchneed_save_figures
block_confr  r  r  r  r  r  rh  s                       r:   rJ  rJ    s   4 %k2;'( EJ&,@,@r
)++C:&H*844Kk;///// HRW__X&&'''}SX&&HHOOBIKK    y=
 
 )D0!5emDDJ ",0C!D!DK >>nl>&BCC L  )K/" EL1$%5#hn4
 
 
 !5%#	!
 !
 !
g 	N#**7333!!! 	 %%e[,GGJJJ 	3)))&
 
  	; 	; 	;!!!%LNNHk<
 

 0:///  	;\:::	;, 	3)))!!!! 	3)))!!!!s,   5BH0 %J5 0AJ
J5 JJ5 5&Kc                 P    |d         }t          j        ||           o|d         }|S )a3  Validate if script has to be run according to gallery configuration.

    Parameters
    ----------
    src_file : str
        path to python script

    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery

    Returns
    -------
    bool
        True if script has to be executed
    filename_patternplot_gallery)r   r   )r   r   r  executes       r:   executable_scriptr  B  s1      $$67i((33T^8TGNr<   c                      t          d          )Nz>Cannot use input() builtin function in Sphinx-Gallery examples)r
   )prompts    r:   rL  rL  W  s    
H  r<   c                    t          |          \  }}t          j                            t          j                            dd                    }|j        }|                    dt          d           ||d<   t          j	        dd         }|d         re|d         t          j	        d<   t          |d	          \  }	 |	||          t          j	        d
d<   t          j                      |d           \  }
}nd}
t                      }t          j                    }|
g|d<   ||d<   t!                      }t#          |                    dd                    5 }| D ]=}|                                 |                    t+          ||||||                     >	 ddd           n# 1 swxY w Y   t                      |z
  }|t          _	        t-          |d                   |d<   |d         rp|dxx         |
z  cc<   t/          |d         dz   d          5 }|                    t3          |d         d                     ddd           n# 1 swxY w Y   d|d<   ||fS )aE  Execute and capture output from python script already in block structure.

    Parameters
    ----------
    script_blocks : list
        (label, content, line_number)
        List where each element is a tuple with the label ('text' or 'code'),
        the corresponding content string of block and the leading line number
    script_vars : dict
        Configuration and run time variables
    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery
    file_conf : dict
        File-specific settings given in source file comments as:
        ``# sphinx_gallery_<name> = <value>``

    Returns
    -------
    output_blocks : list
        List of strings where each element is the restructured text
        representation of the output of each block
    time_elapsed : float
        Time elapsed during execution
    r~  Nr1   )rw   inputr  rQ  r   r   
reset_argvr   c                      d S rH   rX   rX   r<   r:   <lambda>z execute_script.<locals>.<lambda>  s    d r<           r  r{  r  r   r   r*  r   Tr%  )r  	importlibutilmodule_from_specspec_from_loaderr  updaterL  r@   argvr.  gccollectr   codeopCompiler/  r/   r   r6   r3  rJ  rV  r   rP   r)   )script_blocksr   r   r   r  r   r{  r  	argv_origr  memory_startt_startr  output_blocksr  r  time_elapsedr   s                     r:   rQ  rQ  ]  s   : /|<<NK//''
D99 I  (O  "	
 	
   &5K!"I#$ 
 "*-&|\BB!z,<<

%+ll33aaffG~H#/.K(KFFM	[__Z44	5	5 " 	 	E22444  "#  	 	 	 		               66G#LCH"%k.&A"B"BK#$ &N###|3### +m,v5s;; 	LwMM*[%?cJJJKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L!%I,&&s%   AF''F+.F++IIIc                    | s|                     dd          }|t          |t                    st          |t                    st	          d          |d         }t
          j                            t                      d          }t          t          |          |          D ]8\  }}t
          j                            |          st          ||           5dS dS dS )z1Make dummy images when not executing the example.dummy_imagesNzJsphinx_gallery_dummy_images setting is not an integer, got {dummy_image!r}r   r   )r   r?   boolr   r
   r   r   r   r   zipranger   r   )
executabler   r   dummy_imager   	stock_imgr   r   s           r:   _make_dummy_imagesr    s     .mmND99"+t,, J{C4P4P $*  
 #..C"D_%6%6GGIu[113FGG . .4w~~d++ .Y---. ."". .r<   c                     fd|D             }| d         rfd|D             }|d         j                                         r|dd         }|dd         }||fS )z=Remove ignore blocks, config comments and final empty blocks.c                 j    g | ]/\  }}}t          j        |                    |          |          0S rX   )r   Blockremove_ignore_blocksr   labelr  line_numberr  s       r:   r   z(_clean_script_blocks.<locals>.<listcomp>  sL       'E7K 	uf&A&A'&J&JKXX  r<   remove_config_commentsc                 j    g | ]/\  }}}t          j        |                    |          |          0S rX   )r   r  r  r	  s       r:   r   z(_clean_script_blocks.<locals>.<listcomp>  sS     
 
 
 ,w "v44W=={ 
 
 
r<   rN   N)r  r  )r   r  r  r  s    `  r:   _clean_script_blocksr    s       +8  M
 ,- 

 
 
 
 0=	
 
 
 R ((** +%crc*%crc*-''r<   c                    	
  d         r	|d         }nd}t           d                   }t          ||||          }|rt          ||d            d         
 fd		
 fd|                                D             }|d	|v r|d	= ~|S )
zBGet example backreferences for `script_blocks` and write _codeobj.inspect_global_variablesr  Ndefault_rolez.codeobjexclude_implicit_doc_regexc                      dj         di | }d         D ]}t          j        ||          r|c S  dj         di | S )N{module}.{name}prefer_full_modulez{module_short}.{name}rX   )r   r   r   )cobj	full_namepatternr   s      r:   _normalize_namez,_get_backreferences.<locals>._normalize_name  sp    ,%,44t44	#$89 	! 	!Gy),, !    !-&-55555r<   c           
          h | ]]}|D ]X}|d                               d                   #|d         s"r                      dj        di |          M |          Y^S )module
doc_moduleis_explicitr  rX   )r   r   r   )r   cobjsr  r  exclude_regexr   s      r:   	<setcomp>z&_get_backreferences.<locals>.<setcomp>  s     
 
 

 
 >$$\,%?@@	
 
 "
 "(()A):)A)I)ID)I)IJJ

 
 
 
r<   r  )r   r   r(   values)r   r   r  noder  global_variables	ref_regexexample_code_objr-  r  r  s   `        @@r:   _get_backreferencesr&    s    ./  &'89^ <==I%mY@PRVWW ?K!1:>>> !=>M6 6 6 6 6
 
 
 
 
 
%,,..
 
 
H #1A(A(AU#Or<   c                    t           j                            t           j                            ||                     }t	                      }t          |          | z  }t          ||dd           t          | |          \  }}|                    |d          \  }	}
}t          | |
d         j
                  \  }}t          ||          }t          |d          rFd}t                              d|            |r|d	         rd
}nt          |          |d<   |r||d|fS t           j                            |d          }t          j        |d           t           j                            |           d         }d|z   dz   }t           j                            ||          }|t%          |          |t          |          d}|r|d         dv rt'          || d           t)          |
|||	          \  }}t                              d||           t+          ||	|           t-          |||
|          \  }
}t/          |
||	||          }t1          |          \  }}||d         z   }|sdx}}t3          ||||||           t5          ||||	|           |g}|j        |d         v r`t9          |
||          }|                    d          }t=          ||           t          |d           ||                    d          gz  }t?          ||                    d          |           tA          |||
||          |d<   dD ]}||v r||         ||<   ~|r|d         dv rt'          || d            ||||f|fS )!a  Generate the rst file for a given example.

    Parameters
    ----------
    fname : str
        Filename of python script.
    target_dir : str
        Absolute path to directory in documentation where examples are saved.
    src_dir : str
        Absolute path to directory where source examples are stored.
    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery.

    Returns
    -------
    intro: str
        The introduction of the example.
    title : str
        The example title.
    cost : tuple
        A tuple containing the ``(time_elapsed, memory_used)`` required to run the
        script.
    out_vars : dict
        Variables used to run the script, possibly with entries:

        "stale"
            True if the example was stale.
        "backrefs"
            The backreferences.
        "passing"
            True if the example passed.
        "formatted_exception"
            Formatted string of the exception.
    r  r*  )r  r   T)return_noder   r   zmd5sum is current: run_stale_examplesFr&  )r   r   r  r   r   z_{0:03}.png)rQ  r   r   r  reset_modules_order)beforebothr+  z%s ran in : %.2g secondsr  r  r  notebook_extensionsz
.ipynb.new.ipynb.zipr-  )r%  r   )afterr,  r1  )!r   r   r  r   r4  r   r'   r  split_code_and_text_blocksr   r  r  r   r3   debugr   r   r   r   r!   rQ  r  r  
rst_blocksr  save_rst_exampler   suffixr   r5  r   r-   r&  )r   r   r   r   r   rB  r  r  r  r   r  r"  r   r   r  	do_returnr:  r   image_fnamer   r   r  r  example_rstr   r  memory_usedfiles_to_zip
example_nb	ipy_fnamer  s                                  r:   r0  r0    s5   F wWe < <==HvvHz""U*K;vC@@@@"5,77FH%+%F%Fd &G & &"I}d +5-2B2JKKLE5"8\::J3/// 	2	8;88999 	501 5!		$'$4$4! 	2%11Z22IK	D))))g&&u--a0O/-?K',,y+>> %01DEE;''	 K  5l#89=OOOlE8444"0{L)# #M< LL+X|DDD z9k:::#7	$ $ M=   K /|<<NA{N ;;K )%(({    &+y,WWW=L\*?@@@%m\:NN
++L99	j),,,YS))))00::;; lK33F;;ZHHH / HZ 2 - -+',HSM 4l#89=NNNlE7333%,4h>>r<   a  
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "{0}"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_{1}>`
        to download the full example code.{2}

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_{1}:

z/.. GENERATED FROM PYTHON SOURCE LINES {0}-{1}

r-  c          	      :   t          |           dk    }d}t          t          | |                    D ]\  }\  }}	|dk    rC|t                              |j        |j        |j                            d          z             z  }|j        dk    r`|	                    d|d                   r|j        nd}
t          |j        ||
          dz   }|r||z  }||	z  }||	z  }d	|	v r|d
z  }||z  }|j                            d          sdnd}||j        |z   z  }|S )at  Generate the rst string containing the script prose, code and output.

    Parameters
    ----------
    script_blocks : list
        (label, content, line_number)
        List where each element is a tuple with the label ('text' or 'code'),
        the corresponding content string of block and the leading line number
    output_blocks : list
        List of strings where each element is the restructured text
        representation of the output of each block
    file_conf : dict
        File-specific settings given in source file comments as:
        ``# sphinx_gallery_<name> = <value>``
    language : str
        The language to be used for syntax highlighting in code blocks. Must be a name
        or alias recognized by Pygments.
    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery

    Returns
    -------
    out : str
        rst notebook
    r   r1   r   r{   rz  line_numbersN)r   r   zsphx-glr-script-outz

|

r   )r   r2  r  RST_BLOCK_HEADERr   r   r  r   r  r   r   r  )r  r  r   r   r  is_example_notebook_liker9  biscript_blockr  r   code_rstblock_separators                r:   r4  r4    s}   <  #=11A5K+4S5V5V+W+W B B''\; 66+22##l&:&@&@&F&FF  K && ==n1MNN##  L0xOOORVV  ( (x'{*{*(K77;.Kx' +2;;DAAKt  <//AAKKr<   c                h   t          |          }t          |                    |d                             }|                    t          j        d          }|d         }t          |          dk    }	|d         }
|
du}d}|	s|r|dz  }|	r|r|d	z  }n|	r|d
z  }n|r|dz  }t                              |||          | z   } ||d         k    r1t          |d          \  }}| t                              ||          z  } |d         r
| d|ddz  } | t                              |          z  } |j        |d         v }|	r(|r&t          |||          }t          |d          }| |z  } |r'|r%t          ||          }t          |d          }| |z  } |r7|                    d          j        }| t$                              |          z  } | t&                              |j        |          z  } | t(                              |                    d          j                  z  } |d         d         r1t          |          j        }| t,                              |          z  } |d         r
| t.          z  } |                    d          }t1          |dfi t2          5 }|                    |            ddd           n# 1 swxY w Y   t	          j        |          j        }dt6          j        t6          j        z  t6          j        z  z  }t	          j         |||z             tC          |d           dS )a=  Saves the rst notebook to example_file including header & footer.

    Parameters
    ----------
    example_rst : str
        rst containing the executed file content
    example_file : str
        Filename with full path of python example file in documentation folder
    language : str
        Name of the programming language the example is in
    time_elapsed : float
        Time elapsed in seconds while executing file
    memory_used : float
        Additional memory used during the run.
    gallery_conf : dict
        Sphinx-Gallery configuration dictionary
    r   r   binderr   r  Nr1   z, or to run this example in your browser via zJupyterLite or BinderBinderJupyterLitemin_reported_time<   show_memoryz**Estimated memory usage:** z .0fz MB

r.  z  r/  r0  recommenderenableshow_signaturez.rst.newr   iw  r*  r   )"r   r   relative_tor   r   r   r   EXAMPLE_HEADERr   divmodTIMING_CONTENTDOWNLOAD_LINKS_HEADERr6  r   r   r   r5  r
  NOTEBOOK_DOWNLOADCODE_DOWNLOADZIP_DOWNLOADstemRECOMMENDATIONS_INCLUDESPHX_GLR_SIGr   r#   rP   statst_modeS_IWRITES_IWGRPS_IWOTHchmodr'   )r9  example_filer  r:  r   r  example_fname	ref_fnamebinder_confis_binder_enabledjupyterlite_confis_jupyterlite_enabledinteractive_example_texttime_mtime_sr   binder_badge_rstjupyterlite_rstipynb_download_filerecommend_fnamewrite_file_newfr   ro_masks                           r:   r5  r5     s   4 %%L00i1HIIJJM%%bfc22Ix(KK((1,#M2-T9! S2 S $RR  23 2 $;;  	 2 H,  	 2 M1  	mY8PQQ
	 
 l#6777b11~,,VV<<<M" POkOOOOO(//	:::K '<8M+NNM  (] (),\RR!"2D99'' '- '-lLII $77& E*66x@@E(//0CDDD=''(98DDDK<&&|'?'?'G'G'LMMMKM"8, G}--2.55oFFF$% $|#!--j99N	nc	+	+U	+	+ q	               7>""*Dt}t|3dlBCGH^TG^,,, c******s   J<<K K c           
         d}d}|d|z   v s
J |            | |         }|dk    r
|d         g}n||v r|g}t          |t          t          f          s|g}t          |          }t          |          D ]\  }}|dk    r| d}n0||v r| dt	          |           }n| d| d	t	          |           }t          |t
                    r||v rd
| }d|v rc|                    dd          \  }	}
	 t          t          j	        |	          |
          }n# t          $ r t          d| d|
 d|	           w xY w|dk    rg|t          v rt          |         }n	 t          j	        |          }t          |d          } |            }nQ# t          $ r t          d|           w xY w|dk    r+|t          vrt          d| d|           t          |         }|||<   |dk    r$t          j        |          r ||          }|||<   t          j        |          rt          d| d|           t!          |          st          | d          t          |          S )a  Get callables for the given conf key, returning tuple of callable(s).

    If value is a string, import, with the following exceptions:

    * `within_subsection_order` - add full path if value is a built-in aliases,
      instantiate if value is a class
    * `image_scrapers` - get value from `_scraper_dict` or import module and
      get `_get_sg_image_scraper` attribute
    * `reset_modules` - get value from `_reset_dict`
    )ExampleTitleSortKeyFileNameSortKeyFileSizeSortKeyNumberOfCodeLinesSortKey)r  minigallery_sort_ordersubsection_orderr  )image_scrapersreset_modulesr  r  notebook_modification_functionz"['notebook_modification_function']=[z]=zsphinx_gallery.sorting.r   r   zUnknown string option z when importing z from ry  _get_sg_image_scraperzUnknown string option for rz  z: r  z,Got class rather than callable instance for z must be callable)r?   tupler/  r2  reprr   rsplitr  r  import_moduler  r	   r    r   inspectisclasscallable)r   r  r   builtin_aliases
singletonswhichwiwhatra   modattrs              r:   r.  r.  e  sI   OJ DzQQQQSVQQQE
m789	
		eeT]++ KKEe$$ /> />D-AAAHHJ,,T

,,HH2222d4jj22HdC   	 &&777d{{ KKQ//	T"9#:3#?#?FFDD    %< < <*.< <69< <  
 (((=(((.DDS(6t<<&t-DEE#tvv$ S S S)*Qx*Q*QRRRS''{**%&U8&U&Ut&U&UVVV"4(E"I+++0E0E+4==DE"I?4   	QxQQ4QQ   ~~ 	><<<===	><<s   1"D#D7.FF$c                     d |             fS )Nr  rX   )rf  s    r:   _sg_call_memory_noopr    s    ;r<   F)r  c                :   | d         }t           }d}|rt| d         rlt          |          r|}nZ| d         r5|r2t                              d| d         d| d         d           d| d<   nt	                      }||\  }}n|rd| d<   t          |          sJ ||fS )	NrL  r  r  r  zgallery_conf['show_memory']=z* disabled due to gallery_conf['parallel']=r   F)r  r  r3   rZ  _get_memprof_call_memory)r   r  rL  r  r  outs         r:   r  r    s    }-K 'KK 4|N3 4K   	4%KK*% 	4 44|M2 4 4#J/4 4 4   /4]+*,,C+.([[ 4.3]+K     ##r<   c                 n    ddl m}  || ddd          \  }}	 |d         }n# t          $ r Y nw xY w||fS )Nr   r  T)r  retvalmultiprocess)r  r  	TypeError)rf  r  r+  r  s       r:   _sg_call_memory_memprofr    si    ,,,,,,|DDDQQQHC!f   8Os   # 
00c                      	 ddl m}  t          t                      fS # t          $ r t
                              d           Y d S w xY w)Nr   r  zDPlease install 'memory_profiler' to enable peak memory measurements.)r  r  r  r  ImportErrorr3   rZ  r  s    r:   r  r    sl    ;000000 '(8(:(:::    R	
 	
 	
 tt	s    $AA)ry   N)r   )T)NNrH   )rw   r  r  
contextlibr  r  r  r  r   r   r[  r@   rS  rk  	functoolsr   ior   pathlibr   shutilr   textwrapr   r   sphinx.utilsphinxsphinx.errorsr	   r
   sphinx.util.consoler   r   r   r1   r   r   backreferencesr   r   r   r   r   r   block_parserr   interactive_exampler   r   r   notebookr   r   scrapersr   r   r   r    r!   r"   utilsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r  logging	getLoggerr3   r/   HLIST_HEADERHLIST_IMAGE_TEMPLATESINGLE_IMAGEr  rS  rZ  r  rT  rV  rU  rW  rY  r   r   r   r   r   r   r   r  r  rF  ri  rr  contextmanagerrv  rx  r  r  r  r  r  r  r  rJ  r  rL  rQ  r  r  r&  r0  rQ  r@  r4  r5  r.  r  r  r  r  rX   r<   r:   <module>r     st    


       				      				 				  



                                              5 5 5 5 5 5 5 5 / / / / / / / / / / / / / / / / / /                & % % % % %         
 6 5 5 5 5 5 5 5                                         
		&	&'7	8	8W W W W W W W W|
 
	   
+ + + +&- - -
! ! !H  B   I2 I2 I2X   8  <I I I& h h h hVF F FT    	0 	0 	0; ; ; ; ; ; ; ;*      1! 1! 1!h     &9 9 9x  x x xv  *   _' _' _'D. . .$( ( (2$ $ $NN? N? N?b(  HPA A A A AV b+ b+ b+ b+ b+JS S S Sn   7< $ $ $ $ $:   	; 	; 	; 	; 	;r<   