
    Pqh-                        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
ZddZddZddZddZy)    )annotationsN)	ExitStack)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	            U/srv/www/ollama/chat-ollama/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_filenamer5   +   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_pathrB   D   s     006I	ww~~i  GG$$T*MHc""44 77>>(S.)c>! r6   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 )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_pyrB   ImportError)dir_r   	module_idr'   rD   rA   modulepyc_paths           r"   load_python_filerN   U   s     uc8,I77<<h'DWWh'FAs
e|77>>$#It4F M *$/H!"="DEE'	8< M 
 	 	40Mr6   c                    t         j                  j                  | |      }|sJ t         j                  j                  |      }|j                  j                  |       |S )N)r8   r9   spec_from_file_locationmodule_from_specloaderexec_module)rK   r'   specrL   s       r"   rH   rH   i   sJ    >>11)TBDK4^^,,T2FKKF#Mr6   )r   strr   rU   r   rU   returnNone)r!   rU   rV   rU   )r'   rU   rV   zOptional[str])rJ   rU   r   rU   )rK   rU   r'   rU   )
__future__r   r*   
contextlibr   r8   importlib.machineryimportlib.utilr&   rE   r   typingr   makor   mako.templater    r	   excr
   r#   r5   rB   rN   rH   r   r6   r"   <module>ra      sh    "       	 	    "  !47	.2"(r6   