B
    ©0H[×  ã               @   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 )Ú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.FÚipythonÚbpythonÚpythonc             C   s>   |j ddddd� |j dd| jdd	d
� |j ddddd� d S )Nz--no-startupÚ
store_trueÚ
no_startupzaWhen using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.)ÚactionÚdestÚhelpz-iz--interfaceÚ	interfacezcSpecify an interactive interpreter interface. Available options: "ipython", "bpython", and "python")Úchoicesr   r   z-cz	--commandÚcommandzJInstead of opening an interactive shell, run a command as Django and exit.)r   r   )Úadd_argumentÚshells)ÚselfÚparser© r   úiC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\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xŠt	t
j d¡t
j d	¡gƒD ]j}|s¬q¢t
j |¡sºq¢t|ƒ�}| ¡ }	W d Q R X ytt|	|d
ƒ|ƒ W q¢ tk
�r
   t ¡  Y q¢X q¢W |j|d� d S )Nr   Ú__doc__Ú Zlibeditzbind ^I rl_completeztab:completer
   Z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rLt tjgg g d¡d rLt tj ¡ ƒ d S |d r^|d gn| j}x0|D ](}yt| |ƒ|ƒS  tk
r�   Y qjX qjW t	d 
|¡ƒ‚d S )Nr   Úwin32r   r   zCouldn't import {} interface.)r   ÚsysÚplatformÚselectÚstdinr,   r   r$   r"   r   Úformat)r   r   Zavailable_shellsÚshellr   r   r   r1   S   s    "

zCommand.handleN)Ú__name__Ú
__module__Ú__qualname__r   Zrequires_system_checksr   r   r   r   r   r1   r   r   r   r   r   
   s   
)r   )
r%   r5   r3   r/   Zdjango.core.managementr   r   Zdjango.utils.datastructuresr   r   r   r   r   r   Ú<module>   s   