B
    `                 @   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               @   sF   e Zd ZdZdZdddgZdd Zdd	 Zd
d Zdd Z	dd Z
dS )CommandzRuns a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available. Any standard input is executed as code.F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   T/home/dcms/DCMS/lib/python3.7/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   &   s    zCommand.bpythonc       
   
   C   s   dd l }i }ydd l}W n tk
r,   Y nNX dd l}|||j t|dd}|d k	rpd|krp|d n
|d |d sxt	t
jdt
jd	gD ]j}|sqt
j|sqt|}| }	W d Q R X ytt|	|d
| W q tk
r
   t  Y qX qW |j|d d S )Nr   __doc__ Zlibeditzbind ^I rl_completeztab:completeZ
no_startupZPYTHONSTARTUPz~/.pythonrc.pyexec)local)codereadlineImportErrorrlcompleterZset_completerZ	CompleterZcompletegetattrZparse_and_bindr   osenvirongetpath
expanduserisfileopenreadr   compile	Exception	traceback	print_excZinteract)
r   r   r   Zimported_objectsr   r   Zreadline_docZpythonrchandleZpythonrc_coder   r   r   r   *   s2    

"
zCommand.pythonc          	   K   s   |d rt |d  d S tjdkrVtj sVttjgg g dd rVt tj  d S |d rh|d gn| j}x0|D ](}yt| ||S  t	k
r   Y qtX qtW t
d|d S )Ncommandwin32r   Z	interfacezCouldn't import {} interface.)r   sysplatformstdinisattyselectr(   r   r    r   r   format)r   r   Zavailable_shellsshellr   r   r   r-   T   s    ,

zCommand.handleN)__name__
__module____qualname__r   Zrequires_system_checksr   r   r   r   r   r-   r   r   r   r   r   
   s   
*r   )
r!   r4   r0   r+   Zdjango.core.managementr   r   Zdjango.utils.datastructuresr   r   r   r   r   r   <module>   s   