o
    ä§ÊhfB  ã                   @   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 e e¡Zd ¡ Ze d¡Zd	Zd
d„ ZG dd„ deƒZdS )é    )ÚBytesIONé   )Ú	sysconfigÚdetect_encodingÚZipFile)Úfinder)ÚFileOperatorÚget_export_entryÚconvert_pathÚget_executableÚ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   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Ú_executable© r   úA/var/www/html/env/lib/python3.10/site-packages/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	¡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)dd„Zdd„ Zedd„ ƒZejdd„ ƒZejd ks_ejd	krcejd krcd!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   sz   || _ || _|| _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| _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)Úselfr   r   r   Údry_runÚfileopr   r   r   Ú__init__L   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   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)r*   r   Úfpr   r   r   Ú	_is_shelld   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)rA   r   ÚlangÚSystemÚgetPropertyÚlowerÚendswith)r*   r   r   r   r   r   Ú_fix_jython_executablep   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#   ÚlenÚsysÚplatform)r*   r   Úpost_interpÚsimple_shebangÚshebang_lengthÚmax_shebang_lengthÚresultr   r   r   Ú_build_shebang|   s    

ÿýzScriptMaker._build_shebangó    c                 C   sD  d}| j r| j }d}n/t ¡ stƒ }n'tƒ r&tj t d¡dt 	d¡ ¡}ntj t 	d¡dt 	d¡t 	d¡f ¡}|rB|  
||¡}tj d	¡rM|  |¡}|rSt|ƒ}| d
¡}tjdkrid|vrid|vri|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Ú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"   r2   r4   Úget_pathÚget_config_varr8   rO   rP   r   rH   r   ÚencoderV   ÚdecodeÚUnicodeDecodeErrorÚ
ValueError)r*   ÚencodingrQ   r5   Ú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"   r2   ÚbasenameÚmanifest)r*   ÚexenameÚbaser   r   r   Úget_manifestâ   s   
zScriptMaker.get_manifestc                 C   sî  | j o| j}tj d¡}| |¡s||7 }|s|| }n7|dkr&|  d¡}n|  d¡}tƒ }	t|	dƒ�}
|
 	d|¡ W d   ƒ n1 sDw   Y  |	 
¡ }|| | }|D ]Ÿ}tj | j|¡}|r¾tj |¡\}}| d¡rp|}d| }z	| j ||¡ W nq ty½   t d¡ d	| }tj |¡r˜t |¡ t ||¡ | j ||¡ t d
¡ zt |¡ W n	 tyº   Y nw Y n2w | jrÎ| d| ¡sÎd||f }tj |¡rÞ| jsÞt d|¡ qU| j ||¡ | jrï| j |g¡ | |¡ qUd 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 logicri   z%s.%szSkipping existing file %s)r   r)   r"   Úlinesepra   rG   Ú_get_launcherr   r   ÚwritestrÚgetvaluer2   r4   r   Úsplitextr   r(   Úwrite_binary_fileÚ	Exceptionr>   r?   ÚexistsÚremoveÚrenameÚdebugr!   r%   Úset_executable_modeÚappend)r*   Únamesrg   Úscript_bytesÚ	filenamesÚextÚuse_launcherr|   ÚlauncherÚstreamÚzfÚzip_datar#   ÚoutnameÚnÚeÚdfnamer   r   r   Ú_write_scriptæ   sb   


ÿ



ÿ€óßzScriptMaker._write_scriptc                 C   sì   d}|r|  dg ¡}|rdd |¡ }| d¡}| jd||d�}|  |¡ d¡}|j}tƒ }	d| jv r8|	 |¡ d| jv rI|	 d	|t	j
d
 f ¡ d| jv r^|	 d|t	j
d
 t	j
d f ¡ |ri|  dd¡rid}
nd}
|  |	||||
¡ d S )NrW   Úinterpreter_argsz %sr   r\   ©r5   r   ÚXz%s%sr   r   z%s-%s.%sr   r.   FÚpywry   )r1   r4   ra   rh   rr   r#   r&   r'   ÚaddrO   Úversion_infor–   )r*   rq   r‹   r5   rQ   Úargsrg   Úscriptr#   ÚscriptnamesrŒ   r   r   r   Ú_make_script  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 | ¡ }|sRt
 d|  ¡ |¡ d S t | dd¡¡}|rfd}| d¡ped	}|s†|rn| ¡  | 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: %s is an empty file (skipping)s   
rM   Tr   rW   zcopying and adjusting %s -> %sr   s   pythonwrš   ry   )!r"   r2   r4   r   r
   r   rt   r    r(   Únewerr>   r†   r:   r=   r+   Úreadliner?   Úget_command_nameÚFIRST_LINE_REÚmatchr3   ÚgroupÚcloseÚ	copy_filer%   r‡   rˆ   Úinfor   Úseekrh   r–   r;   )r*   rž   r‹   Úadjustr’   ÚfÚ
first_liner¦   rQ   re   Úlinesrg   rŒ   r“   r   r   r   Ú_copy_script2  sZ   ýÿÿ
ÿzScriptMaker._copy_scriptc                 C   s   | j jS rs   ©r(   r+   )r*   r   r   r   r+   f  s   zScriptMaker.dry_runc                 C   s   || j _d S rs   r±   )r*   Úvaluer   r   r   r+   j  s   r   c                 C   s`   t  d¡dkr
d}nd}d||f }t dd¡d }t|ƒ |¡}|s-d	||f }t|ƒ‚|jS )
NÚPé   Ú64Ú32z%s%s.exeri   r   r   z(Unable to find resource %s in package %s)ÚstructÚcalcsizeÚ__name__Úrsplitr   Úfindrd   Úbytes)r*   ÚkindÚbitsr#   Údistlib_packageÚresourceÚmsgr   r   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    )r*   Úspecificationr5   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Ã   )r*   Úspecificationsr5   r‹   rÂ   r   r   r   Úmake_multiple—  s   zScriptMaker.make_multiple)TFN)rW   Nrs   ) r¹   Ú
__module__Ú__qualname__Ú__doc__ÚSCRIPT_TEMPLATErm   r   r-   r8   rO   rP   r   rA   rH   rV   rh   rr   Ú_DEFAULT_MANIFESTru   rx   r–   r    r°   Úpropertyr+   Úsetterr"   r#   r$   r}   rÃ   rÆ   r   r   r   r   r   C   s6    
ÿ
@
44


r   )Úior   Úloggingr"   Úrer·   rO   Úcompatr   r   r   Ú	resourcesr   Úutilr   r	   r
   r   r   Ú	getLoggerr¹   r>   ÚstriprË   Úcompiler¥   rÊ   r   Úobjectr   r   r   r   r   Ú<module>   s"   
ð

