o
    ­—Žj“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 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mZ e e¡Zd	 ¡ Ze d
¡Z dZ!ej"dkskej"dkrej#dkr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é   )ÚDistlibException)Ú	sysconfigÚdetect_encodingÚZipFile)Úfinder)ÚFileOperatorÚget_export_entryÚconvert_pathÚget_executableÚget_platformÚin_venvÚis_in_directoryañ  
<?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
if __name__ == '__main__':
    from %(module)s import %(import_name)s
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(%(func)s())
ÚntÚjavaÚ.c                 C   s"   i | ]}|j  d ¡r|j |j“qS )z.exe)ÚnameÚendswithÚbytes)Ú.0Úr© r   úX/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pip/_vendor/distlib/scripts.pyÚ
<dictcomp>B   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_executableI   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scejd	krgejd#krgd$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Úposixr   )r   úX.Yr   )Ú
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__f   s    
 zScriptMaker.__init__c                 C   s@   |  dd¡r| jrtj |¡\}}| dd¡}tj ||¡}|S )NÚguiFÚpythonÚpythonw)Úgetr3   r-   Úpathr    ÚreplaceÚjoin)r6   r!   ÚoptionsÚdnÚfnr   r   r   Ú_get_alternate_executablet   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)r6   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)rM   r   ÚlangÚSystemÚgetPropertyÚlowerr   )r6   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dƒrd}nt|ƒt|ƒ d }tjdkr#d}nd}d	|vo,||k}|r9d
| | 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Úcross_compilingFé   Údarwini   é   ó    s   #!ó   
s
   #!/bin/sh
s	   '''exec' s    "$0" "$@"
s   ' '''
)r-   r   Úgetattrr4   ÚlenÚplatform)r6   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rµz| |¡ 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   rD   r4   r\   r   rS   r$   Úencoderb   ÚdecodeÚUnicodeDecodeErrorÚ
ValueError)r6   Úencodingr]   rA   Úenquoter!   Úshebangr   r   r   Ú_get_shebang¹   sT    
ÿþ

ÿýÿÿ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    )r6   Úentryr   r   r   Ú_get_script_textû   s   ÿzScriptMaker._get_script_textc                 C   s   t j |¡}| j| S ©N)r-   r>   ÚbasenameÚmanifest)r6   ÚexenameÚbaser   r   r   Úget_manifest  s   
zScriptMaker.get_manifestc                 C   s.  | j o| j}|s|| }nW|dkr|  d¡}n|  d¡}tƒ }t|dƒ�.}	tj d¡}
|
rEt 	t
|
ƒ¡d d… }td|d�}|	 ||¡ n|	 d|¡ W d   ƒ n1 sUw   Y  | ¡ }|| | }|D ]®}tj tj | j|¡¡}t|| jƒs~tdƒ‚|rÝtj |¡\}}| d	¡r�|}d
| }z	| j ||¡ W nr tyÜ   t d¡ d| }tj |¡r·t |¡ t ||¡ | j ||¡ t d¡ zt |¡ W n	 tyÙ   Y nw Y n3w | jrí| d| ¡síd||f }tj |¡rý| j sýt d|¡ qf| j ||¡ | j!�r| j "|g¡ | #|¡ qfd S )NÚpyÚtÚwÚSOURCE_DATE_EPOCHé   z__main__.py)ÚfilenameÚ	date_timez"Attempt to escape script directoryz.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*   r3   Ú_get_launcherr   r   r-   Úenvironr=   ÚtimeÚgmtimeÚintr   ÚwritestrÚgetvaluer>   Úabspathr@   r)   r   r   Úsplitextr   r2   Úwrite_binary_fileÚ	ExceptionrJ   rK   ÚexistsÚremoveÚrenameÚdebugr   r,   r/   Úset_executable_modeÚappend)r6   Únamesrs   Úscript_bytesÚ	filenamesÚextÚuse_launcherÚlauncherÚstreamÚzfÚsource_date_epochrŠ   ÚzinfoÚzip_datar   ÚoutnameÚnÚeÚdfnamer   r   r   Ú_write_script  sl   

€ù



ÿ€óÝ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   )r0   r1   Úaddr5   Úvariant_separator)r6   r   ra   r   r   r   Úget_script_filenames@  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 )Nrc   Úinterpreter_argsz %sr   rh   ©rA   r:   FÚpywr„   )r=   r@   rm   rt   r}   r°   r   r«   )
r6   r|   rž   rA   r]   Úargsrs   ÚscriptÚscriptnamesrŸ   r   r   r   Ú_make_scriptJ  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s¼t|jƒ\}	}
| d¡ |  |	|¡}d|v r¨d}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   
rY   Tr   rc   zcopying and adjusting %s -> %sr   s   pythonwr³   r„   ) r-   r>   r@   r(   r   r)   r   r+   r2   ÚnewerrJ   r™   rF   rI   r7   ÚreadlinerK   ÚFIRST_LINE_REÚmatchr?   ÚgroupÚcloseÚ	copy_filer/   rš   r›   Úinfor   Úseekrt   r«   rG   )r6   rµ   rž   Úadjustr§   ÚfÚ
first_liner¼   r]   rq   Úlinesrs   rŸ   r¨   r   r   r   Ú_copy_scriptZ  sR   ý
ÿzScriptMaker._copy_scriptc                 C   s   | j jS r~   ©r2   r7   )r6   r   r   r   r7   Œ  s   zScriptMaker.dry_runc                 C   s   || j _d S r~   rÇ   )r6   Úvaluer   r   r   r7   �  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_PACKAGErp   )r6   Ú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·   )r6   ÚspecificationrA   rž   r|   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Ö   )r6   ÚspecificationsrA   rž   rÕ   r   r   r   Úmake_multipleº  s   zScriptMaker.make_multiple)TFN)rc   Nr~   )"Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚSCRIPT_TEMPLATErx   r!   r9   rD   r4   r\   r   rM   rS   rb   rt   r}   Ú_DEFAULT_MANIFESTr€   rƒ   r«   r¯   r°   r·   rÆ   Úpropertyr7   Úsetterr-   r   r.   r‹   rÖ   rÙ   r   r   r   r   r%   ]   s6    

$B9

2


r%   ),Úior   Úloggingr-   ÚrerÍ   r4   r�   Úzipfiler   r   r   Úcompatr   r   r   Ú	resourcesr	   Úutilr
   r   r   r   r   r   r   Ú	getLoggerrÚ   rJ   Ústriprß   Úcompiler»   rÞ   r   r.   ÚrsplitrÐ   ÚiteratorrÏ   r$   Ú_enquote_executableÚobjectr%   r   r   r   r   Ú<module>   s4   $
ð
þ