
    ZeIic                        d dl mZ d dlZ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d(dZd)dZd*d Zd+d$Zd,d&Zd-d'ZdS ).    )annotationsN)	ExitStack)	resources)
ModuleType)Any)Optional)Union)
exceptions)Template   )CommandErrorF)append_with_newlinestemplate_fileUnion[str, os.PathLike[str]]destoutput_encodingstrr   boolkwr   returnNonec                  t          t          |                     }	  |j        d	i |                    |          }t	          ||rdnd          5 }|r(|                    d                    |                     |                    |           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abwbz

z.txtF)suffixdeletezDTemplate rendering failed; see %s for a template-oriented traceback. )r   _preserving_path_as_strrender_unicodeencodeopenwritetempfileNamedTemporaryFiler
   text_error_templatenamer   )
r   r   r   r   r   templateoutputfntffnames
             Y/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/alembic/util/pyfiles.pytemplate_to_filer.      s    !8!G!GHHHH((..2..55oFF $ 4>$?? 	1# 8o66777GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
(uEEE 	II.00!!((  
 HE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 +-23
 
 	
sC    B- A B  B$'B$-EAD$E$D(	(E+D(	,Efname_or_resourcepathlib.Pathc                   t           j                            |           sd| v r|                     d          }t	                      }t          j        |j                   t          j	        |d                   }|dd         D ]}||z  }|
                    t          j        |                    } 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   filesenter_contextas_filepathlibPath)r/   tokensfile_managerreftoks        r-   coerce_resource_to_filenamerC   6   s     7==*++ 
7H0H0H"((-- !{{*+++ofQi((!"": 	 	C)CC(66c""
 
 <)***    r4   Optional[pathlib.Path]c                   t          j        |           }t          j        t          j                            |                                                    }|                                r|S |j        }t          j        j	        D ]@}|
                    |                                          r|
                    |          c S Ad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)r4   pathpath	candidateexts       r-   pyc_file_from_pathrR   P   s    
 |D!!H(():):)<)<== I   /C"4  $$++-- 	-'',,,,,	- trD   dir_r   r   c                   t          j        |           } t          j        |          }|j        }t          j        dd|          }| |z  }|j        }|dk    rY|                                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)
r=   r>   r'   resubr   rK   load_module_pyrR   ImportError)rS   r   filename_as_path	module_idr4   rQ   modulepyc_paths           r-   load_python_filer^   f   s    
 <D|H--$Huc8,,I(?D
+C
e||;;== 	=#It44FF)$//H!"="DEEE'	8<<	 	 	 	400MrD   r[   c                    t           j                            | |          }|sJ t           j                            |          }|j                            |           |S )N)rG   rH   spec_from_file_locationmodule_from_specloaderexec_module)r[   r4   specr\   s       r-   rX   rX      sT     >11)TBBDKKK^,,T22FKF###MrD   c                    t          | t                    r| S t          | t          j                  rt          |           S t          t          j        |                     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>   )r4   s    r-   r   r      sT     $ '	D'*	+	+ '4yy7<%%&&&rD   )r   r   r   r   r   r   r   r   r   r   r   r   )r/   r   r   r0   )r4   r   r   rE   )rS   r   r   r   r   r   )r[   r   r4   r   r   r   )r4   r   r   r   )
__future__r   r7   
contextlibr   rG   r   importlib.machineryimportlib.utilr3   r=   rV   r$   typesr   typingr   r   r	   makor
   mako.templater   excr   r.   rC   rR   r^   rX   r   r   rD   r-   <module>rq      s   " " " " " "                                				  				                                " " " " " "       "'     <+ + + +4   ,   8   ' ' ' ' ' 'rD   