o
    h                     @  s   d dl mZ d dlZd dlm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mZ d%ddZd&ddZd'ddZd(d d!Zd)d#d$ZdS )*    )annotationsN)	ExitStack)
ModuleType)Any)Optional)
exceptions)Template   )compat)CommandErrortemplate_filestrdestoutput_encodingkwr   returnNonec           	      K  s   t | d}z|jdi ||}W n/   tjddd}|t  | |j}W d    n1 s7w   Y  t	d| t
|d}|| W d    d S 1 sXw   Y  d S )N)filenamez.txtF)suffixdeletezDTemplate rendering failed; see %s for a template-oriented traceback.wb )r   render_unicodeencodetempfileNamedTemporaryFilewriter   text_error_templatenamer   open)	r   r   r   r   templateoutputntffnamefr   r   h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/alembic/util/pyfiles.pytemplate_to_file   s(   
"r&   r#   c                 C  sp   t j| s6d| v r6| d}t }t|j tj	
|d }|dd D ]}|| }q&|tj	|} | S )zInterpret a filename as either a filesystem location or as a package
    resource.

    Names that are non absolute paths and contain a colon
    are interpreted as resources and coerced to a file location.

    :r   r	   N)ospathisabssplitr   atexitregistercloser
   importlib_resourcesfilesenter_contextas_file)r#   tokensfile_managerreftokr   r   r%   coerce_resource_to_filename-   s   


r7   r)   Optional[str]c                 C  sZ   t j| }tj|r|S tj| \}}t jjD ]}tj|| r*||   S qdS )z,Given a python source path, locate the .pyc.N)		importlibutilcache_from_sourcer(   r)   existssplitext	machineryBYTECODE_SUFFIXES)r)   	candidatefilepathextr   r   r%   pyc_file_from_pathF   s   rC   dir_r   r   c                 C  s   t dd|}tj| |}tj|\}}|dkr<tj|r't||}|S t|}|du r5t	d| t||}|S |dv rGt||}|S J )z3Load a file from the given path as a Python module.z\W_z.pyNzCan't find Python file %s)z.pycz.pyo)
resubr(   r)   joinr=   r<   load_module_pyrC   ImportError)rD   r   	module_idr)   rE   rB   modulepyc_pathr   r   r%   load_python_fileW   s    


rN   rK   c                 C  s2   t j| |}|sJ t j|}|j| |S )N)r9   r:   spec_from_file_locationmodule_from_specloaderexec_module)rK   r)   specrL   r   r   r%   rI   m   s
   rI   )
r   r   r   r   r   r   r   r   r   r   )r#   r   r   r   )r)   r   r   r8   )rD   r   r   r   r   r   )rK   r   r)   r   r   r   )
__future__r   r,   
contextlibr   r9   importlib.machineryimportlib.utilr(   rF   r   typesr   typingr   r   makor   mako.templater    r
   excr   r&   r7   rC   rN   rI   r   r   r   r%   <module>   s*    



