o
    LK&h+                     @  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Zd dl	Z	d dl
mZ d dlmZmZ ddlmZmZ erDd dlmZ ddlmZ d d	lmZ d d
lmZ G dd deddZG dd deZG dd deZG dd dZG dd deZG dd deZ dd Z!dd Z"dd Z#dd  Z$d!d" Z%dS )#    )annotationsN)Iterable)TYPE_CHECKING	TypedDict   )metadata	resources)Self)SetuptoolsWarning)first_line_re)get_platformc                   @  s   e Zd ZU ded< ded< dS )
_SplitArgsboolcommentsposixN)__name__
__module____qualname____annotations__ r   r   F/var/www/html/venv/lib/python3.10/site-packages/setuptools/_scripts.pyr      s   
 r   F)totalc                   @  s   e Zd ZU dZg Zded< e Zedd Z	edd Z
ed ddZedd Zed!ddZd"ddZedd Zdd Zedd Zedd ZdS )#CommandSpeczm
    A command spec for a #! header, specified as a list of arguments akin to
    those passed to Popen.
    z	list[str]optionsc                 C  s   | S )zV
        Choose the best CommandSpec class based on environmental conditions.
        r   clsr   r   r   best'   s   zCommandSpec.bestc                 C  s   t jtj}t jd|S )N__PYVENV_LAUNCHER__)ospathnormpathsys
executableenvironget)r   _defaultr   r   r   _sys_executable.   s   zCommandSpec._sys_executableparam!Self | str | Iterable[str] | Nonereturnr	   c                 C  sV   t || r|S t |tr| |S t |tr| |S |du r"|  S tdt| )zg
        Construct a CommandSpec from a parameter to build_scripts, which may
        be None.
        Nz!Argument has an unsupported type )
isinstancestrfrom_stringr   from_environment	TypeErrortype)r   r'   r   r   r   
from_param3   s   



zCommandSpec.from_paramc                 C  s   | |   gS N)r&   r   r   r   r   r-   C   s   zCommandSpec.from_environmentstringr+   c                 C  s   t j|fi | j}| |S )z}
        Construct a command spec from a simple string representing a command
        line parseable by shlex.split.
        )shlexsplit
split_args)r   r2   itemsr   r   r   r,   G   s   zCommandSpec.from_stringscript_textc                 C  s<   t | || _t| }t|sdg| jd d< d S d S )Nz-xr   )r3   r4   _extract_optionsr   
subprocesslist2cmdlineisascii)selfr7   cmdliner   r   r   install_optionsP   s
   
zCommandSpec.install_optionsc                 C  s:   | d   d }t |}|r|dpdnd}| S )zH
        Extract any options from the first line of the script.
        
r   r    )
splitlines_first_line_rematchgroupstrip)orig_scriptfirstrC   r   r   r   r   r8   V   s    zCommandSpec._extract_optionsc                 C  s   |  | t| j S r1   )_renderlistr   )r<   r   r   r   	as_header`   s   zCommandSpec.as_headerc                 C  s6   d}|D ]}|  |r| |r| dd   S q| S )Nz"'r   )
startswithendswith)item_QUOTESqr   r   r   _strip_quotesc   s   zCommandSpec._strip_quotesc                 C  s    t dd | D }d| d S )Nc                 s  s    | ]
}t | V  qd S r1   )r   rQ   rE   ).0rN   r   r   r   	<genexpr>m   s    
z&CommandSpec._render.<locals>.<genexpr>z#!r?   )r9   r:   )r6   r=   r   r   r   rH   k   s   
zCommandSpec._renderN)r'   r(   r)   r	   )r2   r+   r)   r	   )r7   r+   )r   r   r   __doc__r   r   r   r5   classmethodr   r&   r0   r-   r,   r>   staticmethodr8   rJ   rQ   rH   r   r   r   r   r      s,   
 




	
r   c                   @  s   e Zd ZeddZdS )WindowsCommandSpecF)r   N)r   r   r   r   r5   r   r   r   r   rW   s   s    rW   c                   @  sh   e Zd ZdZed ZeZ	e
dddZedd Ze
dd	 Ze
d
d Ze
		ddddZdS )ScriptWriterz`
    Encapsulates behavior around writing entry point scripts for console and
    gui apps.
    aJ  
        # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
        import re
        import sys

        # for compatibility with easy_install; see #2198
        __requires__ = %(spec)r

        try:
            from importlib.metadata import distribution
        except ImportError:
            try:
                from importlib_metadata import distribution
            except ImportError:
                from pkg_resources import load_entry_point


        def importlib_load_entry_point(spec, group, name):
            dist_name, _, _ = spec.partition('==')
            matches = (
                entry_point
                for entry_point in distribution(dist_name).entry_points
                if entry_point.group == group and entry_point.name == name
            )
            return next(matches).load()


        globals().setdefault('load_entry_point', importlib_load_entry_point)


        if __name__ == '__main__':
            sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
            sys.exit(load_entry_point(%(spec)r, %(group)r, %(name)r)())
        Nc           
      c  s    t |dstd tj|j}|du r|  }|j d|j	 }dD ].}| d}|j
j|dD ]}|j}| |j | jt  }| ||j||}	|	E dH  q3q%dS )z
        Yield write_script() argument tuples for a distribution's
        console_scripts and gui_scripts entry points.
        entry_pointsz%Unsupported distribution encountered.Nz==consolegui_scripts)rD   )hasattrr
   emitr   Distributionategg_info
get_headernameversionrY   select_ensure_safe_nametemplatelocals_get_script_args)
r   distheaderspectype_rD   eprd   r7   argsr   r   r   get_args   s"   
	

zScriptWriter.get_argsc                 C  s   t d| }|rtddS )z?
        Prevent paths in *_scripts entry point names.
        z[\\/]z+Path separators not allowed in script namesN)research
ValueError)rd   has_path_sepr   r   r   rg      s   zScriptWriter._ensure_safe_namec                 C  s*   t jdkstjdkrtjdkrt S | S )zD
        Select the best ScriptWriter for this environment.
        win32javant)r!   platformr   rd   _nameWindowsScriptWriterr   r   r   r   r   r      s   zScriptWriter.bestc                 c  s    ||| fV  d S r1   r   )r   rn   rd   rl   r7   r   r   r   rj      s   zScriptWriter._get_script_argsr@   r7   r+   r"   (str | CommandSpec | Iterable[str] | Noner)   c                 C  s"   | j  |}|| | S )z;Create a #! line, getting options (if any) from script_text)command_spec_classr   r0   r>   rJ   )r   r7   r"   cmdr   r   r   rc      s   
zScriptWriter.get_headerr1   )r@   N)r7   r+   r"   r|   r)   r+   )r   r   r   rT   textwrapdedentlstriprh   r   r}   rU   rq   rV   rg   r   rj   rc   r   r   r   r   rX   w   s(    #%

	
rX   c                   @  s@   e Zd ZeZedd Zedd Zedd Ze	dd Z
d	S )
r{   c                 C  s"   t t| d}tjdd}|| S )zC
        Select the best ScriptWriter suitable for Windows
        )r"   naturalSETUPTOOLS_LAUNCHERr"   )dictWindowsExecutableLauncherWriterr   r#   r$   )r   writer_lookuplauncherr   r   r   r      s   zWindowsScriptWriter.bestc           	      #  s    t ddd| }|tjd  dvr#djdi t }t| g d}|	| | 
||} fdd	|D } | || d
|fV  dS )z For Windows, add a .py extension.pya.pywrZ   PATHEXT;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.)r   .py
-script.py.pyc.pyor   .exec                      g | ]} | qS r   r   rR   xrd   r   r   
<listcomp>       z8WindowsScriptWriter._get_script_args.<locals>.<listcomp>tNr   )r   r   r#   lowerr4   formatri   r
   r_   remove_adjust_header)	r   rn   rd   rl   r7   extmsgoldblockersr   r   r   rj      s   

z$WindowsScriptWriter._get_script_argsc                 C  sN   d}d}|dkr||}}t t |t j}|j||d}| |r%|S |S )z
        Make sure 'pythonw' is used for gui and 'python' is used for
        console (regardless of what sys.executable is).
        zpythonw.exez
python.exer\   )r2   repl)rr   compileescape
IGNORECASEsub_use_header)r   rn   orig_headerpatternr   
pattern_ob
new_headerr   r   r   r     s   
z"WindowsScriptWriter._adjust_headerc                 C  s&   | dd  d}tjdkpt|S )z
        Should _adjust_header use the replaced header?

        On non-windows systems, always use. On
        Windows systems, only use the replaced header if it resolves
        to an executable on the system.
           rK   "rv   )rE   r!   ry   shutilwhich)r   clean_headerr   r   r   r     s   	zWindowsScriptWriter._use_headerN)r   r   r   rW   r}   rU   r   rj   r   rV   r   r   r   r   r   r{      s    


r{   c                   @  s   e Zd Zedd ZdS )r   c                 #  s    |dkrd}d}dg}nd}d}g d}|  ||} fdd|D }	 | || d	|	fV   d
 t|dfV  t sJ d }
|
t d	fV  dS dS )zG
        For Windows, add a .py extension and an .exe launcher
        r\   z-script.pywr   clir   )r   r   r   c                   r   r   r   r   r   r   r   r   +  r   zDWindowsExecutableLauncherWriter._get_script_args.<locals>.<listcomp>r   r   bz.exe.manifestN)r   get_win_launcheris_64bitload_launcher_manifest)r   rn   rd   rl   r7   launcher_typer   r   hdrr   m_namer   r   r   rj     s&   z0WindowsExecutableLauncherWriter._get_script_argsN)r   r   r   rU   rj   r   r   r   r   r     s    r   c                 C  sV   |  d}t  rt dkr|dd}n|dd}n|dd}td| S )z
    Load the Windows launcher (executable) suitable for launching a script.

    `type` should be either 'cli' or 'gui'

    Returns the executable as a byte string.
    r   z	win-arm64.z-arm64.z-64.z-32.
setuptools)r   r   replacer   filesjoinpath
read_bytes)r/   launcher_fnr   r   r   r   <  s   

r   c                 C  s"   t td}|jddt  S )Nzlauncher manifest.xmlzutf-8)encoding)r   r   r   r   	read_textvars)rd   resr   r   r   r   O  s   r   c                   C  s    t tjtrtS ttj S )z_
    Return a regular expression based on first_line_re suitable for matching
    strings.
    )r*   r   r   r+   rr   r   decoder   r   r   r   rB   T  s   rB   c                   C  s   t ddkS )NP   )structcalcsizer   r   r   r   r   `  s   r   c                 C  s&   z|  d W dS  ty   Y dS w )NasciiFT)encodeUnicodeError)sr   r   r   r;   d  s   r;   )&
__future__r   r   rr   r3   r   r   r9   r!   r   collections.abcr   typingr   r   
_importlibr   r   typing_extensionsr	   warningsr
   distutils.command.build_scriptsr   distutils.utilr   r   rI   r   rW   rX   r{   r   r   r   rB   r   r;   r   r   r   r   <module>   s8    Uj; 