U
    X…7h°H  ã                   @   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jdksÆe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é   )Ú	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())
ÚntÚjavaÚ.c                 C   s"   i | ]}|j  d ¡r|j |j“qS )z.exe)ÚnameÚendswithÚbytes)Ú.0Úr© r   úU/var/www/formularioweb/env/lib/python3.8/site-packages/pip/_vendor/distlib/scripts.pyÚ
<dictcomp>@   s   þ r   Ú c                 C   sX   d| krT|   d¡rB|  dd¡\}}d|krT|  d¡sTd||f } n|   d¡sTd|  } | S )Nú z/usr/bin/env r   ú"z%s "%s"z"%s")Ú
startswithÚsplit)Ú
executableÚenvZ_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	¡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Ú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_runZ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ÚpythonZpythonw)Úgetr0   r*   Úpathr   ÚreplaceÚjoin)r3   r   ÚoptionsÚdnÚfnr   r   r   Ú_get_alternate_executabler   s
    z%ScriptMaker._get_alternate_executabler   c              
   C   s\   z0t |ƒ}| d¡dkW  5 Q R £ W S Q R X W n& ttfk
rV   t d|¡ Y dS X dS )zl
            Determine if the specified executable is a script
            (contains a #! line)
            é   z#!zFailed to open %sFN)ÚopenÚreadÚOSErrorÚIOErrorÚloggerÚwarning)r3   r   Úfpr   r   r   Ú	_is_shell{   s    
&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)rH   r   ÚlangÚSystemÚgetPropertyÚlowerr   )r3   r   r   r   r   r   Ú_fix_jython_executable‡   s    
z"ScriptMaker._fix_jython_executablec                 C   s”   t jdkrd}nJttddƒr"d}n8t|ƒt|ƒ d }tjdkrFd}nd}d	|koX||k}|rpd
| | 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#   TZcross_compilingFé   Údarwini   é   ó    s   #!ó   
s
   #!/bin/sh
s	   '''exec' s    "$0" "$@"
s   ' '''
)r*   r   Úgetattrr1   ÚlenÚplatform)r3   r   Úpost_interpZsimple_shebangZshebang_lengthZmax_shebang_lengthÚresultr   r   r   Ú_build_shebang“   s    

zScriptMaker._build_shebangó    c                 C   s~  d}| j r| j }d}nˆt ¡ s&tƒ }nxtƒ rLtj t d¡dt 	d¡ ¡}nRtj
dkrvtj t 	d¡dt 	d¡ ¡}n(tj t 	d¡dt 	d	¡t 	d¡f ¡}|r®|  ||¡}tj d
¡rÄ|  |¡}|rÐt|ƒ}| d¡}tjdkrüd|krüd|krü|d7 }|  ||¡}z| d¡ W n" tk
r8   td| ƒ‚Y nX |dkrzz| |¡ W n& tk
rx   td||f ƒ‚Y nX |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*   r9   r;   Úget_pathÚget_config_varr   r?   r1   rV   r   rN   r!   ÚencoderY   ÚdecodeÚUnicodeDecodeErrorÚ
ValueError)r3   ÚencodingrW   r<   Zenquoter   Úshebangr   r   r   Ú_get_shebang·   sP     
ÿþ

ÿ
ÿzScriptMaker._get_shebangc                 C   s$   | j t|j|j d¡d |jd S )Nr   r   )ÚmoduleZimport_nameÚfunc)Úscript_templateÚdictÚprefixÚsuffixr   )r3   Úentryr   r   r   Ú_get_script_textù   s
      ÿzScriptMaker._get_script_textc                 C   s   t j |¡}| j| S ©N)r*   r9   ÚbasenameÚmanifest)r3   ÚexenameÚbaser   r   r   Úget_manifestÿ   s    zScriptMaker.get_manifestc                 C   s  | j o
| j}|s|| }nš|dkr.|  d¡}n
|  d¡}tƒ }t|dƒR}	tj d¡}
|
rŠt 	t
|
ƒ¡d d… }td|d}|	 ||¡ n|	 d|¡ W 5 Q R X | ¡ }|| | }|D ]V}tj | j|¡}|rštj |¡\}}| d¡rò|}d	| }z| j ||¡ W nŠ tk
r–   t d
¡ d| }tj |¡rHt |¡ t ||¡ | j ||¡ t d¡ zt |¡ W n tk
r   Y nX Y nX nl| jr¾| d| ¡s¾d||f }tj |¡râ| jsât d|¡ q¸| j ||¡ | jr| j |g¡ |  |¡ q¸d S )NÚ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'   r0   Ú_get_launcherr   r   r*   Úenvironr8   ÚtimeÚgmtimeÚintr   ÚwritestrÚgetvaluer9   r;   r&   Úsplitextr   r/   Zwrite_binary_fileÚ	ExceptionrE   rF   ÚexistsÚremoveÚrenameÚdebugr   r)   r,   Úset_executable_modeÚappend)r3   Únamesri   Zscript_bytesÚ	filenamesÚextZuse_launcherZlauncherÚstreamÚzfZsource_date_epochr   ÚzinfoZzip_datar   ÚoutnameÚnÚeZdfnamer   r   r   Ú_write_script  s\    






zScriptMaker._write_scriptú-c                 C   sn   t ƒ }d| jkr| |¡ d| jkr<| d|| jd f ¡ d| jkrj| d|| j| jd | jd f ¡ |S )Nr   ÚXz%s%sr   r$   z	%s%s%s.%sr   )r-   r.   Úaddr2   Úvariant_separator)r3   r   rX   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 )NrZ   Zinterpreter_argsz %sr   r_   ©r<   r6   FÚpywry   )r8   r;   rd   rj   rr   r   r   r˜   )
r3   rq   r   r<   rW   Úargsri   ÚscriptZscriptnamesr‘   r   r   r   Ú_make_scriptF  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k
r‚   | jsz‚ d }Y nFX | ¡ }|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|krVd}nd}t j |¡}|  |g|| ¡ ||¡ |rŒ| ¡  d S )NFznot copying %s (up-to-date)Úrbz%s is an empty file (skipping)s   
rS   Tr   rZ   zcopying and adjusting %s -> %sr   s   pythonwrŸ   ry   ) r*   r9   r;   r%   r   r&   rt   r(   r/   ÚnewerrE   rŒ   rA   rD   r4   ÚreadlinerF   ÚFIRST_LINE_REÚmatchr:   ÚgroupÚcloseÚ	copy_filer,   r   rŽ   Úinfor   Úseekrj   r˜   rB   )r3   r¡   r   Zadjustr•   ÚfÚ
first_liner§   rW   rh   Úlinesri   r‘   r–   r   r   r   Ú_copy_scriptV  sN    



zScriptMaker._copy_scriptc                 C   s   | j jS rs   ©r/   r4   )r3   r   r   r   r4   ˆ  s    zScriptMaker.dry_runc                 C   s   || j _d S rs   r±   )r3   Úvaluer   r   r   r4   Œ  s    r   c                 C   s\   t  d¡dkrd}nd}tƒ dkr&dnd}d|||f }|tkrTd	|tf }t|ƒ‚t| S )
NÚPé   Z64Z32z	win-arm64z-armr   z
%s%s%s.exez(Unable to find resource %s in package %s)ÚstructÚcalcsizer   ÚWRAPPERSÚDISTLIB_PACKAGErg   )r3   ÚkindÚbitsZplatform_suffixr   Úmsgr   r   r   r€   ”  s    ÿzScriptMaker._get_launcherc                 C   s6   g }t |ƒ}|dk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¢   )r3   Úspecificationr<   r   rq   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½   )r3   Zspecificationsr<   r   r¼   r   r   r   Úmake_multiple¶  s    zScriptMaker.make_multiple)TFN)rZ   N)N)N)N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚSCRIPT_TEMPLATErm   r   r5   r?   r1   rV   r   rH   rN   rY   rj   rr   Ú_DEFAULT_MANIFESTru   rx   r˜   rœ   r   r¢   r°   Úpropertyr4   Úsetterr*   r   r+   r€   r½   r¿   r   r   r   r   r"   [   s4   
$
B7

2


r"   ))Úior   Úloggingr*   Úrerµ   r1   r‚   Úzipfiler   Úcompatr   r   r   Ú	resourcesr   Úutilr	   r
   r   r   r   r   Ú	getLoggerrÀ   rE   ÚstriprÅ   Úcompiler¦   rÄ   r   r+   Úrsplitr¸   Úiteratorr·   r!   Z_enquote_executableÚobjectr"   r   r   r   r   Ú<module>   s,    

þ