o
    wvXj  ã                   @   s\   d Z ddlmZmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ G dd„ de	ƒZdS )	z3The ``celery shell`` program, used to start a REPL.é    )Úabsolute_importÚunicode_literalsN)Úimport_module)ÚCommand)Úvaluesc                   @   sx   e Zd ZdZdd„ Zdd„ Z			ddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Úshella?  Start shell session with convenient access to celery symbols.

    The following symbols will be added to the main globals:

        - ``celery``:  the current application.
        - ``chord``, ``group``, ``chain``, ``chunks``,
          ``xmap``, ``xstarmap`` ``subtask``, ``Task``
        - all registered tasks.
    c                 C   s€   |  d¡}|jdddddd� |jdd	dd
dd� |jddddd� |jdddddd� |jddddd� |jddddd� d S )NzShell Optionsz	--ipythonz-IÚ
store_truezforce iPython.F)ÚactionÚhelpÚdefaultz	--bpythonz-Bzforce bpython.z--pythonzforce default Python shell.)r	   r   r
   z--without-tasksz-Tzdon't add tasks to locals.z
--eventletzuse eventlet.z--geventzuse gevent.)Úadd_argument_groupÚadd_argument)ÚselfÚparserÚgroup© r   úM/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/bin/shell.pyÚadd_arguments   s8   
þþýýý
þzshell.add_argumentsc                 O   s$   |r
|   d |¡¡‚| jdi |¤ŽS )Nz*shell command does not take arguments: {0}r   )Ú
UsageErrorÚformatÚ_run)r   ÚargsÚkwargsr   r   r   Úrun5   s
   ÿz	shell.runFc           	      K   sÈ   t j dt ¡ ¡ |rtdƒ |rtdƒ dd l}dd l}| jj	 
¡  | j| j|j|j|j|j|j|j|j|j|jdœ| _|sN| j dd„ t| jjƒD ƒ¡ |rT|  ¡ S |rZ|  ¡ S |r`|  ¡ S |  ¡ S )Nr   zcelery.concurrency.eventletzcelery.concurrency.gevent)ÚappÚceleryÚTaskÚchordr   ÚchainÚchunksÚxmapÚxstarmapÚsubtaskÚ	signaturec                 S   s    i | ]}|j  d ¡s|j|“qS )zcelery.)ÚnameÚ
startswithÚ__name__)Ú.0Útaskr   r   r   Ú
<dictcomp>W   s    
þÿzshell._run.<locals>.<dictcomp>)ÚsysÚpathÚinsertÚosÚgetcwdr   r   Úcelery.task.baser   ÚloaderÚimport_default_modulesr   r   r   r   r   r    r!   r"   r#   ÚlocalsÚupdater   ÚtasksÚinvoke_fallback_shellÚinvoke_bpython_shellÚinvoke_ipython_shellÚinvoke_default_shell)	r   ÚipythonÚbpythonÚpythonÚwithout_tasksÚeventletÚgeventr   r   r   r   r   r   ;   s>   õ
ÿz
shell._runc                 C   sZ   z	dd l }W |  ¡ S  ty,   zdd l}W n ty%   |  ¡  Y  Y S w |  ¡  Y S w ©Nr   )ÚIPythonÚImportErrorr:   r5   r6   r7   )r   r@   r:   r   r   r   r8   d   s   
	øÿúzshell.invoke_default_shellc                 C   s`   dd l }zdd l}W n	 ty   Y nw dd l}| | | j¡j¡ | d¡ |j	| jd� d S )Nr   ztab:complete)Úlocal)
ÚcodeÚreadlinerA   ÚrlcompleterÚset_completerÚ	Completerr2   ÚcompleteÚparse_and_bindÚinteract)r   rC   rD   rE   r   r   r   r5   q   s   ÿÿ
zshell.invoke_fallback_shellc              	   C   s@   | j | j| j| j| jfD ]}z|ƒ W   S  ty   Y qw d S )N)Ú_ipythonÚ_ipython_pre_10Ú_ipython_terminalÚ_ipython_010Ú_no_ipythonrA   )r   Úipr   r   r   r7   ~   s   þÿûzshell.invoke_ipython_shellc                 C   s   ddl m} |g | jd� d S )Nr   )Ústart_ipython©ÚargvÚuser_ns)r@   rQ   r2   )r   rQ   r   r   r   rK   ‡   s   zshell._ipythonc                 C   s<   ddl m} | ¡ }|jg d� |jj | j¡ | ¡  d S )Nr   )ÚTerminalIPythonApp)rS   )	ÚIPython.frontend.terminal.ipapprU   ÚinstanceÚ
initializer   rT   r3   r2   Ústart)r   rU   r   r   r   r   rL   ‹   s
   zshell._ipython_pre_10c                 C   s"   ddl m} |j| jd� ¡  d S )Nr   )Úembed)rT   )ÚIPython.terminalrZ   ÚTerminalInteractiveShellr2   Úmainloop)r   rZ   r   r   r   rM   ’   ó   zshell._ipython_terminalc                 C   s"   ddl m} |g | jd� ¡  d S )Nr   )ÚIPShellrR   )ÚIPython.Shellr_   r2   r]   )r   r_   r   r   r   rN   –   r^   zshell._ipython_010c                 C   s   t dƒ‚)Nzno suitable ipython found)rA   )r   r   r   r   rO   š   s   zshell._no_ipythonc                 C   s   dd l }| | j¡ d S r?   )r:   rZ   r2   )r   r:   r   r   r   r6   �   s   zshell.invoke_bpython_shellN)FFFFFF)r&   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r8   r5   r7   rK   rL   rM   rN   rO   r6   r   r   r   r   r      s"    

þ)	r   )rc   Ú
__future__r   r   r-   r*   Ú	importlibr   Úcelery.bin.baser   Úcelery.fiver   r   r   r   r   r   Ú<module>   s    