B
    =)H[hB  ã               @   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.]*([ 	].*)?$a|  # -*- coding: utf-8 -*-
if __name__ == '__main__':
    import sys, re

    def _resolve(module, func):
        __import__(module)
        mod = sys.modules[module]
        parts = func.split('.')
        result = getattr(mod, parts.pop(0))
        for p in parts:
            result = getattr(result, p)
        return result

    try:
        sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])

        func = _resolve('%(module)s', '%(func)s')
        rc = func() # None interpreted as 0
    except Exception as e:  # only supporting Python >= 2.6
        sys.stderr.write('%%s\n' %% e)
        rc = 1
    sys.exit(rc)
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ÚenvÚ_executable© r   ú\C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_vendor\distlib\scripts.pyÚ_enquote_executableB   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)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   sz   || _ || _|| _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| _d S )NFÚposixÚjava)Ú z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__[   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_executablek   s
    z%ScriptMaker._get_alternate_executabler   c          	   C   sL   y"t |ƒ�}| d¡dkS Q R X W n$ ttfk
rF   t d|¡ dS X 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_shells   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)r@   r   ÚlangÚSystemÚgetPropertyÚlowerÚendswith)r)   r   r   r   r   r   Ú_fix_jython_executable   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|k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"   Ú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   s`  d}| j r| j }d}n^t ¡ s&tƒ }nNtƒ rLtj t d¡dt 	d¡ ¡}n(tj t 	d¡dt 	d¡t 	d¡f ¡}|r„|  
||¡}tj d	¡rš|  |¡}tj |¡}|r²t|ƒ}| d
¡}tjdkrÞd|krÞd|krÞ|d7 }|  ||¡}y| d
¡ W n" tk
�r   td| ƒ‚Y nX |d
k�r\y| |¡ W n& tk
�rZ   td||f ƒ‚Y nX |S )NTFÚscriptszpython%sÚEXEÚBINDIRz
python%s%sÚVERSIONr   z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!   r1   r3   Úget_pathÚget_config_varr7   rN   rO   r   rG   Únormcaser   ÚencoderU   ÚdecodeÚUnicodeDecodeErrorÚ
ValueError)r)   ÚencodingrP   r4   Úenquoter   Úshebangr   r   r   Ú_get_shebangª   sL    



zScriptMaker._get_shebangc             C   s   | j t|j|jd� S )N)ÚmoduleÚfunc)Úscript_templateÚdictÚprefixÚsuffix)r)   Úentryr   r   r   Ú_get_script_textâ   s    
zScriptMaker._get_script_textc             C   s   t j |¡}| j| S )N)r!   r1   ÚbasenameÚmanifest)r)   ÚexenameÚbaser   r   r   Úget_manifestè   s    zScriptMaker.get_manifestc             C   sð  | j o
| j}tj d¡}|s*|| | }n^|dkr>|  d¡}n
|  d¡}tƒ }	t|	dƒ�}
|
 d|¡ W d Q R X |	 	¡ }|| | | }�x`|D �]V}tj
 | j|¡}|�rrtj
 |¡\}}| d¡rÊ|}d| }y| j ||¡ W nŠ tk
�rn   t d¡ d	| }tj
 |¡�r t |¡ t ||¡ | j ||¡ t d
¡ yt |¡ W n tk
�rh   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�W d S )Nzutf-8ÚpyÚtÚwz__main__.pyz.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz%s.deletemez0Able to replace executable using .deleteme logicÚ.z%s.%szSkipping existing file %s)r   r(   r!   Úlinesepr`   Ú_get_launcherr   r   ÚwritestrÚgetvaluer1   r3   r   Úsplitextr   r'   Úwrite_binary_fileÚ	Exceptionr=   r>   ÚexistsÚremoveÚrenameÚdebugrF   r    r$   Úset_executable_modeÚappend)r)   Únamesrf   Úscript_bytesÚ	filenamesÚextÚuse_launcherry   ÚlauncherÚstreamÚzfÚzip_datar"   ÚoutnameÚnÚeÚdfnamer   r   r   Ú_write_scriptì   sT    




zScriptMaker._write_scriptc             C   sè   d}|r0|  dg ¡}|r0dd |¡ }| d¡}| jd||d�}|  |¡ d¡}|j}tƒ }	d| jkrp|	 |¡ d| jkr’|	 d	|t	j
d
 f ¡ d| jkr¸|	 d|t	j
d d… f ¡ |rÎ|  dd¡rÎd}
nd}
|  |	||||
¡ d S )NrV   Úinterpreter_argsz %sr   zutf-8)r4   r   ÚXz%s%sr   zX.Yz%s-%srH   r-   FÚpywru   )r0   r3   r`   rg   ro   r"   r%   r&   ÚaddrN   Úversionr“   )r)   rn   rˆ   r4   rP   Úargsrf   Ú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sT| j 	||¡sTt
 d|¡ d S yt|dƒ}W n  tk
r‚   | jsz‚ d }Y nLX | ¡ }|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�r^d}nd}t j |¡}|  |g||  ¡ ||¡ |�r”| ¡  d S )NFznot copying %s (up-to-date)Úrbz"%s: %s is an empty file (skipping)s   
rL   Tr   rV   zcopying and adjusting %s -> %sr   s   pythonwr–   ru   )!r!   r1   r3   r   r
   r   rp   r   r'   Únewerr=   rƒ   r9   r<   r*   Úreadliner>   Úget_command_nameÚFIRST_LINE_REÚmatchr2   ÚgroupÚcloseÚ	copy_filer$   r„   r…   Úinfor   Úseekrg   r“   r:   )r)   rš   rˆ   Úadjustr�   ÚfÚ
first_liner¢   rP   rd   Úlinesrf   r‰   r�   r   r   r   Ú_copy_script5  sR    



zScriptMaker._copy_scriptc             C   s   | j jS )N)r'   r*   )r)   r   r   r   r*   i  s    zScriptMaker.dry_runc             C   s   || j _d S )N)r'   r*   )r)   Úvaluer   r   r   r*   m  s    r   c             C   sH   t  d¡dkrd}nd}d||f }t dd¡d }t|ƒ |¡j}|S )	NÚPé   Ú64Ú32z%s%s.exerx   r   r   )ÚstructÚcalcsizeÚ__name__Úrsplitr   ÚfindÚbytes)r)   ÚkindÚbitsr"   Údistlib_packagerT   r   r   r   rz   u  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.
        N)r4   )r	   r¬   rœ   )r)   Úspecificationr4   rˆ   rn   r   r   r   Úmakeƒ  s    zScriptMaker.makec             C   s(   g }x|D ]}|  |  ||¡¡ q
W |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)   Úspecificationsr4   rˆ   r»   r   r   r   Úmake_multiple–  s    
zScriptMaker.make_multiple)TFN)rV   N)N)N)N) r´   Ú
__module__Ú__qualname__Ú__doc__ÚSCRIPT_TEMPLATErj   r   r,   r7   rN   rO   r   r@   rG   rU   rg   ro   Ú_DEFAULT_MANIFESTrq   rt   r“   rœ   r¬   Úpropertyr*   Úsetterr!   r"   r#   rz   r¼   r¿   r   r   r   r   r   R   s.    

82
4
r   )Úior   Úloggingr!   Úrer²   rN   Úcompatr   r   r   Ú	resourcesr   Úutilr   r	   r
   r   r   Ú	getLoggerr´   r=   ÚstriprÄ   Úcompiler¡   rÃ   r   Úobjectr   r   r   r   r   Ú<module>   s   

