
    Mh$                         d Z ddlZddlmZ ddlZddlZddlmZ ddl	m
Z
 ddlZej        Zed             Zd Zd Zi ad	 Zd
 Zd ZddZi ad Zej        Zg ej        ddddddR fdZdS )a  
Provides a reload() function that acts recursively.

Python's normal :func:`python:reload` function only reloads the module that it's
passed. The :func:`reload` function in this module also reloads everything
imported from that module, which is useful when you're changing files deep
inside a package.

To use this as your default reload function, type this::

    import builtins
    from IPython.lib import deepreload
    builtins.reload = deepreload.reload

A reference to the original :func:`python:reload` is stored in this module as
:data:`original_reload`, so you can restore it later.

This code is almost entirely based on knee.py, which is a Python
re-implementation of hierarchical module import.
    N)contextmanager)
ModuleType)warnc              #   ~   K   t           j        }| t           _        	 d V  |t           _        d S # |t           _        w xY w)N)builtin_mod
__import__)
new_importsaved_imports     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/lib/deepreload.pyreplace_import_hookr   (   sF      )L'K.!-----s   . <c                 \   |}|rt          | t                    sdS |                     dd          }|Lt          |d          st	          d          t          |          dk    r|dk    rt	          d          dS |}njd| vrdS | d         }d	| v r|x| d<   }nP|                    d
          }|dcxk     r|k     rn nt	          d          |dk     rd| d<   dS |d|         x| d<   }t          |          }t          |dd          D ]<}	 |                    d
d|          }# t          $ r}	t	          d          |	d}	~	ww xY w|d|         }	 t          j
        |         }
nE# t          $ r8}	|dk     rt          d|z             d}
nt          d|z            |	Y d}	~	nd}	~	ww xY w|
|fS )a  
    parent, name = get_parent(globals, level)

    Return the package that an import is being performed in.  If globals comes
    from the module foo.bar.bat (not itself a package), this returns the
    sys.modules entry for foo.bar.  If globals is from a package's __init__.py,
    the package's entry in sys.modules is returned.

    If globals doesn't come from a package or a module in a package, or a
    corresponding entry is not found in sys.modules, None is returned.
    )N __package__Nrindexz__package__ set to non-stringr   z(Attempted relative import in non-package__name____path__.   z2attempted relative import beyond top-level packagez?Parent module '%.200s' not found while handling absolute importzAParent module '%.200s' not loaded, cannot perform relative import)
isinstancedictgethasattr
ValueErrorlenrfindranger   sysmodulesBaseExceptionr   SystemError)globalslevel
orig_levelpkgnamenamemodnamelastdotdotxeparents              r   
get_parentr-   1   sp    J 
7D11 xkk-..Gw)) 	><===w<<1qyy !KLLL8 W$$8*%  ,33GM"TT mmC((G""""U""""" !KLLL{{)-&x,3HWH,==GM"T
d))C5!R   / /	/++c1c**CC 	/ 	/ 	/ ' ( (-./	/ :D	GT" G G G>>  ! " " "FF 8:>? @ @EFG FFFF	G 4<s0   D%%
E/D??EE% %
F'/.F""F'c                 x   t          |          dk    r| d|fS |                    d          }|dk    rt          d          |dk     r|}d}n|d|         }||dz   d         }|dk    r|dz  }||z  }t          | ||          }|| |k    rt          |||          }||}|t	          d|z            |||fS )zf
    mod, name, buf = load_next(mod, altmod, name, buf)

    altmod is either None or same as mod
    r   Nr   Empty module namer   r   zNo module named %.200s)r   findr   import_submoduleImportError)modaltmodr&   bufr)   subnamenextresults           r   	load_nextr9   z   s     4yyA~~ D#~
))C..C
axx,---
Qwwtt*CEFF|
byys
7NCc7C00F~#--!&'7;;C~2T9:::4    c                 |   |t           v r!|t          j        v rt          j        |         }nt          d|           dt           |<   t          j                            |d          }	 |t          j        |          }nt          j        ||           }n#  |r|t          j        |<    xY wt          | |||           |S )z,m = import_submodule(mod, subname, fullname)	Reloadingr   N)		found_nowr   r   printr   	importlibreloadimport_moduleadd_submodule)r3   r6   fullnamemoldms        r   r1   r1      s     9S[!8!8K!k8$$$	({x..
	$T**+GS99	  -(,H%c1h000Hs   &,B B'c                 X    | dS |t           j        |         }t          | ||           dS )zmod.{subname} = submodN)r   r   setattr)r3   submodrC   r6   s       r   rB   rB      s4    
{~X&C&!!!
Fr:   c                 2   t          | d          sdS |D ]}t          |d          st          d          |dk    r3|r*	 | j        }t          | ||d          }|s dS J# t          $ r Y Vw xY wt          | |          st          | ||dz   |z              dS )	z,Handle 'from module import a, b, c' imports.r   Nr   z"Item in ``from list'' not a string*r   r   r   )r   	TypeError__all__ensure_fromlistAttributeErrorr1   )r3   fromlistr5   	recursiveitemallrets          r   rM   rM      s    3
##  : :tX&& 	B@AAA3;; k &c3Q77 11	 "    d## 	:S$c	D(8999: :s    A
A,+A,r   c                     t          ||          \  }}t          ||dk     rdn|| |          \  }} }|}| rt          ||| |          \  }} }| |t          d          |s|S t          |||d           |S )zReplacement for __import__()r   Nr/   )r-   r9   r   rM   )	r&   r"   localsrO   r#   r,   r5   headtails	            r   deep_import_hookrX      s    We,,KFC		vtSQQOD$D
 ;#D$c::dC  ; |,--- D(C+++Kr:   c                    | t           u r| S t          | t                    st          d          | j        }|t
          j        vrt          d|z            	 t          |         S #  | t          |<   Y nxY w	 t          j
        |           }n#  | t
          j        |<    xY w	 t                                           n# t                                           w xY w|S )zReplacement for reload().z reload() argument must be modulez*reload(): module %.200s not in sys.modules)typesr   r   rK   r   r   r   r2   modules_reloadingr?   r@   clear)rD   r&   newms      r   deep_reload_hookr^      s     	Ezza$$ <:;;;:D3;FMNNN$ &&$"#$"""D 	
 	!!!!!!!!Ks*   A% %A37B B< BB< <Cr   zos.pathbuiltins__main__numpyznumpy._globalsc                     |D ]}dt           |<   	 t          t                    5  t          |           cddd           i a S # 1 swxY w Y   	 i a dS # i a w xY w)aM  Recursively reload all modules used in the given module.  Optionally
    takes a list of modules to exclude from reloading.  The default exclude
    list contains modules listed in sys.builtin_module_names with additional
    sys, os.path, builtins and __main__, to prevent, e.g., resetting
    display, exception, and io hooks.
    r   N)r=   r   rX   r^   )moduleexcludeis      r   r@   r@     s    &   	! !122 	, 	,#F++	, 	, 	, 	, 	, 	, 	, 			, 	, 	, 	, 	, 	, 	, 	, 	, 			B	s-   A AA AA 
AA A)NNNr   )__doc__r_   r   
contextlibr   r?   r   rZ   r   warningsr   r   original_importr   r-   r9   r=   r1   rB   rM   rX   r[   r^   r@   original_reloadbuiltin_module_names r:   r   <module>rm      s   6     % % % % % %     



             (. . .G G GR$ $ $P 	  :
 
 
: : :*   ,    @ "
		! 	 		
 	 	 	      r:   