
 X                 @   sR   d  d l  Z  d  d l Z d  d l m Z d  d l m Z Gd d   d e  Z d S)    N)BaseCommand)RemovedInDjango20Warningc               @   s   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 d   Z d d   Z d d   Z d S)CommandzdRuns a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available.Fipythonbpythonpythonc          	   C   s   | j  d d d d d d d | j  d d d d d	 d d
 | j  d d d |  j d d d d | j  d d d d d d d  S)Nz--plainaction
store_truedestplainhelpzTells Django to use plain Python, not IPython or bpython. Deprecated, use the `-i python` or `--interface python` option instead.z--no-startup
no_startupzaWhen using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.z-iz--interfacechoices	interfacezcSpecify an interactive interpreter interface. Available options: "ipython", "bpython", and "python"z-cz	--commandcommandzJInstead of opening an interactive shell, run a command as Django and exit.)add_argumentshells)selfparser r   S/home/ubuntu/projects/ifolica/build/django/django/core/management/commands/shell.pyadd_arguments   s    zCommand.add_argumentsc             C   s-   d d l  m } | d g   } | j   d S)zStart IPython pre-0.11r   )IPShellargvN)ZIPython.Shellr   Zmainloop)r   r   shellr   r   r   _ipython_pre_011    s    zCommand._ipython_pre_011c             C   s:   d d l  m } | j   } | j d g   | j   d S)zStart IPython pre-1.0.0r   )TerminalIPythonAppr   N)ZIPython.frontend.terminal.ipappr   instanceZ
initializestart)r   r   Zappr   r   r   _ipython_pre_100&   s    zCommand._ipython_pre_100c             C   s!   d d l  m } | d g   d S)zStart IPython >= 1.0r   )start_ipythonr   N)ZIPythonr    )r   r    r   r   r   _ipython-   s    zCommand._ipythonc             C   sW   xD |  j  |  j |  j f D]* } y |   Wn t k
 r> Yq Xd Sq Wt d   d S)zStart any version of IPythonNz
No IPython)r!   r   r   ImportError)r   optionsipr   r   r   r   2   s    zCommand.ipythonc             C   s   d d  l  } | j   d  S)Nr   )r   embed)r   r#   r   r   r   r   r   >   s    zCommand.bpythonc       	      C   sj  d d  l  } i  } y d d  l } Wn t k
 r6 Ynm Xd d  l } | j | j |  j  t | d d  } | d  k	 r d | k r | j d  n | j d  | d sVx t	 j
 j d  d	 f D] } | s q n  t	 j j |  } t	 j j |  sq n  y8 t |  & } t t | j   | d
  |  Wd  QXWq t k
 rNYq Xq Wn  | j d |  d  S)Nr   __doc__ libeditzbind ^I rl_completeztab:completer   ZPYTHONSTARTUPz~/.pythonrc.pyexeclocal)codereadliner"   rlcompleterZset_completerZ	CompleterZcompletegetattrparse_and_bindosenvirongetpath
expanduserisfileopenr)   compileread	NameErrorZinteract)	r   r#   r+   Zimported_objectsr,   r-   readline_docZpythonrchandler   r   r   r   B   s2    
)zCommand.pythonc             K   s   | d r' t  j d t  d | d <n  | d rC t | d  d  S| d rZ | d g n |  j } x: | D]2 } y t |  |  |  SWqj t k
 r Yqj Xqj Wt d   d  S)Nr   zXThe --plain option is deprecated in favor of the -i python or --interface python option.r   r   r   z.Couldn't load any of the specified interfaces.)warningswarnr   r)   r   r.   r"   )r   r#   Zavailable_shellsr   r   r   r   r;   h   s    

 	zCommand.handleN)__name__
__module____qualname__r   Zrequires_system_checksr   r   r   r   r!   r   r   r   r;   r   r   r   r   r      s   &r   )r0   r<   Zdjango.core.management.baser   Zdjango.utils.deprecationr   r   r   r   r   r   <module>   s   