a
    Lcòf  ã                   @   sP   d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ G dd„ deƒZ	dS )é    N)ÚBaseCommandÚCommandError)Ú
OrderedSetc                   @   sD   e Zd ZdZg Zg d¢Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dS )ÚCommandzŒRuns a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available. Any standard input is executed as code.)ÚipythonÚbpythonÚpythonc                 C   s8   |j dddd� |j dd| jdd� |j d	d
dd� d S )Nz--no-startupÚ
store_truezaWhen using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.)ÚactionÚhelpz-iz--interfacezcSpecify an interactive interpreter interface. Available options: "ipython", "bpython", and "python")Úchoicesr   z-cz	--commandzJInstead of opening an interactive shell, run a command as Django and exit.)r   )Úadd_argumentÚshells)ÚselfÚparser© r   úb/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/management/commands/shell.pyÚadd_arguments   s     üû	üzCommand.add_argumentsc                 C   s   ddl m} |g d� d S )Nr   )Ústart_ipython)Úargv)ZIPythonr   )r   Úoptionsr   r   r   r   r   /   s    zCommand.ipythonc                 C   s   dd l }| ¡  d S )Nr   )r   Úembed)r   r   r   r   r   r   r   4   s    zCommand.bpythonc           
   	   C   sD  dd l }i }|d s¬ttj d¡tj d¡gƒD ]z}|s:q0tj |¡sHq0t|ƒ�}| 	¡ }W d   ƒ n1 sn0    Y  zt
t||dƒ|ƒ W q0 ty¨   t ¡  Y q00 q0z
tj}W n tyÈ   Y n00 z
|ƒ  W n" työ   tdƒ t ¡  Y n0 z&dd l}dd l}	| |	 |¡j¡ W n t�y2   Y n0 |j|d� d S )Nr   Z
no_startupZPYTHONSTARTUPz~/.pythonrc.pyÚexecz&Failed calling sys.__interactivehook__)Úlocal)Úcoder   ÚosÚenvironÚgetÚpathÚ
expanduserÚisfileÚopenÚreadr   ÚcompileÚ	ExceptionÚ	tracebackÚ	print_excÚsysÚ__interactivehook__ÚAttributeErrorÚprintÚreadlineÚrlcompleterZset_completerZ	CompleterZcompleteÚImportErrorZinteract)
r   r   r   Zimported_objectsZpythonrcÚhandleZpythonrc_codeÚhookr+   r,   r   r   r   r   9   s@    ÿ
&

zCommand.pythonc              	   K   sº   |d rt |d tƒ ƒ d S tjdkr^tj ¡ s^t tjgg g d¡d r^t tj ¡ tƒ ƒ d S |d rp|d gn| j}|D ],}zt	| |ƒ|ƒW   S  t
y¤   Y qz0 qztd |¡ƒ‚d S )NÚcommandÚwin32r   Z	interfacezCouldn't import {} interface.)r   Úglobalsr'   ÚplatformÚstdinÚisattyÚselectr"   r   Úgetattrr-   r   Úformat)r   r   Zavailable_shellsÚshellr   r   r   r.   r   s&    ÿþýÿzCommand.handleN)Ú__name__Ú
__module__Ú__qualname__r   Zrequires_system_checksr   r   r   r   r   r.   r   r   r   r   r   
   s   ÿ9r   )
r   r6   r'   r%   Zdjango.core.managementr   r   Zdjango.utils.datastructuresr   r   r   r   r   r   Ú<module>   s   