\e[c@sddlmZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZmZmZmZmZejeZdjZejdZd Zd Zd efd YZdS( i(tBytesIONi(t sysconfigtdetect_encodingtZipFile(tfinder(t FileOperatortget_export_entryt convert_pathtget_executabletin_venvs s^#!.*pythonw?[0-9.]*([ ].*)?$s|# -*- 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) cCsd|kr|jdre|jdd\}}d|kr|jd rd||f}qq|jdsd|}qn|S(Nt s /usr/bin/env it"s%s "%s"s"%s"(t startswithtsplit(t executabletenvt _executable((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt_enquote_executableBs t ScriptMakercBseZdZeZdZeeddZ dZ e j j drZdZdZndZdddZd ZeZd Zd Zdd Zd ZedZejdZejdksejdkrejdkrdZnddZ ddZ!RS(s_ A class to copy or create scripts from source scripts or callable specifications. cCs||_||_||_t|_t|_tjdkpWtjdkoWtjdk|_ t d|_ |p{t ||_ tjdkptjdkotjdk|_dS(NtposixtjavatsX.Ytnt(RsX.Y(t source_dirt target_dirt add_launcherstFalsetforcetclobbertostnamet_nametset_modetsettvariantsRt_fileopt_is_nt(tselfRRRtdry_runtfileop((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt__init__[s     cCsa|jdtr]|jr]tjj|\}}|jdd}tjj||}n|S(Ntguitpythontpythonw(tgetRR$RtpathR treplacetjoin(R%Rtoptionstdntfn((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt_get_alternate_executableks RcCs[y,t|}|jddkSWdQXWn(ttfk rVtjd|tSXdS(sl Determine if the specified executable is a script (contains a #! line) is#!NsFailed to open %s(topentreadtOSErrortIOErrortloggertwarningR(R%Rtfp((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt _is_shellss cCs^|j|r=ddl}|jjjddkrV|Sn|jjdrV|Sd|S(Nisos.nametLinuxs jython.exes/usr/bin/env %s(R;RtlangtSystemt getPropertytlowertendswith(R%RR((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt_fix_jython_executables cCstjdkrt}nPt|t|d}tjdkrJd}nd}d|koe||k}|rd||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 RitdarwiniiR s#!s s #!/bin/sh s '''exec' s "$0" "$@" s' '''(RRtTruetlentsystplatform(R%Rt post_interptsimple_shebangtshebang_lengthtmax_shebang_lengthtresult((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt_build_shebangs      RcCst}|jr!|j}t}ntjs9t}nqtrptjj tj ddtj d}n:tjj tj ddtj dtj df}|r|j ||}nt jjdr|j|}ntjj|}|rt|}n|jd}t jd krSd |krSd |krS|d 7}n|j||}y|jdWn!tk rtd |nX|dkry|j|Wqtk rtd||fqXn|S(Ntscriptsspython%stEXEtBINDIRs python%s%stVERSIONRsutf-8tclis -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)(RDRRRtis_python_buildRR RR-R/tget_pathtget_config_varR3RFRGR RBtnormcaseRtencodeRMtdecodetUnicodeDecodeErrort ValueError(R%tencodingRHR0tenquoteRtshebang((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt _get_shebangsL             cCs |jtd|jd|jS(Ntmoduletfunc(tscript_templatetdicttprefixtsuffix(R%tentry((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt_get_script_textscCstjj|}|j|S(N(RR-tbasenametmanifest(R%texenametbase((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt get_manifestscCs|jo|j}tjjd}|s;|||}n||dkrY|jd}n|jd}t} t| d} | jd|WdQX| j } |||| }x|D]} tj j |j | } |rtj j | \}}|jdr|} nd| } y|jj| |Wqltk rtjdd | }tj j|r|tj|ntj| ||jj| |tjd ytj|Wqtk rqXqlXn|jr| jd | rd | |f} ntj j| r:|j r:tjd | qn|jj| ||jrl|jj| gn|j| qWdS(Nsutf-8tpytttws __main__.pys.pys%s.exes:Failed to write executable - trying to use .deleteme logics %s.deletemes0Able to replace executable using .deleteme logict.s%s.%ssSkipping existing file %s(RR$RtlinesepRWt _get_launcherRRtwritestrtgetvalueR-R/RtsplitextR R#twrite_binary_filet ExceptionR8R9texiststremovetrenametdebugRARR tset_executable_modetappend(R%tnamesR]t script_bytest filenamestextt use_launcherRptlaunchertstreamtzftzip_dataRtoutnametntetdfname((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt _write_scriptsT             c CsQd}|rL|jdg}|rLddj|}|jd}qLn|jd|d|}|j|jd}|j}t} d|jkr| j|nd|jkr| jd|t j d fnd |jkr | jd |t j d fn|r.|jd t r.d} nd} |j | |||| dS(NRtinterpreter_argss %sR sutf-8R0tXs%s%sisX.Ys%s-%siR)tpywRl( R,R/RWR^RfRR!R"taddRFtversionRR( R%ReRR0RHtargsR]tscriptRt scriptnamesR((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt _make_scripts(  !! cCs@t}tjj|jt|}tjj|jtjj|}|j r||j j || r|t j d|dSyt |d}Wn&tk r|jsnd}noX|j}|st jd|j|dStj|jdd}|r&t}|jdp d}n|s|r?|jn|j j|||jrq|j j|gn|j|nt jd||j|j js)t|j\} } |j d |j!| |} d |krd } nd } tjj|} |j"| g| |j#|| n|r<|jndS( Nsnot copying %s (up-to-date)trbs"%s: %s is an empty file (skipping)s s iRscopying and adjusting %s -> %siR+RRl($RRR-R/RRRRgRR#tnewerR8RzR4R7R&tNonetreadlineR9tget_command_namet FIRST_LINE_REtmatchR.RDtgrouptcloset copy_fileR R{R|tinfoRtseekR^RR5(R%RRtadjustRtft first_lineRRHR[tlinesR]RR((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt _copy_script5sR$              %cCs |jjS(N(R#R&(R%((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyR&iscCs||j_dS(N(R#R&(R%tvalue((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyR&msRcCsftjddkrd}nd}d||f}tjddd}t|j|j}|S( NtPit64t32s%s%s.exeRoii(tstructtcalcsizet__name__trsplitRtfindtbytes(R%tkindtbitsRtdistlib_packageRL((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyRqus cCsKg}t|}|dkr1|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. R0N(RRRR(R%t specificationR0RRe((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pytmakes   cCs4g}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, (textendR(R%tspecificationsR0RR((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyt make_multiples N("Rt __module__t__doc__tSCRIPT_TEMPLATERaRRRDRR(R3RFRGR R;RBRMR^Rft_DEFAULT_MANIFESTRhRkRRRtpropertyR&tsetterRRRRqRR(((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyRRs.  8   2  4-  (tioRtloggingRtreRRFtcompatRRRt resourcesRtutilRRRRR t getLoggerRR8tstripRtcompileRRRtobjectR(((s:/tmp/pip-install-0xiv62/pip/pip/_vendor/distlib/scripts.pyts     (