U
    ZÊ¹já;  ã                   @   s¢   d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ	dZ
dZddd„Zdd„ Zdd„ Zdd„ Zdg d
d
fdd„Zdd„ Zdd	dddd
d
d
dddg fdd„ZdS )z+Tools for setting up interactive sessions. é    )ÚGROUND_TYPES)Úversion_tuple)Úinit_printing)ÚARCHz–from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()
zjThese commands were executed:
%(source)s
Documentation can be found at https://docs.sympy.org/%(version)s
zÏCould not locate IPython. Having IPython installed is greatly recommended.
See http://ipython.scipy.org for more details. If you use Debian/Ubuntu,
just install the 'ipython' package and start isympy again.
TFNc                 C   s(  ddl m} ddl m} ddl}ddl}|r0dS d|jdd…  }| rLd}nd	}d
t g}	| d¡}
|
dk	r‚|
 ¡ dkr‚|	 	d¡ |r�|	 	d¡ |||t
d |	¡f}d| }|dkr¸t}d}| d¡dd… D ]"}|sà|d7 }qÎ|d| d 7 }qÎ|}d|k�rd}nd| }|dt||dœ  7 }|S )z,Create a banner for an interactive session. r   )Ú__version__)ÚSYMPY_DEBUGNÚ z%d.%d.%dé   ÚIPythonÚPythonzground types: %sZSYMPY_USE_CACHEÚnoz
cache: offzdebugging: onz, z,%s console for SymPy %s (Python %s-%s) (%s)
Ú
éÿÿÿÿz>>> Údevz%s/)ÚsourceÚversion)Zsympyr   r   ÚsysÚosÚversion_infor   ÚgetenvÚlowerÚappendr   ÚjoinÚpreexec_sourceÚsplitÚverbose_message)ÚipythonÚquietr   Zsympy_versionr   r   r   Úpython_versionZ
shell_nameÚinfoÚcacheÚargsÚmessageÚ_sourceÚlineZdoc_version© r%   úX/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/interactive/session.pyÚ_make_message   sB    





ÿr'   c                 C   s    ddl m}m}m}m}m} ddlm} dd„ }g }||| ƒjƒ}	|	D ]P\}
}}}}|
|krˆ||ƒrˆ| 	|df|df||f|dfg¡ qF| 
|
|f¡ qF||ƒS )	aw  
    Wrap integer literals with Integer.

    This is based on the decistmt example from
    https://docs.python.org/3/library/tokenize.html.

    Only integer literals are converted.  Float literals are left alone.

    Examples
    ========

    >>> from sympy import Integer # noqa: F401
    >>> from sympy.interactive.session import int_to_Integer
    >>> s = '1.2 + 1/2 - 0x12 + a1'
    >>> int_to_Integer(s)
    '1.2 +Integer (1 )/Integer (2 )-Integer (0x12 )+a1 '
    >>> s = 'print (1/2)'
    >>> int_to_Integer(s)
    'print (Integer (1 )/Integer (2 ))'
    >>> exec(s)
    0.5
    >>> exec(int_to_Integer(s))
    1/2
    r   )Úgenerate_tokensÚ
untokenizeÚNUMBERÚNAMEÚOP)ÚStringIOc                 S   s(   d| ks d|   ¡ ks d|   ¡ kr$dS dS )z]
        Returns true if string value num (with token NUMBER) represents an integer.
        Ú.ÚjÚeFT)r   )Únumr%   r%   r&   Ú_is_intq   s     zint_to_Integer.<locals>._is_intÚIntegerú(ú))Útokenizer(   r)   r*   r+   r,   Úior-   ÚreadlineÚextendr   )Úsr(   r)   r*   r+   r,   r-   r2   ÚresultÚgÚtoknumÚtokvalÚ_r%   r%   r&   Úint_to_IntegerU   s    	ür@   c                    s&   ddl ‰ | j‰‡ ‡fdd„}|| _dS )zM
    Allow IPython to automatically convert integer literals to Integer.
    r   Nc                    s<   zˆ   | ¡ W n tk
r"   Y n
X t| ƒ} ˆ| f|ž|ŽS )N)ÚparseÚSyntaxErrorr@   )Úcellr!   Úkwargs©ÚastZold_run_cellr%   r&   Úmy_run_cell�   s    z7enable_automatic_int_sympification.<locals>.my_run_cell)rF   Úrun_cell)ÚshellrG   r%   rE   r&   Ú"enable_automatic_int_sympification‰   s    rJ   c                    s2   ddl }| d¡‰ d‡ fdd„	}|  tf|¡ dS )z?Allow IPython to automatically create symbols (``isympy -a``). r   Nz8name '(?P<symbol>[A-Za-z_][A-Za-z0-9_]*)' is not definedc                    sÐ   |t krª|jrª|jjsªˆ  t|ƒ¡}|dk	rª| jdd| d¡i dd� zFz| jd d }W n ttfk
rt   Y nX | j|dd� W ¢dS W 5 | jd| d¡ dd� X | j	j
||||d	�}|  |||¡ dS )
zJHandle :exc:`NameError` exception and allow injection of missing symbols. Nz!%(symbol)s = Symbol('%(symbol)s')ÚsymbolF)Zstore_historyzdel %sÚInr   )Ú	tb_offset)Ú	NameErrorÚtb_nextÚmatchÚstrrH   ÚgroupZuser_nsÚKeyErrorÚ
IndexErrorZInteractiveTBZstructured_tracebackÚ_showtraceback)ÚselfÚetypeÚvalueÚtbrM   rP   ÚcodeZstb©Zre_nameerrorr%   r&   Ú_handlerÌ   s0    ÿÿÿ   ÿz*enable_automatic_symbols.<locals>._handler)N)ÚreÚcompileZset_custom_excrN   )rI   r]   r\   r%   r[   r&   Úenable_automatic_symbols¡   s    'ÿr_   c                 C   sœ   ddl }t|jƒtdƒkr„| sht|jƒtdƒkr>ddlm} nddlm} | ¡ }d|_| |¡ |j	} |rtt
| ƒ |r€t| ƒ | S ddlm} ||ƒS dS )zConstruct new IPython session. r   Nú0.11z1.0)ÚipappF)Úmake_IPython)r
   r   r   ZIPython.terminalra   ZIPython.frontend.terminalZTerminalIPythonAppZdisplay_bannerZ
initializerI   r_   rJ   ZIPython.Shellrb   )rI   ÚargvÚauto_symbolsÚauto_int_to_Integerr
   ra   Zapprb   r%   r%   r&   Úinit_ipython_sessionè   s"    
rf   c                     s&   ddl m‰  G ‡ fdd„dˆ ƒ} | ƒ S )zConstruct new Python session. r   ©ÚInteractiveConsolec                       s   e Zd ZdZ‡ fdd„ZdS )z)init_python_session.<locals>.SymPyConsolez.An interactive console with readline support. c                    s´   i }ˆ j | |d� zdd l}dd l}W n tk
r:   Y nvX dd l}dd l}| | |¡j¡ | 	d¡ t
|dƒr°|j d¡}z| |¡ W n tk
r    Y nX | |j|¡ d S )N)Úlocalsr   ztab: completeÚread_history_filez~/.sympy-history)Ú__init__Úrlcompleterr8   ÚImportErrorr   ÚatexitZset_completerZ	CompleterZcompleteÚparse_and_bindÚhasattrÚpathÚ
expanduserrj   ÚOSErrorÚregisterÚwrite_history_file)rV   Z	ns_localsrl   r8   r   rn   Úhistoryrg   r%   r&   rk     s$    

z2init_python_session.<locals>.SymPyConsole.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rk   r%   rg   r%   r&   ÚSymPyConsole  s   r{   )rZ   rh   )r{   r%   rg   r&   Úinit_python_session	  s    r|   c              
      sÐ  ddl }d}| dk	rŽzddl}W n( tk
rH   | dkr@tdƒ‚d‰ Y n2X zddlm} |ƒ ‰ W n tk
rx   d‰ Y nX tˆ ƒ}| dkrŽ|} | dkr¤tƒ ‰ ˆ j}ndtˆ |||d�‰ t	|j
ƒt	dƒkrüd‡ fd
d„	ˆ _zˆ jdd� W n tk
rú   Y nX |�sˆ j}|�r0| �r(t	|j
ƒt	dƒk �r0tdƒ‚|�rX| �rPt	|j
ƒt	dƒk �rXtdƒ‚t}ˆ j|d	d� t||||ˆ ||	|
d� t| ||ƒ}|�s®t|ƒ |ƒ  | d¡ nt|ƒ ddl}| dd„ ¡ dS )u”  
    Initialize an embedded IPython or Python session. The IPython session is
    initiated with the --pylab option, without the numpy imports, so that
    matplotlib plotting can be interactive.

    Parameters
    ==========

    pretty_print: boolean
        If True, use pretty_print to stringify;
        if False, use sstrrepr to stringify.
    order: string or None
        There are a few different settings for this parameter:
        lex (default), which is lexographic order;
        grlex, which is graded lexographic order;
        grevlex, which is reversed graded lexographic order;
        old, which is used for compatibility reasons and for long expressions;
        None, which sets it to lex.
    use_unicode: boolean or None
        If True, use unicode characters;
        if False, do not use unicode characters.
    use_latex: boolean or None
        If True, use latex rendering if IPython GUI's;
        if False, do not use latex rendering.
    quiet: boolean
        If True, init_session will not print messages regarding its status;
        if False, init_session will print messages regarding its status.
    auto_symbols: boolean
        If True, IPython will automatically create symbols for you.
        If False, it will not.
        The default is False.
    auto_int_to_Integer: boolean
        If True, IPython will automatically wrap int literals with Integer, so
        that things like 1/2 give Rational(1, 2).
        If False, it will not.
        The default is False.
    ipython: boolean or None
        If True, printing will initialize for an IPython console;
        if False, printing will initialize for a normal console;
        The default is None, which automatically determines whether we are in
        an ipython instance or not.
    str_printer: function, optional, default=None
        A custom string printer function. This should mimic
        sympy.printing.sstrrepr().
    pretty_printer: function, optional, default=None
        A custom pretty printer. This should mimic sympy.printing.pretty().
    latex_printer: function, optional, default=None
        A custom LaTeX printer. This should mimic sympy.printing.latex()
        This should mimic sympy.printing.latex().
    argv: list of arguments for IPython
        See sympy.bin.isympy for options that can be used to initialize IPython.

    See Also
    ========

    sympy.interactive.printing.init_printing: for examples and the rest of the parameters.


    Examples
    ========

    >>> from sympy import init_session, Symbol, sin, sqrt
    >>> sin(x) #doctest: +SKIP
    NameError: name 'x' is not defined
    >>> init_session() #doctest: +SKIP
    >>> sin(x) #doctest: +SKIP
    sin(x)
    >>> sqrt(5) #doctest: +SKIP
      ___
    \/ 5
    >>> init_session(pretty_print=False) #doctest: +SKIP
    >>> sqrt(5) #doctest: +SKIP
    sqrt(5)
    >>> y + x + y**2 + x**2 #doctest: +SKIP
    x**2 + x + y**2 + y
    >>> init_session(order='grlex') #doctest: +SKIP
    >>> y + x + y**2 + x**2 #doctest: +SKIP
    x**2 + y**2 + x + y
    >>> init_session(order='grevlex') #doctest: +SKIP
    >>> y * x**2 + x * y**2 #doctest: +SKIP
    x**2*y + x*y**2
    >>> init_session(order='old') #doctest: +SKIP
    >>> x**2 + y**2 + x + y #doctest: +SKIP
    x + y + x**2 + y**2
    >>> theta = Symbol('theta') #doctest: +SKIP
    >>> theta #doctest: +SKIP
    theta
    >>> init_session(use_unicode=True) #doctest: +SKIP
    >>> theta # doctest: +SKIP
    Î¸
    r   NFTz'IPython is not available on this system)Úget_ipython)rc   rd   re   r`   Úexecc                    s   ˆ   | d¡S )NF)rH   )ÚsrcrK   ©Úipr%   r&   Ú<lambda>«  ó    zinit_session.<locals>.<lambda>)Z
import_allzKautomatic construction of symbols is possible only in IPython 0.11 or abovezQautomatic int to Integer transformation is possible only in IPython 0.11 or above)rK   )Úpretty_printÚorderÚuse_unicodeÚ	use_latexr�   Ústr_printerÚpretty_printerÚlatex_printerzExiting ...c                   S   s   t dƒS )NzExiting ...
)Úprintr%   r%   r%   r&   r‚   Ï  rƒ   )r~   )r   r
   rm   ÚRuntimeErrorr}   Úboolr|   Zinteractrf   r   r   Z	runsourceZenable_pylabÚ	ExceptionÚmainloopr   r   r'   r‹   Úexitrn   rt   )r   r„   r…   r†   r‡   r   rd   re   rˆ   r‰   rŠ   rc   r   Z
in_ipythonr
   r}   r�   Z_preexec_sourcer"   rn   r%   r€   r&   Úinit_session,  sj    _


ÿ     ýr‘   )TFN)rz   Zsympy.external.gmpyr   Zsympy.external.importtoolsr   Zsympy.interactive.printingr   Zsympy.utilities.miscr   r   r   Z
no_ipythonr'   r@   rJ   r_   rf   r|   r‘   r%   r%   r%   r&   Ú<module>   s0   
64G!#      ý