ó
ä™L]c           @   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 j e ƒ Z d j ƒ  Z e j d ƒ Z d	 Z d
 „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   BytesIONi   (   t	   sysconfigt   detect_encodingt   ZipFile(   t   finder(   t   FileOperatort   get_export_entryt   convert_patht   get_executablet   in_venvsñ  
<?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.]*([ 	].*)?$sÍ   # -*- 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   sˆ   d |  k r„ |  j  d ƒ re |  j d d ƒ \ } } d | k r� | j  d ƒ r� d | | f }  q� q„ |  j  d ƒ s„ d |  }  q„ n  |  S(   Nt    s   /usr/bin/env i   t   "s   %s "%s"s   "%s"(   t
   startswitht   split(   t
   executablet   envt   _executable(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _enquote_executable3   s    t   ScriptMakerc           B   s  e  Z d  Z e Z d Z e e d d „ Z	 d „  Z
 e j j d ƒ rZ d „  Z d „  Z n  d „  Z d d d „ Z d	 „  Z e Z d
 „  Z d „  Z d d „ Z d „  Z e d „  ƒ Z e j d „  ƒ Z e j d k sö e j d k re j d k rd „  Z n  d d „ Z  d d „ Z! RS(   s_   
    A class to copy or create scripts from source scripts or callable
    specifications.
    c         C   sµ   | |  _  | |  _ | |  _ t |  _ t |  _ t j d k pW t j d k oW t j d k |  _	 t
 d ƒ |  _ | p{ t | ƒ |  _ t j d k p« t j d k o« t j d k |  _ d  S(   Nt   posixt   javat    s   X.Yt   nt(   R   s   X.Y(   t
   source_dirt
   target_dirt   add_launcherst   Falset   forcet   clobbert   ost   namet   _namet   set_modet   sett   variantsR   t   _fileopt   _is_nt(   t   selfR   R   R   t   dry_runt   fileop(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   __init__L   s    					c         C   sa   | j  d t ƒ r] |  j r] t j j | ƒ \ } } | j d d ƒ } t j j | | ƒ } n  | S(   Nt   guit   pythont   pythonw(   t   getR   R$   R   t   pathR   t   replacet   join(   R%   R   t   optionst   dnt   fn(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _get_alternate_executable\   s
    R   c         C   s[   y, t  | ƒ � } | j d ƒ d k SWd QXWn( t t f k
 rV t j d | ƒ t SXd S(   sl   
            Determine if the specified executable is a script
            (contains a #! line)
            i   s   #!Ns   Failed to open %s(   t   opent   readt   OSErrort   IOErrort   loggert   warningR   (   R%   R   t   fp(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt	   _is_shelld   s    c         C   s^   |  j  | ƒ r= d d  l } | j j j d ƒ d k rV | Sn | j ƒ  j d ƒ rV | Sd | S(   Niÿÿÿÿs   os.namet   Linuxs
   jython.exes   /usr/bin/env %s(   R;   R   t   langt   Systemt   getPropertyt   lowert   endswith(   R%   R   R   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _fix_jython_executablep   s    c         C   s­   t  j d k r t } nP t | ƒ t | ƒ d } t j d k rJ d } n d } d | k oe | | k } | rƒ d | | d } n& d	 } | d
 | | d 7} | d 7} | S(   s  
        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   i   t   darwini   i   R
   s   #!s   
s
   #!/bin/sh
s	   '''exec' s    "$0" "$@"
s   ' '''(   R   R   t   Truet   lent   syst   platform(   R%   R   t   post_interpt   simple_shebangt   shebang_lengtht   max_shebang_lengtht   result(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _build_shebang|   s    		
R   c         C   sè  t  } |  j r! |  j } t } n‰ t j ƒ  s9 t ƒ  } nq t ƒ  rp t j j	 t j
 d ƒ d t j d ƒ ƒ } n: t j j	 t j d ƒ d t j d ƒ t j d ƒ f ƒ } | rÅ |  j | | ƒ } n  t j j d ƒ ré |  j | ƒ } n  t j j | ƒ } | rt | ƒ } n  | j d ƒ } t j d	 k rSd
 | k rSd | k rS| d 7} n  |  j | | ƒ } y | j d ƒ Wn! t k
 r™t d | ƒ ‚ n X| d k räy | j | ƒ Wqät k
 ràt d | | f ƒ ‚ qäXn  | S(   Nt   scriptss   python%st   EXEt   BINDIRs
   python%s%st   VERSIONR   s   utf-8t   clis	   -X:Framess   -X:FullFramess
    -X:Framess,   The shebang (%r) is not decodable from utf-8s?   The shebang (%r) is not decodable from the script encoding (%r)(   RD   R   R   R   t   is_python_buildR   R	   R   R-   R/   t   get_patht   get_config_varR3   RF   RG   R   RB   t   normcaseR   t   encodeRM   t   decodet   UnicodeDecodeErrort
   ValueError(   R%   t   encodingRH   R0   t   enquoteR   t   shebang(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _get_shebang›   sL    					c         C   s6   |  j  t d | j d | j j d ƒ d d | j ƒ S(   Nt   modulet   import_namet   .i    t   func(   t   script_templatet   dictt   prefixt   suffixR   (   R%   t   entry(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _get_script_textÓ   s    c         C   s   t  j j | ƒ } |  j | S(   N(   R   R-   t   basenamet   manifest(   R%   t   exenamet   base(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   get_manifestÚ   s    c         C   s•  |  j  o |  j } t j j d ƒ } | j | ƒ s@ | | 7} n  | sS | | } nx | d k rq |  j d ƒ } n |  j d ƒ } t ƒ  }	 t |	 d ƒ � }
 |
 j	 d | ƒ Wd  QX|	 j
 ƒ  } | | | } xÃ| D]»} t j j |  j | ƒ } | rìt j j | ƒ \ } } | j d ƒ r&| } n  d | } y |  j j | | ƒ Wq€t k
 rèt j d ƒ d	 | } t j j | ƒ r�t j | ƒ n  t j | | ƒ |  j j | | ƒ t j d
 ƒ y t j | ƒ Wqét k
 räqéXq€Xn” |  j r| j d | ƒ rd | | f } n  t j j | ƒ rN|  j rNt j d | ƒ qÒ n  |  j j | | ƒ |  j r€|  j j | g ƒ n  | j | ƒ qÒ Wd  S(   Ns   utf-8t   pyt   tt   ws   __main__.pys   .pys   %s.exes:   Failed to write executable - trying to use .deleteme logics   %s.deletemes0   Able to replace executable using .deleteme logicRa   s   %s.%ss   Skipping existing file %s(   R   R$   R   t   linesepRW   RA   t   _get_launcherR    R   t   writestrt   getvalueR-   R/   R   t   splitextR   R#   t   write_binary_filet	   ExceptionR8   R9   t   existst   removet   renamet   debugR   R    t   set_executable_modet   append(   R%   t   namesR]   t   script_bytest	   filenamest   extt   use_launcherRq   t   launchert   streamt   zft   zip_dataR   t   outnamet   nt   et   dfname(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _write_scriptÞ   sX    		

	c         C   sQ  d } | rL | j  d g  ƒ } | rL d d j | ƒ } | j d ƒ } qL n  |  j d | d | ƒ} |  j | ƒ j d ƒ } | j } t ƒ  }	 d |  j k r­ |	 j | ƒ n  d |  j k rÝ |	 j d | t	 j
 d	 f ƒ n  d
 |  j k r|	 j d | t	 j
 d  f ƒ n  | r.| j  d t ƒ r.d }
 n d }
 |  j |	 | | | |
 ƒ d  S(   NR   t   interpreter_argss    %sR
   s   utf-8R0   t   Xs   %s%si    s   X.Ys   %s-%si   R)   t   pywRn   (   R,   R/   RW   R^   Rh   R   R!   R"   t   addRF   t   versionR   R‹   (   R%   Rg   R€   R0   RH   t   argsR]   t   scriptR   t   scriptnamesR�   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _make_script  s(    		!!	c         C   s@  t  } t j j |  j t | ƒ ƒ } t j j |  j t j j | ƒ ƒ } |  j r| |  j	 j
 | | ƒ r| t j d | ƒ d  Sy t | d ƒ } Wn& t k
 r· |  j s® ‚  n  d  } no X| j ƒ  } | sç t j d |  j ƒ  | ƒ d  St j | j d d ƒ ƒ } | r&t } | j d ƒ p d } n  | s�| r?| j ƒ  n  |  j	 j | | ƒ |  j rq|  j	 j | g ƒ n  | j | ƒ n» t j d | |  j ƒ |  j	 j s)t | j ƒ \ }	 }
 | j  d	 ƒ |  j! |	 | ƒ } d
 | k rìd } n d } t j j | ƒ } |  j" | g | | j# ƒ  | | ƒ n  | r<| j ƒ  n  d  S(   Ns   not copying %s (up-to-date)t   rbs"   %s: %s is an empty file (skipping)s   
s   
i   R   s   copying and adjusting %s -> %si    R+   RŽ   Rn   ($   R   R   R-   R/   R   R   R   Ri   R   R#   t   newerR8   R{   R4   R7   R&   t   Nonet   readlineR9   t   get_command_namet   FIRST_LINE_REt   matchR.   RD   t   groupt   closet	   copy_fileR    R|   R}   t   infoR   t   seekR^   R‹   R5   (   R%   R’   R€   t   adjustR‡   t   ft
   first_lineR›   RH   R[   t   linesR]   R�   Rˆ   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   _copy_script)  sR    $ 	
		
	%c         C   s
   |  j  j S(   N(   R#   R&   (   R%   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyR&   ]  s    c         C   s   | |  j  _ d  S(   N(   R#   R&   (   R%   t   value(    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyR&   a  s    R   c         C   sf   t  j d ƒ d k r d } n d } d | | f } t j d d ƒ d } t | ƒ j | ƒ j } | S(	   Nt   Pi   t   64t   32s   %s%s.exeRa   i   i    (   t   structt   calcsizet   __name__t   rsplitR   t   findt   bytes(   R%   t   kindt   bitsR   t   distlib_packageRL   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyRr   i  s    	c         C   sK   g  } t  | ƒ } | d k r1 |  j | | ƒ n |  j | | d | ƒ| S(   sÓ  
        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.
        R0   N(   R   R—   R¥   R”   (   R%   t   specificationR0   R€   Rg   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   makew  s    c         C   s4   g  } x' | D] } | j  |  j | | ƒ ƒ q W| S(   sÂ   
        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,
        (   t   extendR´   (   R%   t   specificationsR0   R€   R³   (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   make_multipleŠ  s    N("   R¬   t
   __module__t   __doc__t   SCRIPT_TEMPLATERc   R—   R   RD   R   R(   R3   RF   RG   R   R;   RB   RM   R^   Rh   t   _DEFAULT_MANIFESTRj   Rm   R‹   R”   R¥   t   propertyR&   t   setterR   R   R   Rr   R´   R·   (    (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyR   C   s.   			8			4	4-(   t   ioR    t   loggingR   t   reRª   RF   t   compatR   R   R   t	   resourcesR   t   utilR   R   R   R   R	   t	   getLoggerR¬   R8   t   stripR»   t   compileRš   Rº   R   t   objectR   (    (    (    s8   /tmp/pip-build-sZz8gW/pip/pip/_vendor/distlib/scripts.pyt   <module>   s   (	