o
    f\I                     @   s   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mZmZ ddlmZ ddlmZmZmZmZmZmZ eeZd Zed	Zd
Zeddd  Z dd ee !dD Z"dd Z#e#Z$G dd de%Z&dS )    )BytesION)ZipInfo   )	sysconfigdetect_encodingZipFile)finder)FileOperatorget_export_entryconvert_pathget_executableget_platformin_venva  
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 <assemblyIdentity version="1.0.0.0"
 processorArchitecture="X86"
 name="%s"
 type="win32"/>

 <!-- Identify the application security requirements. -->
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
 <security>
 <requestedPrivileges>
 <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
 </requestedPrivileges>
 </security>
 </trustInfo>
</assembly>s   ^#!.*pythonw?[0-9.]*([ 	].*)?$z# -*- coding: utf-8 -*-
import re
import sys
from %(module)s import %(import_name)s
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(%(func)s())
.c                 C   s"   i | ]}|j d r|j |jqS )z.exe)nameendswithbytes).0r r   W/var/www/html/mig_web/myenv/lib/python3.10/site-packages/pip/_vendor/distlib/scripts.py
<dictcomp>@   s    
r    c                 C   sZ   d| v r+|  dr"| dd\}}d|v r | ds d||f } | S |  ds+d|  } | S )N z/usr/bin/env r   "z%s "%s"z"%s")
startswithsplit)
executableenv_executabler   r   r   enquote_executableG   s   

r    c                   @   s   e Zd ZdZeZdZ			d*ddZdd Ze	j
d	r$d
d Zdd Zdd Zd+ddZdd ZeZdd Zdd ZdZdd Zd,ddZdd Zed d! Zejd"d! Zejd#ksfejd	krjejd#krjd$d% Zd,d&d'Z d,d(d)Z!dS )-ScriptMakerz_
    A class to copy or create scripts from source scripts or callable
    specifications.
    NTFc                 C   s   || _ || _|| _d| _d| _tjdkptjdkotjdk| _t	d| _
|p)t|| _tjdkp9tjdko9tjdk| _tj| _d S )NFposixjava)r   X.Ynt)
source_dir
target_diradd_launchersforceclobberosr   _nameset_modesetvariantsr	   _fileop_is_ntsysversion_info)selfr&   r'   r(   dry_runfileopr   r   r   __init__d   s   
zScriptMaker.__init__c                 C   s@   | ddr| jrtj|\}}|dd}tj||}|S )NguiFpythonpythonw)getr1   r+   pathr   replacejoin)r4   r   optionsdnfnr   r   r   _get_alternate_executabley   s
   z%ScriptMaker._get_alternate_executabler#   c              	   C   sd   zt |}|ddkW  d   W S 1 sw   Y  W dS  ttfy1   td| Y dS w )zl
            Determine if the specified executable is a script
            (contains a #! line)
               z#!NzFailed to open %sF)openreadOSErrorIOErrorloggerwarning)r4   r   fpr   r   r   	_is_shell   s   
(zScriptMaker._is_shellc                 C   sJ   |  |rdd l}|jjddkr|S d| S | dr!|S d| S )Nr   zos.nameLinuxz
jython.exez/usr/bin/env %s)rK   r#   langSystemgetPropertylowerr   )r4   r   r#   r   r   r   _fix_jython_executable   s   
z"ScriptMaker._fix_jython_executablec                 C   s   t jdkrd}nt|t| d }tjdkrd}nd}d|vo#||k}|r0d| | d	 }|S d
}|d| | d 7 }|d7 }|S )a  
        Build a shebang line. In the simple case (on Windows, or a shebang line
        which is not too long or contains spaces) use a simple formulation for
        the shebang. Otherwise, use /bin/sh as the executable, with a contrived
        shebang which allows the script to run either under Python or sh, using
        suitable quoting. Thanks to Harald Nordgren for his input.

        See also: http://www.in-ulm.de/~mascheck/various/shebang/#length
                  https://hg.mozilla.org/mozilla-central/file/tip/mach
        r"   T   darwini          s   #!   
s
   #!/bin/sh
s	   '''exec' s    "$0" "$@"
s   ' ''')r+   r   lenr2   platform)r4   r   post_interpsimple_shebangshebang_lengthmax_shebang_lengthresultr   r   r   _build_shebang   s    

zScriptMaker._build_shebang    c                 C   sn  d}| j r| j }d}nDt st }n<t r&tjtddt	d }n)tj
dkr;tjt	ddt	d }ntjt	ddt	d	t	df }|rW| ||}tjd
rb| |}|rht|}|d}tjdkr~d|vr~d|vr~|d7 }| ||}z|d W n ty   td| w |dkrz|| W |S  ty   td||f w |S )NTFscriptszpython%sEXEr%   BINDIRz
python%s%sVERSIONr#   utf-8cliz	-X:Framesz-X:FullFramess
    -X:Framesz,The shebang (%r) is not decodable from utf-8z?The shebang (%r) is not decodable from the script encoding (%r))r   r   is_python_buildr   r   r+   r<   r>   get_pathget_config_varr   rB   r2   rX   r   rQ   r    encoder^   decodeUnicodeDecodeError
ValueError)r4   encodingrY   r?   enquoter   shebangr   r   r   _get_shebang   sd   



zScriptMaker._get_shebangc                 C   s$   | j t|j|jdd |jd S )Nr   r   )moduleimport_namefunc)script_templatedictprefixsuffixr   )r4   entryr   r   r   _get_script_text  s
   zScriptMaker._get_script_textc                 C   s   t j|}| j| S N)r+   r<   basenamemanifest)r4   exenamebaser   r   r   get_manifest	  s   
zScriptMaker.get_manifestc                 C   s0  | j o| j}tjd}||s||7 }|s|| }nW|dkr&| d}n| d}t }	t|	d.}
tj	
d}|rTtt|d d }td|d}|
|| n|
d| W d    n1 sdw   Y  |	 }|| | }|D ]}tj| j|}|rtj|\}}|d	r|}d
| }z	| j|| W nr ty   td d| }tj|rt| t|| | j|| td zt| W n	 ty   Y nw Y n3w | jr|d| sd||f }tj|r| jstd| qu| j|| | j r| j!|g |"| qud S )Nrd   pytwSOURCE_DATE_EPOCH   z__main__.py)filename	date_timez.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz%s.deletemez0Able to replace executable using .deleteme logicr   z%s.%szSkipping existing file %s)#r(   r1   r+   linesepri   r   _get_launcherr   r   environr;   timegmtimeintr   writestrgetvaluer<   r>   r'   splitextr   r0   write_binary_file	ExceptionrH   rI   existsremoverenamedebugr*   r-   set_executable_modeappend)r4   namesro   script_bytes	filenamesextuse_launcherr   launcherstreamzfsource_date_epochr   zinfozip_datar   outnamenedfnamer   r   r   _write_script  sv   


	




zScriptMaker._write_script-c                 C   sn   t  }d| jv r|| d| jv r|d|| jd f  d| jv r5|d|| j| jd | jd f  |S )Nr   Xz%s%sr   r$   z	%s%s%s.%sr   )r.   r/   addr3   variant_separator)r4   r   r]   r   r   r   get_script_filenamesK  s   



z ScriptMaker.get_script_filenamesc           
      C   s   d}|r| dg }|rdd| }|d}| jd||d}| |d}| |j}|r9| ddr9d	}	nd
}	| |||||	 d S )Nr_   interpreter_argsz %sr   rd   r?   r8   Fpywr   )r;   r>   ri   rp   ry   r   r   r   )
r4   rx   r   r?   rY   argsro   scriptscriptnamesr   r   r   r   _make_scriptW  s   
zScriptMaker._make_scriptc                 C   s  d}t j| jt|}t j| jt j|}| js*| j	||s*t
d| d S zt|d}W n ty@   | js< d }Y n#w | }|sOt
d| d S t|dd}|rcd}|dpbd	}|s|rk|  | j|| | jr|| j|g || d S t
d
|| j | jjst|j\}	}
|d | |	|}d|v rd}nd}t j|}| |g|| || |r|  d S d S )NFznot copying %s (up-to-date)rbz%s is an empty file (skipping)s   
rV   Tr   r_   zcopying and adjusting %s -> %sr   s   pythonwr   r   ) r+   r<   r>   r&   r   r'   r{   r)   r0   newerrH   r   rD   rG   r5   readlinerI   FIRST_LINE_REmatchr=   groupclose	copy_filer-   r   r   infor   seekrp   r   rE   )r4   r   r   adjustr   f
first_liner   rY   rm   linesro   r   r   r   r   r   _copy_scriptg  sV   
zScriptMaker._copy_scriptc                 C   s   | j jS rz   r0   r5   )r4   r   r   r   r5     s   zScriptMaker.dry_runc                 C   s   || j _d S rz   r   )r4   valuer   r   r   r5     s   r%   c                 C   s\   t ddkr
d}nd}t dkrdnd}d|||f }|tvr*d	|tf }t|t| S )
NP   6432z	win-arm64z-armr   z
%s%s%s.exez(Unable to find resource %s in package %s)structcalcsizer   WRAPPERSdistlib_packagerl   )r4   kindbitsplatform_suffixr   msgr   r   r   r     s   zScriptMaker._get_launcherc                 C   s8   g }t |}|du r| || |S | j|||d |S )a  
        Make a script.

        :param specification: The specification, which is either a valid export
                              entry specification (to make a script from a
                              callable) or a filename (to make a script by
                              copying from a source location).
        :param options: A dictionary of options controlling script generation.
        :return: A list of all absolute pathnames written to.
        Nr   )r
   r   r   )r4   specificationr?   r   rx   r   r   r   make  s   zScriptMaker.makec                 C   s$   g }|D ]}| | || q|S )z
        Take a list of specifications and make scripts from them,
        :param specifications: A list of specifications.
        :return: A list of all absolute pathnames written to,
        )extendr   )r4   specificationsr?   r   r   r   r   r   make_multiple  s   zScriptMaker.make_multiple)TFN)r_   Nrz   )"__name__
__module____qualname____doc__SCRIPT_TEMPLATErt   r   r7   rB   r2   rX   r   rK   rQ   r^   rp   ry   _DEFAULT_MANIFESTr|   r   r   r   r   r   r   propertyr5   setterr+   r   r,   r   r   r   r   r   r   r   r!   [   s>    

H<
3



r!   )'ior   loggingr+   rer   r2   r   zipfiler   compatr   r   r   	resourcesr   utilr	   r
   r   r   r   r   	getLoggerr   rH   stripr   compiler   r   rsplitr   iteratorr   r    _enquote_executableobjectr!   r   r   r   r   <module>   s0    

