
вEbc           @   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 e 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-UPPWic/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 |  _ t j |  _ 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_ntt   syst   version_info(   t   selfR   R   R   t   dry_runt   fileop(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   __init__N   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-UPPWic/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-UPPWic/pip/pip/_vendor/distlib/scripts.pyt	   _is_shellg   s    c         C   s^   |  j  |  r= d d  l } | j j j d  d k rV | Sn | j   j d  rV | Sd | S(   Nis   os.namet   Linuxs
   jython.exes   /usr/bin/env %s(   R=   R   t   langt   Systemt   getPropertyt   lowert   endswith(   R'   R   R   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   _fix_jython_executables   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   lenR%   t   platform(   R'   R   t   post_interpt   simple_shebangt   shebang_lengtht   max_shebang_lengtht   result(    (    s8   /tmp/pip-build-UPPWic/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  | r t |  } n  | j d  } t j d	 k rAd
 | k rAd | k rA| 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)(   RF   R   R   R   t   is_python_buildR   R	   R   R/   R1   t   get_patht   get_config_varR5   R%   RH   R   RD   R   t   encodeRN   t   decodet   UnicodeDecodeErrort
   ValueError(   R'   t   encodingRI   R2   t   enquoteR   t   shebang(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   _get_shebang   sJ    					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-UPPWic/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-UPPWic/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   RC   t   _get_launcherR    R   t   writestrt   getvalueR/   R1   R   t   splitextR   R#   t   write_binary_filet	   ExceptionR:   R;   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-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   _write_script   sX    		

	c         C   s[  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 | |  j	 d	 f  n  d
 |  j k r|	 j d | |  j	 d	 |  j	 d f  n  | r8| j  d t
  r8d }
 n d }
 |  j |	 | | | |
  d  S(   NR   t   interpreter_argss    %sR
   s   utf-8R2   t   Xs   %s%si    s   X.Ys   %s-%s.%si   R+   t   pywRn   (   R.   R1   RW   R^   Rh   R   R!   R"   t   addR&   R   R   (   R'   Rg   R   R2   RI   t   argsR]   t   scriptR   t   scriptnamesR   (    (    s8   /tmp/pip-build-UPPWic/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/   R1   R   R   R   Ri   R   R#   t   newerR:   R{   R6   R9   R(   t   Nonet   readlineR;   t   get_command_namet   FIRST_LINE_REt   matchR0   RF   t   groupt   closet	   copy_fileR    R|   R}   t   infoR   t   seekR^   R   R7   (   R'   R   R   t   adjustR   t   ft
   first_lineR   RI   R[   t   linesR]   R   R   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   _copy_script5  sR    $ 	
		
	%c         C   s
   |  j  j S(   N(   R#   R(   (   R'   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyR(   i  s    c         C   s   | |  j  _ d  S(   N(   R#   R(   (   R'   t   value(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyR(   m  s    R   c         C   s   t  j d  d k r d } n d } d | | f } t j d d  d } t |  j |  } | s d	 | | f } t |   n  | j S(
   Nt   Pi   t   64t   32s   %s%s.exeRa   i   i    s(   Unable to find resource %s in package %s(   t   structt   calcsizet   __name__t   rsplitR   t   findRZ   t   bytes(   R'   t   kindt   bitsR   t   distlib_packaget   resourcet   msg(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyRr   u  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.
        R2   N(   R   R   R   R   (   R'   t   specificationR2   R   Rg   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   make  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   specificationsR2   R   R   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   make_multiple  s    N("   R   t
   __module__t   __doc__t   SCRIPT_TEMPLATERc   R   R   RF   R   R*   R5   R%   RH   R   R=   RD   RN   R^   Rh   t   _DEFAULT_MANIFESTRj   Rm   R   R   R   t   propertyR(   t   setterR   R   R   Rr   R   R   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyR   E   s.   			@			4	4-(   t   ioR    t   loggingR   t   reR   R%   t   compatR   R   R   t	   resourcesR   t   utilR   R   R   R   R	   t	   getLoggerR   R:   t   stripR   t   compileR   R   R   t   _enquote_executablet   objectR   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/distlib/scripts.pyt   <module>   s   (	