U
    ,eF                     @   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Zd dlm	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mZ eeZd Zed	Zd
Zdd ZeZ G dd de!Z"dS )    )BytesION)ZipInfo   )	sysconfigdetect_encodingZipFile)finder)FileOperatorget_export_entryconvert_pathget_executableget_platform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   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envZ_executable r   \/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pip/_vendor/distlib/scripts.pyenquote_executable5   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Zdd Zd,ddZdd Zed d! Zejd"d! Zejd#ksejd	krejd#krd$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   s   || _ || _|| _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| _tj| _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sysversion_info)selfr   r   r    dry_runZfileopr   r   r   __init__P   s    

zScriptMaker.__init__c                 C   s@   | ddr<| jr<tj|\}}|dd}tj||}|S )NguiFpythonZpythonw)getr*   r#   pathr   replacejoin)r-   r   optionsdnfnr   r   r   _get_alternate_executablea   s
    z%ScriptMaker._get_alternate_executabler   c              
   C   s\   z0t |}|ddkW  5 Q R  W S Q R X W n& ttfk
rV   td| Y dS X dS )zl
            Determine if the specified executable is a script
            (contains a #! line)
               z#!zFailed to open %sFN)openreadOSErrorIOErrorloggerwarning)r-   r   fpr   r   r   	_is_shelli   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)rB   r   langSystemgetPropertylowerendswith)r-   r   r   r   r   r   _fix_jython_executableu   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$   lenr+   platform)r-   r   post_interpZsimple_shebangZshebang_lengthZmax_shebang_lengthresultr   r   r   _build_shebang   s    

zScriptMaker._build_shebang    c                 C   s~  d}| j r| j }d}nt s&t }nxt rLtjtddt	d }nRtjt	ddt	dt	df }tj
|stjt	ddt	d }|r| ||}tjd	r| |}|rt|}|d
}tjdkrd|krd|kr|d7 }| ||}z|d
 W n" tk
r8   td| Y nX |d
krzz|| W n& tk
rx   td||f Y nX |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#   r3   r5   get_pathget_config_varisfiler9   r+   rP   r   rI   r   encoderS   decodeUnicodeDecodeError
ValueError)r-   encodingrQ   r6   Zenquoter   shebangr   r   r   _get_shebang   s`    





zScriptMaker._get_shebangc                 C   s$   | j t|j|jdd |jd S )N.r   )moduleZ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#   r3   basenamemanifest)r-   exenamebaser   r   r   get_manifest   s    zScriptMaker.get_manifestc                 C   s6  | j o
| j}tjd}||s*||7 }|s8|| }n|dkrL| d}n
| d}t }	t|	dR}
tj	
d}|rtt|d d }td|d}|
|| n|
d| W 5 Q R X |	 }|| | }|D ]X}tj| j|}|rtj|\}}|d	r|}d
| }z| j|| W n tk
r   td d| }tj|rht| t|| | j|| td zt| W n tk
r   Y nX Y nX nl| jr|d| sd||f }tj|r| jstd| q| j|| | j r&| j!|g |"| qd S )NrY   pytwSOURCE_DATE_EPOCH   z__main__.py)filename	date_timez.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz%s.deletemez0Able to replace executable using .deleteme logicrf   z%s.%szSkipping existing file %s)#r    r*   r#   linesepr_   rH   _get_launcherr   r   environr2   timegmtimeintr   writestrgetvaluer3   r5   r   splitextr   r)   Zwrite_binary_file	Exceptionr?   r@   existsremoverenamedebugr"   r&   set_executable_modeappend)r-   namesrd   Zscript_bytes	filenamesextZuse_launcherr|   ZlauncherstreamzfZsource_date_epochr{   zinfoZzip_datar$   outnameneZdfnamer   r   r   _write_script   sb    






zScriptMaker._write_script-c                 C   sn   t  }d| jkr|| d| jkr<|d|| jd f  d| jkrj|d|| j| jd | jd f  |S )Nr   Xz%s%sr   r   z	%s%s%s.%sr   )r'   r(   addr,   variant_separator)r-   r$   rR   r   r   r   get_script_filenames,  s    



 z ScriptMaker.get_script_filenamesc           
      C   s   d}|r0| dg }|r0dd| }|d}| jd||d}| |d}| |j}|rr| ddrrd	}	nd
}	| |||||	 d S )NrT   Zinterpreter_argsz %sr   rY   r6   r0   Fpywru   )r2   r5   r_   re   rn   r   r$   r   )
r-   rm   r   r6   rQ   argsrd   scriptZscriptnamesr   r   r   r   _make_script7  s    
zScriptMaker._make_scriptc                 C   s  d}t j| jt|}t j| jt j|}| jsT| j	||sTt
d| d S zt|d}W n  tk
r   | jsz d }Y nFX | }|st
d| d S t|dd}|rd}|dpd	}|s|r|  | j|| | jr| j|g || nt
d
|| j | jjs~t|j\}	}
|d | |	|}d|krVd}nd}t j|}| |g|| || |r|  d S )NFznot copying %s (up-to-date)rbz%s is an empty file (skipping)s   
rN   Tr   rT   zcopying and adjusting %s -> %sr   s   pythonwr   ru   ) r#   r3   r5   r   r   r   rp   r!   r)   newerr?   r   r;   r>   r.   readliner@   FIRST_LINE_REmatchr4   groupclose	copy_filer&   r   r   infor   seekre   r   r<   )r-   r   r   Zadjustr   f
first_liner   rQ   rc   linesrd   r   r   r   r   r   _copy_scriptG  sR    



zScriptMaker._copy_scriptc                 C   s   | j jS ro   r)   r.   )r-   r   r   r   r.   z  s    zScriptMaker.dry_runc                 C   s   || j _d S ro   r   )r-   valuer   r   r   r.   ~  s    r   c                 C   st   t ddkrd}nd}t dkr&dnd}d|||f }td	d
d }t||}|snd||f }t||jS )NP   Z64Z32z	win-arm64z-armr   z
%s%s%s.exerf   r   r   z(Unable to find resource %s in package %s)	structcalcsizer   __name__rsplitr   findrb   bytes)r-   kindbitsZplatform_suffixr$   Zdistlib_packageresourcemsgr   r   r   r}     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.
        Nr   )r
   r   r   )r-   specificationr6   r   rm   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-   Zspecificationsr6   r   r   r   r   r   make_multiple  s    zScriptMaker.make_multiple)TFN)rT   N)N)N)N)"r   
__module____qualname____doc__SCRIPT_TEMPLATEri   r   r/   r9   r+   rP   r   rB   rI   rS   re   rn   _DEFAULT_MANIFESTrq   rt   r   r   r   r   r   propertyr.   setterr#   r$   r%   r}   r   r   r   r   r   r   r   G   s:       

E:
3


r   )#ior   loggingr#   rer   r+   r   zipfiler   compatr   r   r   	resourcesr   utilr	   r
   r   r   r   r   	getLoggerr   r?   stripr   compiler   r   r   Z_enquote_executableobjectr   r   r   r   r   <module>   s"    


