o
    8 hz                     @  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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lmZ ddd.ddZd/ddZd0d"d#Zd1d'd(Zd2d*d+Zd3d,d-ZdS )4    )annotationsN)	ExitStack)
ModuleType)Any)Optional)Union)
exceptions)Template   )compat)CommandErrorF)append_with_newlinestemplate_fileUnion[str, os.PathLike[str]]destoutput_encodingstrr   boolkwr   returnNonec          
      K  s   t t| d}z|jd	i ||}W n/   tjddd}|t  | |j	}W d    n1 s9w   Y  t
d| t||rJdnd}	|rX|	d| |	| W d    d S 1 shw   Y  d S )
N)filenamez.txtF)suffixdeletezDTemplate rendering failed; see %s for a template-oriented traceback.abwbz

 )r	   _preserving_path_as_strZrender_unicodeencodetempfileNamedTemporaryFilewriter   Ztext_error_templatenamer   open)
r   r   r   r   r   templateoutputZntffnamefr   r   \/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/alembic/util/pyfiles.pytemplate_to_file   s,   "r)   fname_or_resourcepathlib.Pathc                 C  sv   t j| s6d| v r6| d}t }t|j tj	
|d }|dd D ]}|| }q&|tj	|} t| 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pathlibPath)r*   tokensZfile_managerreftokr   r   r(   coerce_resource_to_filename6   s   	



r=   r.   Optional[pathlib.Path]c                 C  s`   t | }t tj| }| r|S |j}tjj	D ]}|
| r-|
|  S qdS )z,Given a python source path, locate the .pyc.N)r8   r9   	importlibutilcache_from_sourceas_posixexistsr   	machineryBYTECODE_SUFFIXESwith_suffix)r.   Zpathpath	candidateextr   r   r(   pyc_file_from_pathP   s   
rI   dir_r   r   c                 C  s   t | } t |}|j}tdd|}| | }|j}|dkr?| r*t||}|S t|}|du r8t	d| t||}|S |dv rJt||}|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)
r8   r9   r"   resubr   rC   load_module_pyrI   ImportError)rJ   r   Zfilename_as_path	module_idr.   rH   moduleZpyc_pathr   r   r(   load_python_filef   s&   




rR   rP   c                 C  s2   t j| |}|sJ t j|}|j| |S )N)r?   r@   spec_from_file_locationmodule_from_specloaderexec_module)rP   r.   specrQ   r   r   r(   rN      s
   rN   c                 C  s0   t | tr| S t | tjrt| S tt| S )zreceive str/pathlike and return a string.

    Does not convert an incoming string path to a Path first, to help with
    unit tests that are doing string path round trips without OS-specific
    processing if not necessary.

    )
isinstancer   r8   PurePathr9   )r.   r   r   r(   r      s
   
r   )r   r   r   r   r   r   r   r   r   r   r   r   )r*   r   r   r+   )r.   r   r   r>   )rJ   r   r   r   r   r   )rP   r   r.   r   r   r   )r.   r   r   r   ) 
__future__r   r1   
contextlibr   r?   Zimportlib.machineryimportlib.utilr-   r8   rL   r   typesr   typingr   r   r   Zmakor   Zmako.templater	    r   excr   r)   r=   rI   rR   rN   r   r   r   r   r(   <module>   s2    




