o
    Phz                     @  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_strrender_unicodeencodetempfileNamedTemporaryFilewriter   text_error_templatenamer   open)
r   r   r   r   r   templateoutputntffnamefr   r   Y/var/www/html/stock_analysis/be/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-   tokensfile_managerreftokr   r   r+   coerce_resource_to_filename6   s   	



rA   r1   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)r;   r<   	importlibutilcache_from_sourceas_posixexistsr   	machineryBYTECODE_SUFFIXESwith_suffix)r1   pathpath	candidateextr   r   r+   pyc_file_from_pathP   s   
rN   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)
r;   r<   r$   resubr   rG   load_module_pyrN   ImportError)rO   r   filename_as_path	module_idr1   rM   modulepyc_pathr   r   r+   load_python_filef   s&   




rY   rV   c                 C  s2   t j| |}|sJ t j|}|j| |S )N)rC   rD   spec_from_file_locationmodule_from_specloaderexec_module)rV   r1   specrW   r   r   r+   rS      s
   rS   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   r;   PurePathr<   )r1   r   r   r+   r      s
   
r   )r   r   r   r   r   r   r   r   r   r   r   r   )r-   r   r   r.   )r1   r   r   rB   )rO   r   r   r   r   r   )rV   r   r1   r   r   r   )r1   r   r   r   ) 
__future__r   r4   
contextlibr   rC   importlib.machineryimportlib.utilr0   r;   rQ   r    typesr   typingr   r   r   makor   mako.templater	    r   excr   r,   rA   rN   rY   rS   r   r   r   r   r+   <module>   s2    




