o
    i                     @   s   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m	Z	m
Z
 d dlmZmZ ddlmZmZ ddlmZmZ eeZG dd	 d	ed
Ze ZG dd dZe Zejd e g Zdd ZdS )    N)SourceFileLoader)CodeTypeFunctionType
ModuleType)OvldMCovld   )CodeFileFunctionDefinition)EventSourceglob_filterc                   @   s   e Zd Zdd Zdd Zdd Zddd	Zd
d Zdd Ze	dfddZ
edefddZedefddZedefddZedefddZdS )Registryc                 C   s0   i | _ i | _i | _tdd| _t | _d | _d S )NT)save_history)filename_to_moduleprecachecacher   precache_activityactivity_logself r   T/home/ubuntu/.local/lib/python3.10/site-packages/spaces/_vendor/jurigged/register.py__init__   s   
zRegistry.__init__c                 C   s
   || _ d S Nr   )r   logr   r   r   
set_logger      
zRegistry.set_loggerc                 O   s"   | j d ur| j |i | d S d S r   r   )r   argskwargsr   r   r   r      s   
zRegistry.logNc                 C   s  |d u r|d us
J t j| j}|| jvr|| jvr|d u rM|| jv r)| j| }n$t j D ]\}}t|dd }|rE|| j|< ||krE nq.td| t	j
|rt|ddd}|| t	j
|f| j|< W d    n1 ssw   Y  | j|| ||fS )N__file__z'Cannot find module that corresponds to rutf8)encoding)sysmodulesr!   r   r   r   itemsgetattr	Exceptionospathexistsopenreadgetmtimer   emit)r   module_namefilenamemodulefnamefr   r   r   prepare#   s4   


zRegistry.preparec                 C   s   || j v r
| j | S || jv rC| j| \}}}|tjvrd S t|||d}|tj|  |j| j |j| jj	 || j |< |S d S )N)sourcer1   )
r   r   r%   r&   r	   	associater   registerr   r0   )r   r2   r1   cached_sourcemtimecfr   r   r   getC   s   




zRegistry.getc                 C   s   |  |}|d u rdS |j D ],}t|tr<|jd ur<|jj|kr(|jj|ks6|jj	j|kr<|jj	j|kr<||f  S q|d fS )NNN)
r=   rootwalk
isinstancer
   nodestashedlinenor2   extent)r   r2   rD   r<   entryr   r   r   get_atW   s   

zRegistry.get_atz./*.pyc                    sP    fdd}t tj D ]\}}t|dd }t|dd }||| qt|S )Nc              	      sP   |d ur"| d ur$ |r&z	 | | W d S  ttfy!   Y d S w d S d S d S r   )r6   UnicodeDecodeErrorOSError)r1   r2   filterr   r   r   prepo   s   z$Registry.auto_register.<locals>.prepr!   __name__)listr%   r&   r'   r(   add_sniffer)r   rK   rL   namer3   r2   r1   r   rJ   r   auto_registern   s   zRegistry.auto_registerr3   c                 C   s&   |  |j|j | |j}||jfS r   )r6   rM   r!   r=   r?   )r   r3   r<   r   r   r   find   s   
zRegistry.findfnc                 C   s&   |j }| |j|j | |j|jS r   )__code__r6   
__module__co_filenamerG   co_firstlineno)r   rS   cor   r   r   rR      s   rX   c                 C   s   | j |jd | |j|jS )N)r2   )r6   rV   rG   rW   )r   rX   r   r   r   rR      s   clsc                 C   s^   | j |jd\}}| |}|j d|j }|j D ]}| |kr*||f  S q|d fS )N)r1   .)r6   rU   r=   __qualname__r?   r@   dotpath)r   rY   _r2   r<   keyrF   r   r   r   rR      s   
r>   )rM   rU   r[   r   r   r   r6   r=   rG   r   rQ   r   r   rR   r   r   typer   r   r   r   r      s     
 r   )	metaclassc                   @   s"   e Zd ZdZdd ZdddZdS )ImportSnifferaA  A spec finder that simply sniffs for attempted imports.

    Basically we install this at the front of sys.meta_path so that
    importlib.util.find_spec calls it, then we call find_spec
    ourselves to locate the file that's going to be read so that we
    know we have to cache its contents and watch for changes.
    c                 C   s
   d| _ d S )NF)workingr   r   r   r   r      r   zImportSniffer.__init__Nc                 C   s   t sd S | jsSd| _tj||}|d urPt|jtrP|jd urP|j	d urPt D ](}z	||j|j	 W q' t
yO } ztjd|j |d W Y d }~q'd }~ww d| _d S )NTz jurigged: Error processing spec )exc_infoF)_sniffer_callbacksrb   	importlibutil	find_specrA   loaderr   rP   originr)   r   error)r   fullnamer+   targetmspecreportexcr   r   r   rg      s,   



zImportSniffer.find_specr   )rM   rU   r[   __doc__r   rg   r   r   r   r   ra      s    ra   c                    s   t    fdd _ S )Nc                      s
   t  S r   )rd   remover   rn   r   r   <lambda>   s   
 zadd_sniffer.<locals>.<lambda>)rd   append	uninstallrr   r   rr   r   rO      s   
rO   )importlib.utilre   loggingr*   r%   _frozen_importlib_externalr   typesr   r   r   r   r   	codetoolsr	   r
   utilsr   r   	getLoggerrM   r   r   registryra   _main_sniffer	meta_pathinsertrd   rO   r   r   r   r   <module>   s$    
 *