
    i                        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dS )%    )annotationsN)	ExitStack)
ModuleType)Any)Optional)
exceptions)Template   )compat)CommandErrortemplate_filestrdestoutput_encodingkwr   returnNonec                   t          |           }	  |j        di |                    |          }t          |d          5 }|                    |           d d d            d S # 1 swxY w Y   d S #  t          j        dd          5 }|                    t          j                                                                        |                     |j	        }d d d            n# 1 swxY w Y   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   )	r   r   r   r   templateoutputfntffnames	            Z/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/alembic/util/pyfiles.pytemplate_to_filer(      s    ///H((..2..55oFF $ 	GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
(uEEE 	II.00!!((  
 HE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 +-23
 
 	
sB    A2 A%%A),A)2D
AC)D)C-	-D0C-	1Dr&   c                   t           j                            |           sd| v r|                     d          }t	                      }t          j        |j                   t          j	        
                    |d                   }|dd         D ]}||z  }|                    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toks        r'   coerce_resource_to_filenamer:   -   s     7== 
C5LLS!! !{{*+++(..vay99!"": 	 	C)CC**&..s33
 
 L    r,   Optional[str]c                D   t           j                            |           }t          j                            |          r|S t          j                            |           \  }}t           j        j        D ]+}t          j                            ||z             r||z   c S ,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exts       r'   pyc_file_from_pathrH   F   s     0066I	w~~i    G$$T**MHc"4  7>>(S.)) 	"c>!!!	" tr;   dir_r   r   c                   t          j        dd|          }t          j                            | |          }t          j                            |          \  }}|dk    rdt          j                            |          rt          ||          }nKt          |          }|t          d|z            t          ||          }n|dv rt          ||          }nJ |S )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,   joinrB   rA   load_module_pyrH   ImportError)rI   r   	module_idr,   rK   rG   modulepyc_paths           r'   load_python_filerT   W   s     uc8,,I7<<h''DWh''FAs
e||7>>$ 	=#It44FF)$//H!"="DEEE'	8<<	 	 	 	400uMr;   rQ   c                    t           j                            | |          }|sJ t           j                            |          }|j                            |           |S )N)r>   r?   spec_from_file_locationmodule_from_specloaderexec_module)rQ   r,   specrR   s       r'   rO   rO   m   sR    >11)TBBDKK4^,,T22FKF###Mr;   )
r   r   r   r   r   r   r   r   r   r   )r&   r   r   r   )r,   r   r   r<   )rI   r   r   r   r   r   )rQ   r   r,   r   r   r   )
__future__r   r/   
contextlibr   r>   importlib.machineryimportlib.utilr+   rL   r   typesr   typingr   r   makor   mako.templater	    r   excr   r(   r:   rH   rT   rO   r   r;   r'   <module>re      s]   " " " " " "                          				 				                          " " " " " "               .   2   "   ,     r;   