o
    5‘ðiï+  ã                   @  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   úR/root/parts/websockify/install/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; 