o
    ›¨ÊhM!  ã                   @   sÀ  d 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	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 zddlmZ ddlmZ ddlmZ W n eyo   dd„ ZdZdZY nw eƒ Zeƒ ZG dd„ dƒZ dd„ Z!G dd„ de	j"ƒZ#G dd„ de	j$ƒZ%G dd„ de%ƒZ&G dd„ de
ƒZ'G dd„ de
ƒZ(G d d!„ d!e
ƒZ)G d"d#„ d#e
ƒZ*G d$d%„ d%e
ƒZ+G d&d'„ d'e	j,ƒZ-e(ƒ Z.e)ƒ Z/e*ƒ Z0e+ƒ Z1e-ƒ Z2e'ƒ Z3dS )(z Click customizations for Celery.é    N)ÚOrderedDict©Úupdate_wrapper)Úpformat)Ú	ParamType)Úcached_property)Úget_current_app)Úuser_preload_options)Útext)Úmlevel)Úmaybe_iso8601)Ú	highlight)ÚTerminal256Formatter)ÚPythonLexerc                 O   s   | S )z2Place holder function in case pygments is missing.© )ÚsÚargsÚkwargsr   r   úA/var/www/html/env/lib/python3.10/site-packages/celery/bin/base.pyr      s   r   c                   @   s|   e Zd ZdZddd„Zedd„ ƒZedd„ ƒZdd
d„Zddd„Z	ddd„Z
ddd„Zdd„ Zdd„ Zdd„ Zddd„Zd	S )Ú
CLIContextzContext Object for the CLI.Fc                 C   s"   |pt ƒ | _|| _|| _|| _dS )zInitialize the CLI context.N)r   ÚappÚno_colorÚquietÚworkdir)Úselfr   r   r   r   r   r   r   Ú__init__$   s   
zCLIContext.__init__c                 C   ó   | j dddd�S )NÚOKÚgreenT©ÚfgÚbold©Ústyle©r   r   r   r   r   +   ó   zCLIContext.OKc                 C   r   )NÚERRORÚredTr   r"   r$   r   r   r   r&   /   r%   zCLIContext.ERRORNc                 K   s   | j r|S tj|fi |¤ŽS ©N)r   Úclickr#   ©r   Úmessager   r   r   r   r#   3   s   zCLIContext.stylec                 K   s:   | j rd|d< tj|fi |¤Ž d S tj|fi |¤Ž d S ©NFÚcolor©r   r)   ÚechoÚsechor*   r   r   r   r0   9   ó   zCLIContext.sechoc                 K   s:   | j rd|d< tj|fi |¤Ž d S tj|fi |¤Ž d S r,   )r   r)   r/   r*   r   r   r   r/   @   r1   zCLIContext.echoc                 K   sB   d|d< | j rd|d< tj|fi |¤Ž d S tj|fi |¤Ž d S )NTÚerrFr-   r.   r*   r   r   r   ÚerrorG   s
   zCLIContext.errorc                 C   sŒ   t |tƒr| j|  |¡fS t |tƒr5d|v sd|v r|  |¡S tj|ddd�}| js0t	|t
tƒ}| j|fS t |tƒr?| j|fS | jt|ƒfS )NÚokr3   Té   )Ú	sort_keysÚindent)Ú
isinstanceÚlistr   Úpretty_listÚdictÚpretty_dict_ok_errorÚjsonÚdumpsr   r   ÚLEXERÚ	FORMATTERÚstrr   )r   Únr   r   r   r   ÚprettyO   s   





zCLIContext.prettyc                    s    |sdS d  ‡ fdd„|D ƒ¡S )Nz	- empty -Ú
c                 3   s(   � | ]}ˆ j d dd�› d|› �V  qdS )Ú*Úwhite)r    ú Nr"   )Ú.0Úitemr$   r   r   Ú	<genexpr>a   s   € 
ÿz)CLIContext.pretty_list.<locals>.<genexpr>)Újoin©r   rB   r   r$   r   r:   ^   s
   ÿzCLIContext.pretty_listc                 C   sV   z| j t |  |d ¡d d¡fW S  ty   Y nw | jt |  |d ¡d d¡fS )Nr4   é   r5   r3   )r   r
   r7   rC   ÚKeyErrorr&   rL   r   r   r   r<   e   s   ÿÿÿzCLIContext.pretty_dict_ok_errorÚ c                 C   sf   |dkr	| j r	d S | j  r| j|ddd�› d�pd}|  |› d|› �¡ |r/|r1|  |¡ d S d S d S )Nz<-rF   Tr   rG   rO   )r   r#   r/   )r   Ú	directionÚtitleÚbodyÚ	show_bodyÚdirstrr   r   r   Úsay_chatn   s   "ÿzCLIContext.say_chat)Fr(   )rO   F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r#   r0   r/   r3   rC   r:   r<   rU   r   r   r   r   r   !   s    






	r   c                    s   ‡ fdd„}t |ˆ ƒS )z6Extract preload options and return a wrapped callable.c                    s\   | j j}dd„ |j dg ¡D ƒ}|r#‡ fdd„|D ƒ}tjˆ||d� ˆ| g|¢R i ˆ ¤ŽS )Nc                 S   s   g | ]}|j ‘qS r   )Úname)rH   Úor   r   r   Ú
<listcomp>|   s    z:handle_preload_options.<locals>.caller.<locals>.<listcomp>Úpreloadc                    s   i | ]}|ˆ | “qS r   r   )rH   Úpreload_option©r   r   r   Ú
<dictcomp>   s    ÿÿz:handle_preload_options.<locals>.caller.<locals>.<dictcomp>)Úsenderr   Úoptions)Úobjr   Úuser_optionsÚgetr	   Úsend)Úctxr   r   r   Úpreload_optionsrd   ©Úfr_   r   Úcallery   s   
þz&handle_preload_options.<locals>.callerr   )rj   rk   r   ri   r   Úhandle_preload_optionsw   s   
rl   c                       ó,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚCeleryOptionzCustomized option for Celery.c                    s.   | j r
|j| j  | _tƒ j|g|¢R i |¤ŽS r(   )Údefault_value_from_contextrc   ÚdefaultÚsuperÚget_default)r   rg   r   r   ©Ú	__class__r   r   rr   Ž   s   zCeleryOption.get_defaultc                    s2   |  dd¡| _|  dd¡| _tƒ j|i |¤Ž dS )zInitialize a Celery option.Ú
help_groupNro   )Úpopru   ro   rq   r   ©r   r   r   rs   r   r   r   “   s   zCeleryOption.__init__)rV   rW   rX   rY   rr   r   Ú__classcell__r   r   rs   r   rn   ‹   s    rn   c                   @   s   e Zd ZdZdd„ ZdS )ÚCeleryCommandzCustomized command for Celery.c              	   C   s®   t ƒ }|  |¡D ])}| |¡}|dur1t|dƒr(|jr(| t|jƒg ¡ |¡ q| dg ¡ |¡ q| ¡ D ]\}}| 	|¡� | 
|¡ W d  ƒ n1 sOw   Y  q6dS )z7Write all the options into the formatter if they exist.Nru   ÚOptions)r   Ú
get_paramsÚget_help_recordÚhasattrru   Ú
setdefaultrA   ÚappendÚitemsÚsectionÚwrite_dl)r   rg   Ú	formatterÚoptsÚparamÚrvrZ   Ú
opts_groupr   r   r   Úformat_options�   s   
€ÿ€ÿzCeleryCommand.format_optionsN)rV   rW   rX   rY   rˆ   r   r   r   r   ry   š   s    ry   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚCeleryDaemonCommandzDaemon commands.c                    s�   t ƒ j|i |¤Ž | j tdddd�¡ | j tddd�¡ | j tddd�¡ | j tddd�¡ | j td	dd�¡ | j td
dd�¡ dS )z7Initialize a Celery command with common daemon options.)z-fz	--logfilezDaemonization Optionsz#Log destination; defaults to stderr)ru   Úhelp)z	--pidfile)ru   )z--uid)z--gid)z--umask)z--executableN)rq   r   Úparamsr   rn   rw   rs   r   r   r   °   s   ÿzCeleryDaemonCommand.__init__)rV   rW   rX   rY   r   rx   r   r   rs   r   r‰   ­   s    r‰   c                   @   ó   e Zd ZdZdZdd„ ZdS )ÚCommaSeparatedListzComma separated list argument.zcomma separated listc                 C   s
   t  |¡S r(   )r
   Ústr_to_list©r   Úvaluer…   rg   r   r   r   ÚconvertÁ   s   
zCommaSeparatedList.convertN©rV   rW   rX   rY   rZ   r‘   r   r   r   r   r�   ¼   ó    r�   c                   @   rŒ   )Ú	JsonArrayzJSON formatted array argument.z
json arrayc              
   C   ón   t |tƒr|S zt |¡}W n ty' } z|  t|ƒ¡ W Y d }~nd }~ww t |tƒs5|  |› d�¡ |S )Nz was not an array)r8   r9   r=   ÚloadsÚ
ValueErrorÚfailrA   ©r   r�   r…   rg   ÚvÚer   r   r   r‘   Ê   ó   
€ÿ
zJsonArray.convertNr’   r   r   r   r   r”   Å   r“   r”   c                   @   rŒ   )Ú
JsonObjectzJSON formatted object argument.zjson objectc              
   C   r•   )Nz was not an object)r8   r;   r=   r–   r—   r˜   rA   r™   r   r   r   r‘   Þ   rœ   zJsonObject.convertNr’   r   r   r   r   r�   Ù   r“   r�   c                   @   rŒ   )ÚISO8601DateTimezISO 8601 Date Time argument.z	iso-86091c              
   C   s@   zt |ƒW S  ttfy } z|  |¡ W Y d }~d S d }~ww r(   )r   Ú	TypeErrorr—   r˜   ©r   r�   r…   rg   r›   r   r   r   r‘   ò   s   
€ÿzISO8601DateTime.convertNr’   r   r   r   r   rž   í   r“   rž   c                   @   rŒ   )ÚISO8601DateTimeOrFloatz%ISO 8601 Date Time or float argument.ziso-86091 or floatc              
   C   sb   zt |ƒW S  ttfy   Y nw zt|ƒW S  ttfy0 } z|  |¡ W Y d }~d S d }~ww r(   )ÚfloatrŸ   r—   r   r˜   r    r   r   r   r‘   þ   s   
ÿ
€ÿzISO8601DateTimeOrFloat.convertNr’   r   r   r   r   r¡   ù   r“   r¡   c                       rm   )ÚLogLevelzLog level option.c                    s   t ƒ  d¡ dS )z:Initialize the log level option with the relevant choices.)ÚDEBUGÚINFOÚWARNINGr&   ÚCRITICALÚFATALN)rq   r   r$   rs   r   r   r     r%   zLogLevel.__init__c                    s0   t |tjƒr|S | ¡ }tƒ  |||¡}t|ƒS r(   )r8   ÚnumbersÚIntegralÚupperrq   r‘   r   r�   rs   r   r   r‘     s
   zLogLevel.convert)rV   rW   rX   rY   r   r‘   rx   r   r   rs   r   r£   
  s    r£   )4rY   r=   r©   Úcollectionsr   Ú	functoolsr   Úpprintr   r)   r   Úkombu.utils.objectsr   Úcelery._stater   Úcelery.signalsr	   Úcelery.utilsr
   Úcelery.utils.logr   Úcelery.utils.timer   Úpygmentsr   Úpygments.formattersr   Úpygments.lexersr   ÚImportErrorr?   r@   r   rl   ÚOptionrn   ÚCommandry   r‰   r�   r”   r�   rž   r¡   ÚChoicer£   Ú
JSON_ARRAYÚJSON_OBJECTÚISO8601ÚISO8601_OR_FLOATÚ	LOG_LEVELÚCOMMA_SEPARATED_LISTr   r   r   r   Ú<module>   sT    ûV	
