a
    hbòf8E  ã                   @   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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d
d„ ZeZG dd„ deƒZdS )é    )ÚBytesIONé   )Ú	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   sX   d| v rT|   d¡rB|  dd¡\}}d|v rT|  d¡sTd||f } n|   d¡sTd|  } | S )Nú z/usr/bin/env r   ú"z%s "%s"z"%s")Ú
startswithÚsplit)Ú
executableÚenvÚ_executable© r   úX/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/distlib/scripts.pyÚenquote_executable3   s    

r   c                   @   sæ   e Zd ZdZeZdZd*dd„Zdd„ Ze	j
 d	¡rBd
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sÆejd	krÎejd#krÎd$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ƒ| _
|pRt|ƒ| _tjdkprtjdkortjdk| _tj| _d S )NFÚposixÚjava)Ú úX.YÚnt)Ú
source_dirÚ
target_dirÚadd_launchersÚforceÚclobberÚosÚnameÚ_nameÚset_modeÚsetÚvariantsr   Ú_fileopÚ_is_ntÚsysÚversion_info)Úselfr   r   r    Údry_runÚfileopr   r   r   Ú__init__N   s    ÿ

ÿzScriptMaker.__init__c                 C   s@   |  dd¡r<| jr<tj |¡\}}| dd¡}tj ||¡}|S )NÚguiFÚpythonÚpythonw)Úgetr*   r#   Úpathr   ÚreplaceÚjoin)r-   r   ÚoptionsÚdnÚfnr   r   r   Ú_get_alternate_executable_   s
    z%ScriptMaker._get_alternate_executabler   c              	   C   sf   z<t |ƒ� }| d¡dkW  d  ƒ W S 1 s00    Y  W n$ ttfy`   t d|¡ Y dS 0 dS )zl
            Determine if the specified executable is a script
            (contains a #! line)
            é   z#!NzFailed to open %sF)ÚopenÚreadÚOSErrorÚIOErrorÚloggerÚwarning)r-   r   Úfpr   r   r   Ú	_is_shellg   s    
2zScriptMaker._is_shellc                 C   sD   |   |¡r*dd l}|jj d¡dkr<|S n| ¡  d¡r<|S d| S )Nr   zos.nameÚLinuxz
jython.exez/usr/bin/env %s)rD   r   ÚlangÚSystemÚgetPropertyÚlowerÚendswith)r-   r   r   r   r   r   Ú_fix_jython_executables   s    
z"ScriptMaker._fix_jython_executablec                 C   s‚   t jdkrd}n8t|ƒt|ƒ d }tjdkr4d}nd}d|voF||k}|r^d| | d	 }n 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$   Úlenr+   Úplatform)r-   r   Úpost_interpÚsimple_shebangÚshebang_lengthÚmax_shebang_lengthÚresultr   r   r   Ú_build_shebang   s    

ÿzScriptMaker._build_shebangó    c                 C   sz  d}| j r| j }d}nˆt ¡ s&tƒ }nxtƒ rLtj t d¡dt 	d¡ ¡}nRtj t 	d¡dt 	d¡t 	d¡f ¡}tj 
|¡sžtj t 	d¡dt 	d¡ ¡}|r®|  ||¡}tj d	¡rÄ|  |¡}|rÐt|ƒ}| d
¡}tjdkrüd|vrüd|vrü|d7 }|  ||¡}z| d
¡ W n  t�y6   td| ƒ‚Y n0 |d
k�rvz| |¡ W n$ t�yt   td||f ƒ‚Y n0 |S )NTFÚscriptszpython%sÚEXEÚ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#   r5   r7   Úget_pathÚget_config_varÚisfiler;   r+   rR   r   rK   r   ÚencoderX   ÚdecodeÚUnicodeDecodeErrorÚ
ValueError)r-   ÚencodingrS   r8   Úenquoter   Úshebangr   r   r   Ú_get_shebangž   s`    ÿ
ÿþÿ

ÿÿ

ÿÿ
zScriptMaker._get_shebangc                 C   s$   | j t|j|j d¡d |jd� S )NÚ.r   )ÚmoduleÚimport_nameÚfunc)Úscript_templateÚdictÚprefixÚsuffixr   )r-   Úentryr   r   r   Ú_get_script_textã   s    
þzScriptMaker._get_script_textc                 C   s   t j |¡}| j| S ©N)r#   r5   ÚbasenameÚmanifest)r-   ÚexenameÚbaser   r   r   Úget_manifestê   s    zScriptMaker.get_manifestc                 C   s  | j o
| j}tj d¡}| |¡s*||7 }|s8|| }nn|dkrL|  d¡}n
|  d¡}tƒ }	t|	dƒ�}
|
 	d|¡ W d   ƒ n1 sˆ0    Y  |	 
¡ }|| | }|D �]R}tj | j|¡}|�rˆtj |¡\}}| d¡rä|}d| }z| j ||¡ W n† t�y„   t d¡ d	| }tj |¡�r8t |¡ t ||¡ | j ||¡ t d
¡ zt |¡ W n t�y~   Y n0 Y n0 nl| j�r¬| d| ¡�s¬d||f }tj |¡�rÐ| j�sÐt d|¡ qª| j ||¡ | j�rô| j |g¡ | |¡ qªd S )Nr^   ÚpyÚtÚwz__main__.pyz.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz%s.deletemez0Able to replace executable using .deleteme logicrl   z%s.%szSkipping existing file %s)r    r*   r#   Úlineseprd   rJ   Ú_get_launcherr   r   ÚwritestrÚgetvaluer5   r7   r   Úsplitextr   r)   Úwrite_binary_fileÚ	ExceptionrA   rB   ÚexistsÚremoveÚrenameÚdebugr"   r&   Úset_executable_modeÚappend)r-   Únamesrj   Úscript_bytesÚ	filenamesÚextÚuse_launcherr   ÚlauncherÚstreamÚzfÚzip_datar$   ÚoutnameÚnÚeÚdfnamer   r   r   Ú_write_scriptî   sX    


*




zScriptMaker._write_scriptú-c                 C   sn   t ƒ }d| jv r| |¡ d| jv r<| d|| jd f ¡ d| jv rj| d|| j| jd | jd f ¡ |S )Nr   ÚXz%s%sr   r   z	%s%s%s.%sr   )r'   r(   Úaddr,   Úvariant_separator)r-   r$   rW   r   r   r   Úget_script_filenames$  s    



ÿz ScriptMaker.get_script_filenamesc           
      C   sŒ   d}|r0|  dg ¡}|r0dd |¡ }| d¡}| jd||d�}|  |¡ d¡}|  |j¡}|rr|  dd¡rrd	}	nd
}	|  |||||	¡ d S )NrY   Úinterpreter_argsz %sr   r^   ©r8   r1   FÚpywr|   )r4   r7   rd   rk   ru   rž   r$   r™   )
r-   rt   rŽ   r8   rS   Úargsrj   ÚscriptÚscriptnamesr�   r   r   r   Ú_make_script/  s    
zScriptMaker._make_scriptc                 C   sŽ  d}t j | jt|ƒ¡}t j | jt j |¡¡}| jsT| j 	||¡sTt
 d|¡ d S zt|dƒ}W n ty€   | jsx‚ d }Y nF0 | ¡ }|sžt
 d|¡ d S t | dd¡¡}|rÆd}| d¡pÄd	}|�s|rØ| ¡  | j ||¡ | jrú| j |g¡ | |¡ n„t
 d
|| j¡ | jj�s|t|jƒ\}	}
| d¡ |  |	|¡}d|v �rTd}nd}t j |¡}|  |g|| ¡ ||¡ |�rŠ| ¡  d S )NFznot copying %s (up-to-date)Úrbz%s is an empty file (skipping)s   
rP   Tr   rY   zcopying and adjusting %s -> %sr   s   pythonwr¡   r|   ) r#   r5   r7   r   r
   r   rw   r!   r)   ÚnewerrA   r‰   r=   r@   r.   ÚreadlinerB   ÚFIRST_LINE_REÚmatchr6   ÚgroupÚcloseÚ	copy_filer&   rŠ   r‹   Úinfor   Úseekrk   r™   r>   )r-   r£   rŽ   Úadjustr•   ÚfÚ
first_linerª   rS   rh   Úlinesrj   r�   r–   r   r   r   Ú_copy_script?  sR    
ÿ


zScriptMaker._copy_scriptc                 C   s   | j jS rv   ©r)   r.   )r-   r   r   r   r.   r  s    zScriptMaker.dry_runc                 C   s   || j _d S rv   rµ   )r-   Úvaluer   r   r   r.   v  s    r   c                 C   st   t  d¡dkrd}nd}tƒ dkr&dnd}d|||f }t d	d
¡d }t|ƒ |¡}|snd||f }t|ƒ‚|jS )NÚPé   Z64Z32z	win-arm64z-armr   z
%s%s%s.exerl   r   r   z(Unable to find resource %s in package %s)	ÚstructÚcalcsizer   Ú__name__Úrsplitr   Úfindrg   Úbytes)r-   ÚkindÚbitsZplatform_suffixr$   Zdistlib_packageÚresourceÚmsgr   r   r   r€   ~  s    ÿzScriptMaker._get_launcherc                 C   s6   g }t |ƒ}|du r"|  ||¡ n| 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¥   )r-   Úspecificationr8   rŽ   rt   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Ä   )r-   Úspecificationsr8   rŽ   rÃ   r   r   r   Úmake_multiple¤  s    zScriptMaker.make_multiple)TFN)rY   N)N)N)N)"r»   Ú
__module__Ú__qualname__Ú__doc__ÚSCRIPT_TEMPLATErp   r   r0   r;   r+   rR   r   rD   rK   rX   rk   ru   Ú_DEFAULT_MANIFESTrx   r{   r™   r�   rž   r¥   r´   Úpropertyr.   Úsetterr#   r$   r%   r€   rÄ   rÇ   r   r   r   r   r   E   s8     ÿ

E4
3


r   ) Úior   Úloggingr#   Úrer¹   r+   Úcompatr   r   r   Ú	resourcesr   Úutilr   r	   r
   r   r   r   Ú	getLoggerr»   rA   ÚstriprÌ   Úcompiler©   rË   r   Ú_enquote_executableÚobjectr   r   r   r   r   Ú<module>   s    


