o
    Uh                  	   @   s   U d 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	m
Z
 ddlmZ er7ddlmZ ed Zed Zd	d
gZdddddddddZee
d ef ed< dZdedefddZdededefddZG dd	 d	eZG dd
 d
ZdS ) z2Generate executable scripts, on various platforms.    N)read_binary)TYPE_CHECKINGMappingOptionalTuple)_scripts)Literal)posixwin-ia32	win-amd64win-arm	win-arm64)consoleguiInvalidScriptScriptzt32.exezt64.exez	t_arm.exezt64-arm.exezw32.exezw64.exez	w_arm.exezw64-arm.exe))r   r
   )r   r   )r   r   )r   r   )r   r
   )r   r   )r   r   )r   r   )ScriptSectionLauncherKind_ALLOWED_LAUNCHERSz# -*- coding: utf-8 -*-
import re
import sys
from {module} import {import_name}
if __name__ == "__main__":
    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit({func_path}())

executablereturnc                 C   s    d| v rdS t | d }|dkS )N    F      )len)r   shebang_length r   e/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/installer/scripts.py_is_executable_simple+   s   r   forlauncherc                 C   sF   |  d}|rd| S t|rd| S t|  d}d| d d S )a  Build a shebang line.

    The non-launcher cases are taken directly from distlib's implementation,
    which tries its best to account for command length, spaces in path, etc.

    https://bitbucket.org/pypa/distlib/src/58cd5c6/distlib/scripts.py#lines-124
    utf-8s   #!s   #!/bin/sh
'''exec' s    "$0" "$@"
s   ' ''')encoder   shlexquote)r   r   executable_bytesquotedr   r   r   _build_shebang5   s   
r&   c                   @   s   e Zd ZdZdS )r   z=Raised if the user provides incorrect script section or kind.N)__name__
__module____qualname____doc__r   r   r   r   r   N   s    c                
   @   st   e Zd ZdZdZdedededddd	f
d
dZdefddZdddee	 fddZ
dedddeee	f fddZd	S )r   z7Describes a script based on an entry point declaration.namemoduleattrsectionr,   r-   r.   r/   r   r   Nc                 C   s   || _ || _|| _|| _dS )ax  Construct a Script object.

        :param name: name of the script
        :param module: module path, to load the entry point from
        :param attr: final attribute access, for the entry point
        :param section: Denotes the "entry point section" where this was specified.
            Valid values are ``"gui"`` and ``"console"``.
        :type section: str

        Nr+   )selfr,   r-   r.   r/   r   r   r   __init__W   s   
zScript.__init__c                 C   s   d | j| j| jS )Nz(Script(name={!r}, module={!r}, attr={!r})formatr,   r-   r.   )r0   r   r   r   __repr__i   s
   zScript.__repr__kindr   c                 C   sV   |dkrd S | j |f}zt| }W n ty%   |dtt}t|w tt|S )Nr	   z not in )r/   r   KeyErrorsortedr   r   r   )r0   r4   keyr,   errorr   r   r   _get_launcher_datap   s   

zScript._get_launcher_datar   c           
      C   s   |  |}t|t|d}tj| j| jdd | jdd}|du r-| j	|d | fS t
 }t|d}|d	| W d   n1 sHw   Y  | j	 d
}|| d |  }	||	fS )a  Generate a launcher for this script.

        :param executable: Path to the executable to invoke.
        :param kind: Which launcher template should be used.
            Valid values are ``"posix"``, ``"win-ia32"``, ``"win-amd64"`` and
            ``"win-arm"``.
        :type kind: str

        :raises InvalidScript: if no appropriate template is available.
        :return: The name and contents of the launcher file.
        )r   .r   )r-   import_name	func_pathr    N   
wz__main__.pyz.exe)r9   r&   bool_SCRIPT_TEMPLATEr2   r-   r.   splitr!   r,   ioBytesIOzipfileZipFilewritestrgetvalue)
r0   r   r4   launchershebangcodestreamzfr,   datar   r   r   generate{   s$   
zScript.generate)r'   r(   r)   r*   	__slots__strr1   r3   r   bytesr9   r   rN   r   r   r   r   r   R   s"    
")r*   rB   r"   rD   importlib.resourcesr   typingr   r   r   r   	installerr   r   r   r   __all__r   rP   __annotations__r@   rQ   r?   r   r&   
ValueErrorr   r   r   r   r   r   <module>   s4    
