
    +h                        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ZddZddZddZddZy)    )annotationsN)	ExitStack)
ModuleType)Any)Optional)
exceptions)Template   )compat)CommandErrorc                   t        |       }	  |j                  di |j                  |      }t        |d      5 }|j	                  |       d d d        y # 1 sw Y   y xY w#  t        j                  dd      5 }|j	                  t        j                         j                         j                  |             |j                  }d d d        n# 1 sw Y   nxY wt        dz        xY w)N)filenamewbz.txtF)suffixdeletezDTemplate rendering failed; see %s for a template-oriented traceback. )r	   render_unicodeencodeopenwritetempfileNamedTemporaryFiler   text_error_templatenamer   )	template_filedestoutput_encodingkwtemplateoutputfntffnames	            G/var/www/html/venv/lib/python3.12/site-packages/alembic/util/pyfiles.pytemplate_to_filer%      s     /H(((.2.55oF $ 	GGFO	 	 	
((uE 	II..0!(
 HHE	 	 	 +-23
 	
s/   !A" AA"C+;AC	C+C	C+c                ~   t         j                  j                  |       sd| v r| j                  d      }t	               }t        j                  |j                         t        j                  j                  |d         }|dd D ]  }||z  }	 |j                  t        j                  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toks        r$   coerce_resource_to_filenamer7   -   s     77==C5LS! !{**+((..vay9!": 	C)C	**&&..s3
 L    c                X   t         j                  j                  |       }t        j                  j                  |      r|S t        j                  j                  |       \  }}t         j                  j                  D ]+  }t        j                  j                  ||z         s&||z   c S  y)z,Given a python source path, locate the .pyc.N)		importlibutilcache_from_sourcer(   r)   existssplitext	machineryBYTECODE_SUFFIXES)r)   	candidatefilepathexts       r$   pyc_file_from_pathrD   F   s     006I	ww~~i  GG$$T*MHc""44 77>>(S.)c>! r8   c                   t        j                  dd|      }t        j                  j	                  | |      }t        j                  j                  |      \  }}|dk(  rVt        j                  j                  |      rt        ||      }|S t        |      }|t        d|z        t        ||      }|S |dv rt        ||      }|S J )z3Load a file from the given path as a Python module.z\W_z.pyzCan't find Python file %s)z.pycz.pyo)
resubr(   r)   joinr>   r=   load_module_pyrD   ImportError)dir_r   	module_idr)   rF   rC   modulepyc_paths           r$   load_python_filerP   W   s     uc8,I77<<h'DWWh'FAs
e|77>>$#It4F M *$/H!"="DEE'	8<
 M	 
 	 	40 M 	ur8   c                    t         j                  j                  | |      }|sJ t         j                  j                  |      }|j                  j                  |       |S )N)r:   r;   spec_from_file_locationmodule_from_specloaderexec_module)rM   r)   specrN   s       r$   rJ   rJ   m   sJ    >>11)TBDK4^^,,T2FKKF#Mr8   )
r   strr   rW   r   rW   r   r   returnNone)r#   rW   rX   rW   )r)   rW   rX   zOptional[str])rL   rW   r   rW   rX   r   )rM   rW   r)   rW   rX   r   )
__future__r   r,   
contextlibr   r:   importlib.machineryimportlib.utilr(   rG   r   typesr   typingr   r   makor   mako.templater	    r   excr   r%   r7   rD   rP   rJ   r   r8   r$   <module>rd      sv    "       	 	      "  !47?B	.2",r8   