o
    VÌhÅO  ã                   @  sº  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 erÔd dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d d l8m9Z9 d d!l*m:Z: d d"l;m<Z< G d#d$„ d$ƒZ=dS )%é    )ÚannotationsN)Úsuppress)ÚTYPE_CHECKING)Úcast)ÚCompletionsCommand)ÚHelpCommand)ÚListCommand)ÚConsoleCommandEvent)ÚConsoleErrorEvent)ÚCOMMAND)ÚERROR)Ú	TERMINATE)ÚConsoleTerminateEvent)ÚCleoCommandNotFoundError)Ú	CleoError)ÚCleoLogicError)ÚCleoNamespaceNotFoundError)ÚCleoUserError)ÚArgument)Ú	ArgvInput)Ú
Definition)ÚOption)ÚIO)Ú	Verbosity)ÚStreamOutput)ÚTerminal)ÚUI)ÚSolutionProviderRepository)ÚCommand)ÚEventDispatcher)ÚInput)ÚOutput)ÚCommandLoaderc                   @  sì  e Zd ZdZdd€d	d
„Zeddd„ƒZeddd„ƒZeddd„ƒZeddd„ƒZ	ed‚dd„ƒZ
edƒdd„ƒZeddd„ƒZed„dd„ƒZed…dd „ƒZd†d#d$„Zd‡d%d&„Zdˆd(d)„Zd‰d*d+„ZdŠd-d.„Zd‹d1d2„ZdŒdd6d7„ZdŽd8d9„ZdŽd:d;„ZdŒdd=d>„ZdŽd?d@„ZddCdD„Zd‘dHdI„Zd’dJdK„Zd“dLdM„Zd”dOdP„Zd•dRdS„Zd’dTdU„Z d–d—dYdZ„Z!	V	V	Vd˜d™dadb„Z"dšdedf„Z#d›dgdh„Z$	V	V	Vd˜dœdidj„Z%ddmdn„Z&dždodp„Z'ed‚dqdr„ƒZ(dŸdsdt„Z)d–d dwdx„Z*d„dydz„Z+d¡d{d|„Z,d¢d}d~„Z-dVS )£ÚApplicationzð
    An Application is the container for a collection of commands.

    This class is optimized for a standard CLI environment.

    Usage:
    >>> app = Application('myapp', '1.0 (stable)')
    >>> app.add(Command())
    >>> app.run()
    ÚconsoleÚ ÚnameÚstrÚversionÚreturnÚNonec                 C  sn   || _ || _d | _tƒ j| _d| _d| _i | _d | _	d| _
d | _d| _d| _d| _d | _d | _d | _d | _d S )NÚlistFT)Ú_nameÚ_versionÚ_display_namer   ÚsizeÚ	_terminalÚ_default_commandÚ_single_commandÚ	_commandsÚ_running_commandÚ_want_helpsÚ_definitionÚ_catch_exceptionsÚ
_auto_exitÚ_initializedÚ_uiÚ_event_dispatcherÚ_command_loaderÚ_solution_provider_repository)Úselfr&   r(   © r?   úd/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/cleo/application.pyÚ__init__<   s"   

zApplication.__init__c                 C  ó   | j S ©N©r,   ©r>   r?   r?   r@   r&   S   ó   zApplication.namec                 C  s$   | j d u rt dd| j¡ ¡ S | j S )Nz[\s\-_]+ú )r.   ÚreÚsubr,   ÚtitlerE   r?   r?   r@   Údisplay_nameW   s   
zApplication.display_namec                 C  rB   rC   ©r-   rE   r?   r?   r@   r(   ^   rF   zApplication.versionc                 C  s4   | j r| jrd| j› d| j› dS d| j› dS dS )Nz<b>z</b> (version <c1>z</c1>)z</b>z<b>Console</b> application)r,   r-   rK   rE   r?   r?   r@   Úlong_versionb   s
   zApplication.long_versionr   c                 C  s2   | j d u r	| j| _ | jr| j }| g ¡ |S | j S rC   )r6   Ú_default_definitionr2   Úset_arguments)r>   Ú
definitionr?   r?   r@   rP   l   s   

zApplication.definitionúlist[Command]c                 C  s   t ƒ tƒ tƒ gS rC   )r   r   r   rE   r?   r?   r@   Údefault_commandsy   s   zApplication.default_commandsc                 C  rB   rC   )rM   rE   r?   r?   r@   Úhelp}   rF   zApplication.helpr   c                 C  s   | j d u r
|  ¡ | _ | j S rC   )r:   Ú_get_default_uirE   r?   r?   r@   Úui   s   

zApplication.uiúEventDispatcher | Nonec                 C  rB   rC   ©r;   rE   r?   r?   r@   Úevent_dispatcherˆ   rF   zApplication.event_dispatcherrX   r   c                 C  ó
   || _ d S rC   rW   )r>   rX   r?   r?   r@   Úset_event_dispatcherŒ   ó   
z Application.set_event_dispatcherc                 C  rY   rC   rD   ©r>   r&   r?   r?   r@   Úset_name   r[   zApplication.set_namerK   c                 C  rY   rC   )r.   )r>   rK   r?   r?   r@   Úset_display_name’   r[   zApplication.set_display_namec                 C  rY   rC   rL   )r>   r(   r?   r?   r@   Úset_version•   r[   zApplication.set_versionrU   c                 C  rY   rC   )r:   )r>   rU   r?   r?   r@   Úset_ui˜   r[   zApplication.set_uiÚcommand_loaderr"   c                 C  rY   rC   )r<   )r>   ra   r?   r?   r@   Úset_command_loader›   r[   zApplication.set_command_loaderTÚ
auto_exitsÚboolc                 C  rY   rC   ©r8   )r>   rc   r?   r?   r@   rc   ž   r[   zApplication.auto_exitsc                 C  rB   rC   re   rE   r?   r?   r@   Úis_auto_exit_enabled¡   ó   z Application.is_auto_exit_enabledc                 C  rB   rC   ©r7   rE   r?   r?   r@   Úare_exceptions_caught¤   rg   z!Application.are_exceptions_caughtÚcatch_exceptionsc                 C  rY   rC   rh   )r>   rj   r?   r?   r@   rj   §   r[   zApplication.catch_exceptionsc                 C  rB   rC   )r2   rE   r?   r?   r@   Úis_single_commandª   rg   zApplication.is_single_commandÚsolution_provider_repositoryr   c                 C  rY   rC   )r=   )r>   rl   r?   r?   r@   Ú set_solution_provider_repository­   s   
z,Application.set_solution_provider_repositoryÚcommandr   úCommand | Nonec                 C  sd   |   ¡  | | ¡ |js| ¡  d S |jstd|jj› dƒ‚|| j|j< |jD ]}|| j|< q(|S )NzThe command "z" cannot have an empty name)	Ú_initÚset_applicationÚenabledr&   r   Ú	__class__Ú__name__r3   Úaliases)r>   rn   Úaliasr?   r?   r@   Úadd²   s   
ÿ
zApplication.addc                 C  sd   |   ¡  |  |¡st|ƒ‚|| jvrt|ƒ‚| j| }| jr0d| _tt|  d¡ƒ}| |¡ |S |S )NFrS   )	rp   Úhasr   r3   r5   r   r   ÚgetÚset_command)r>   r&   rn   Úhelp_commandr?   r?   r@   ry   È   s   



zApplication.getc                 C  sB   |   ¡  || jv rdS | jsdS t| j |¡o|  | j |¡¡ƒS )NTF)rp   r3   r<   rd   rx   rw   ry   r\   r?   r?   r@   rx   Þ   s   
ÿzApplication.hasú	list[str]c                 C  s˜   g }t ƒ }|  ¡  ¡ D ]>}|js|jsq|  |j¡D ]}||v r!q| |¡ | |¡ q|jD ]}|  |¡D ]}||v r=q6| |¡ | |¡ q6q/q|S rC   )	ÚsetÚallÚvaluesÚhiddenr&   Ú_extract_all_namespacesÚappendrw   ru   )r>   Ú
namespacesÚseenrn   Ú	namespacerv   r?   r?   r@   Úget_namespacesë   s&   


ûÿzApplication.get_namespacesr…   c                 C  s   |   ¡ }||vrt||ƒ‚|S rC   )r†   r   )r>   r…   Úall_namespacesr?   r?   r@   Úfind_namespace  s   
zApplication.find_namespacec                 C  sT   |   ¡  |  |¡r|  |¡S g }| jr|| jj7 }|dd„ | j ¡ D ƒ7 }t||ƒ‚)Nc                 S  s   g | ]	\}}|j s|‘qS r?   )r€   )Ú.0r&   rn   r?   r?   r@   Ú
<listcomp>  s
    
ÿÿz$Application.find.<locals>.<listcomp>)rp   rx   ry   r<   Únamesr3   Úitemsr   )r>   r&   Úall_commandsr?   r?   r@   Úfind  s   

ÿ
zApplication.findNú
str | Noneúdict[str, Command]c                 C  sâ   |   ¡  |d u r+| j ¡ }| js|S | jjD ]}||vr(|  |¡r(|  |¡||< q|S i }| j ¡ D ]\}}||  || 	d¡d ¡krG|||< q2| jro| jjD ]}||vrn||  || 	d¡d ¡krn|  |¡rn|  |¡||< qO|S )NrG   é   )
rp   r3   Úcopyr<   r‹   rx   ry   rŒ   Úextract_namespaceÚcount)r>   r…   Úcommandsr&   rn   r?   r?   r@   r~     s0   
€€ÿ€zApplication.allÚinputúInput | NoneÚoutputúOutput | NoneÚerror_outputÚintc              
   C  sÊ   zO|   |||¡}|  |¡ z|  |¡}W n9 ty0   t tjtj¡}t |t	j
 ¡ ¡ d}Y n tyM } z| js;‚ |  ||¡ d}W Y d }~nd }~ww W n tyZ   d}Y nw | jrct	 |¡ |S )Nr   r‘   )Ú	create_ioÚ_configure_ioÚ_runÚBrokenPipeErrorÚosÚopenÚdevnullÚO_WRONLYÚdup2ÚsysÚstdoutÚfilenoÚ	Exceptionr7   Úrender_errorÚKeyboardInterruptr8   Úexit)r>   r–   r˜   rš   ÚioÚ	exit_coder¢   Úer?   r?   r@   Úrun;  s.   
€ú€ÿ
zApplication.runr¬   r   c                 C  s@  |j  ddgd¡r| | j¡ dS | j}tƒ }|jD ]}|jdkr-tddd| 	d¡j
d}| |¡ q| |j¡ ttƒ |j  |¡ W d   ƒ n1 sNw   Y  |  |¡}|j  ddgd¡rt|sqd	}| td
d	| jgƒ¡ nd| _|s˜| j}| j}|j}| d¡s“| tdd| 	d¡j
|d¡ | |¡ d | _|  |¡}|| _d|v rt|j tƒr|j jd d … }|j jd urÅ| d|j j¡ | d¡d }	d }
t |ƒD ]\}}||	kræ|dkræ|||< |}
 nqÒ|
d urù||
d |
d | !d¡ …= |j j"}|j  #¡ }| t|ƒ¡ |j  $|¡ |j  %|¡ |  &||¡}d | _|S )Nú	--versionú-VTr   rn   )ÚrequiredÚis_listÚdescriptionú--helpú-hrS   r$   F)r²   r´   ÚdefaultrG   r‘   )'r–   Úhas_parameter_optionÚ
write_linerM   rP   r   Ú	argumentsr&   r   Úargumentr´   Úadd_argumentÚset_optionsÚoptionsr   r   ÚbindÚ_get_command_nameÚ	set_inputr   r1   r5   Úhas_argumentr‚   rO   r4   rŽ   Ú
isinstanceÚ_tokensÚscript_nameÚinsertÚsplitÚ	enumerater”   ÚstreamÚis_interactiveÚ
set_streamÚinteractiveÚ_run_command)r>   r¬   rP   Úinput_definitionr»   r&   rº   rn   Úargvr…   ÚindexÚiÚargrÉ   rÌ   r­   r?   r?   r@   rž   ^  s~   


ü
ý


üÿ

€
zApplication._runc           	   
   C  s   | j d u r
| |¡S z| ¡  |j |j¡ W n	 ty    Y nw t||ƒ}d }z| j  |t	¡ | 
¡ r:| |¡}ntj}W n+ tyi } zt|||ƒ}| j  |t¡ |j}|j}|dkr_d }W Y d }~nd }~ww t|||ƒ}| j  |t¡ |d ur}|‚|jS )Nr   )r;   r¯   Úmerge_application_definitionr–   r¿   rP   r   r	   Údispatchr   Úcommand_should_runÚRETURN_CODE_DISABLEDr¨   r
   r   Úerrorr­   r   r   )	r>   rn   r¬   Úcommand_eventr×   r­   r®   Úerror_eventÚterminate_eventr?   r?   r@   rÍ   ´  s<   

ý
€€ù	zApplication._run_commandc                 C  sJ   |d u rt ƒ }| tj¡ |d u rttjƒ}|d u rttjƒ}t|||ƒS rC   )r   rË   r¥   Ústdinr   r¦   Ústderrr   )r>   r–   r˜   rš   r?   r?   r@   rœ   Ý  s   

zApplication.create_ior×   r¨   c                 C  s@   ddl m} ||| jd}| ¡  pt|tƒ}| |j|¡ d S )Nr   )ÚExceptionTrace)rl   )Úcleo.ui.exception_tracerÝ   r=   Ú
is_verboserÃ   r   Úrenderrš   )r>   r×   r¬   rÝ   ÚtraceÚsimpler?   r?   r@   r©   ï  s   ÿzApplication.render_errorc                 C  s†  |j  dd¡r| d¡ n|j  dd¡r| d¡ |j  ddgd¡s2|j jd u r7|j jr7|j j ¡ s7| d¡ tt 	dd¡ƒ}|d	krJ| 
tj¡ n#|d
krU| 
tj¡ n|dkr`| 
tj¡ n|dkrk| 
tj¡ nd}|j  ddgd¡r| 
tj¡ d	}n7|j  dd¡r| 
tj¡ d}n'|j  dd¡rŸ| 
tj¡ d}n|j  dd¡s®|j jdddr¶| 
tj¡ d
}|d	krÁ| d¡ d S d S )Nú--ansiTú	--no-ansiFú--no-interactionú-nÚSHELL_VERBOSITYr   éÿÿÿÿr‘   é   é   ú--quietú-qz-vvvz-vvz-vú	--verbose)Úonly_params)r–   r¸   Ú	decoratedÚ_interactiverÉ   ÚisattyrÌ   r›   r    ÚgetenvÚset_verbosityr   ÚQUIETÚVERBOSEÚVERY_VERBOSEÚDEBUG)r>   r¬   Úshell_verbosityr?   r?   r@   r   ø  sP   
ÿ
þ
ÿþÿzApplication._configure_ioc                 C  s|   t tddddtdddd| j› dd	td
dddd	tddddd	tddddd	tdddd	tdddd	tddddd	gƒS )Nrn   TzThe command to execute.)r²   r´   rµ   r¶   zXDisplay help for the given command. When no command is given display help for the <info>z</info> command.)Úflagr´   rë   rì   zDo not output any message.rí   z	-v|vv|vvvzcIncrease the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.r°   r±   z!Display this application version.rã   zForce ANSI output.rä   zDisable ANSI output.rå   ræ   z$Do not ask any interactive question.)r   r   r   r1   rE   r?   r?   r@   rN   $  sN   ýþû
ÿû
üüÛÿzApplication._default_definitionc                 C  sˆ   | j r| jS d|jjv r@|j d¡r@g }|j d¡D ]}|r*| |d d | ¡ q| |¡ qt|ƒD ]}|  |¡r?|  S q4|jjS )Nrn   rè   rG   )	r2   r1   r–   rº   r»   r‚   Úreversedrx   Úfirst_argument)r>   r¬   Ú
candidatesÚcommand_partÚ	candidater?   r?   r@   rÀ   U  s   
ÿzApplication._get_command_nameÚlimitú
int | Nonec                 C  s$   |  d¡d d… }d |d |… ¡S ©NrG   rè   )rÇ   Újoin)r>   r&   rÿ   Úpartsr?   r?   r@   r“   g  s   zApplication.extract_namespacec                 C  s"   ddl m} |  ¡ }t||ƒgƒS )Nr   )ÚProgressBar)Úcleo.ui.progress_barr  rœ   r   )r>   r  r¬   r?   r?   r@   rT   k  s   zApplication._get_default_uic                 C  sB   |  d¡d d… }g }|D ]}| |r|d d | n|¡ q|S r  )rÇ   r‚   )r>   r&   r  rƒ   Úpartr?   r?   r@   r   q  s
    z#Application._extract_all_namespacesc                 C  s*   | j rd S d| _ | jD ]}|  |¡ qd S )NT)r9   rR   rw   )r>   rn   r?   r?   r@   rp   z  s   
ÿzApplication._init)r$   r%   )r&   r'   r(   r'   r)   r*   )r)   r'   )r)   r   )r)   rQ   )r)   r   )r)   rV   )rX   r   r)   r*   )r&   r'   r)   r*   )rK   r'   r)   r*   )r(   r'   r)   r*   )rU   r   r)   r*   )ra   r"   r)   r*   )T)rc   rd   r)   r*   )r)   rd   )rj   rd   r)   r*   )rl   r   r)   r*   )rn   r   r)   ro   )r&   r'   r)   r   )r&   r'   r)   rd   )r)   r|   )r…   r'   r)   r'   rC   )r…   r   r)   r   )NNN)r–   r—   r˜   r™   rš   r™   r)   r›   )r¬   r   r)   r›   )rn   r   r¬   r   r)   r›   )r–   r—   r˜   r™   rš   r™   r)   r   )r×   r¨   r¬   r   r)   r*   )r¬   r   r)   r*   )r¬   r   r)   r   )r&   r'   rÿ   r   r)   r'   )r&   r'   r)   r|   )r)   r*   ).rt   Ú
__module__Ú__qualname__Ú__doc__rA   Úpropertyr&   rK   r(   rM   rP   rR   rS   rU   rX   rZ   r]   r^   r_   r`   rb   rc   rf   ri   rj   rk   rm   rw   ry   rx   r†   rˆ   rŽ   r~   r¯   rž   rÍ   rœ   r©   r   rN   rÀ   r“   rT   r   rp   r?   r?   r?   r@   r#   0   sv    	















!ü
#
V+ü

	,
0

	r#   )>Ú
__future__r   r    rH   r¥   Ú
contextlibr   Útypingr   r   Ú!cleo.commands.completions_commandr   Úcleo.commands.help_commandr   Úcleo.commands.list_commandr   Ú!cleo.events.console_command_eventr	   Úcleo.events.console_error_eventr
   Úcleo.events.console_eventsr   r   r   Ú#cleo.events.console_terminate_eventr   Úcleo.exceptionsr   r   r   r   r   Úcleo.io.inputs.argumentr   Úcleo.io.inputs.argv_inputr   Úcleo.io.inputs.definitionr   Úcleo.io.inputs.optionr   Ú
cleo.io.ior   Úcleo.io.outputs.outputr   Úcleo.io.outputs.stream_outputr   Úcleo.terminalr   Ú
cleo.ui.uir   Ú9crashtest.solution_providers.solution_provider_repositoryr   Úcleo.commands.commandr   Úcleo.events.event_dispatcherr   Úcleo.io.inputs.inputr    r!   Úcleo.loaders.command_loaderr"   r#   r?   r?   r?   r@   Ú<module>   sL    