<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> from distutils . version import LooseVersion as V <EOL> from sympy . external import import_module <EOL> from sympy . interactive . printing import init_printing <EOL> preexec_source = """<STR_LIT>""" <EOL> verbose_message = """<STR_LIT>""" <EOL> no_ipython = """<STR_LIT>""" <EOL> def _make_message ( ipython = True , quiet = False , source = None ) : <EOL> """<STR_LIT>""" <EOL> from sympy import __version__ as sympy_version <EOL> from sympy . polys . domains import GROUND_TYPES <EOL> from sympy . utilities . misc import ARCH <EOL> from sympy import SYMPY_DEBUG <EOL> import sys <EOL> import os <EOL> if quiet : <EOL> return "<STR_LIT>" <EOL> python_version = "<STR_LIT>" % sys . version_info [ : <NUM_LIT:3> ] <EOL> if ipython : <EOL> shell_name = "<STR_LIT>" <EOL> else : <EOL> shell_name = "<STR_LIT>" <EOL> info = [ '<STR_LIT>' % GROUND_TYPES ] <EOL> cache = os . getenv ( '<STR_LIT>' ) <EOL> if cache is not None and cache . lower ( ) == '<STR_LIT>' : <EOL> info . append ( '<STR_LIT>' ) <EOL> if SYMPY_DEBUG : <EOL> info . append ( '<STR_LIT>' ) <EOL> args = shell_name , sympy_version , python_version , ARCH , '<STR_LIT:U+002CU+0020>' . join ( info ) <EOL> message = "<STR_LIT>" % args <EOL> if source is None : <EOL> source = preexec_source <EOL> _source = "<STR_LIT>" <EOL> for line in source . split ( '<STR_LIT:\n>' ) [ : - <NUM_LIT:1> ] : <EOL> if not line : <EOL> _source += '<STR_LIT:\n>' <EOL> else : <EOL> _source += '<STR_LIT>' + line + '<STR_LIT:\n>' <EOL> doc_version = sympy_version <EOL> if '<STR_LIT>' in doc_version : <EOL> doc_version = "<STR_LIT>" <EOL> else : <EOL> doc_version = "<STR_LIT>" % doc_version <EOL> message += '<STR_LIT:\n>' + verbose_message % { '<STR_LIT:source>' : _source , <EOL> '<STR_LIT:version>' : doc_version } <EOL> return message <EOL> def int_to_Integer ( s ) : <EOL> """<STR_LIT>""" <EOL> from tokenize import generate_tokens , untokenize , NUMBER , NAME , OP <EOL> from sympy . core . compatibility import StringIO <EOL> def _is_int ( num ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:.>' in num or '<STR_LIT>' in num . lower ( ) or '<STR_LIT:e>' in num . lower ( ) : <EOL> return False <EOL> return True <EOL> result = [ ] <EOL> g = generate_tokens ( StringIO ( s ) . readline ) <EOL> for toknum , tokval , _ , _ , _ in g : <EOL> if toknum == NUMBER and _is_int ( tokval ) : <EOL> result . extend ( [ <EOL> ( NAME , '<STR_LIT>' ) , <EOL> ( OP , '<STR_LIT:(>' ) , <EOL> ( NUMBER , tokval ) , <EOL> ( OP , '<STR_LIT:)>' ) <EOL> ] ) <EOL> else : <EOL> result . append ( ( toknum , tokval ) ) <EOL> return untokenize ( result ) <EOL> def enable_automatic_int_sympification ( app ) : <EOL> """<STR_LIT>""" <EOL> hasshell = hasattr ( app , '<STR_LIT>' ) <EOL> import ast <EOL> if hasshell : <EOL> old_run_cell = app . shell . run_cell <EOL> else : <EOL> old_run_cell = app . run_cell <EOL> def my_run_cell ( cell , * args , ** kwargs ) : <EOL> try : <EOL> ast . parse ( cell ) <EOL> except SyntaxError : <EOL> pass <EOL> else : <EOL> cell = int_to_Integer ( cell ) <EOL> old_run_cell ( cell , * args , ** kwargs ) <EOL> if hasshell : <EOL> app . shell . run_cell = my_run_cell <EOL> else : <EOL> app . run_cell = my_run_cell <EOL> def enable_automatic_symbols ( app ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> re_nameerror = re . compile ( <EOL> "<STR_LIT>" ) <EOL> def _handler ( self , etype , value , tb , tb_offset = None ) : <EOL> """<STR_LIT>""" <EOL> if etype is NameError and tb . tb_next and not tb . tb_next . tb_next : <EOL> match = re_nameerror . match ( str ( value ) ) <EOL> if match is not None : <EOL> self . run_cell ( "<STR_LIT>" % <EOL> { '<STR_LIT>' : match . group ( "<STR_LIT>" ) } , store_history = False ) <EOL> try : <EOL> code = self . user_ns [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] <EOL> except ( KeyError , IndexError ) : <EOL> pass <EOL> else : <EOL> self . run_cell ( code , store_history = False ) <EOL> return None <EOL> finally : <EOL> self . run_cell ( "<STR_LIT>" % match . group ( "<STR_LIT>" ) , <EOL> store_history = False ) <EOL> stb = self . InteractiveTB . structured_traceback ( <EOL> etype , value , tb , tb_offset = tb_offset ) <EOL> self . _showtraceback ( etype , value , stb ) <EOL> if hasattr ( app , '<STR_LIT>' ) : <EOL> app . shell . set_custom_exc ( ( NameError , ) , _handler ) <EOL> else : <EOL> app . set_custom_exc ( ( NameError , ) , _handler ) <EOL> def init_ipython_session ( argv = [ ] , auto_symbols = False , auto_int_to_Integer = False ) : <EOL> """<STR_LIT>""" <EOL> import IPython <EOL> if V ( IPython . __version__ ) >= '<STR_LIT>' : <EOL> if V ( IPython . __version__ ) >= '<STR_LIT:1.0>' : <EOL> from IPython . terminal import ipapp <EOL> else : <EOL> from IPython . frontend . terminal import ipapp <EOL> app = ipapp . TerminalIPythonApp ( ) <EOL> app . display_banner = False <EOL> app . initialize ( argv ) <EOL> if auto_symbols : <EOL> readline = import_module ( "<STR_LIT>" ) <EOL> if readline : <EOL> enable_automatic_symbols ( app ) <EOL> if auto_int_to_Integer : <EOL> enable_automatic_int_sympification ( app ) <EOL> return app . shell <EOL> else : <EOL> from IPython . Shell import make_IPython <EOL> return make_IPython ( argv ) <EOL> def init_python_session ( ) : <EOL> """<STR_LIT>""" <EOL> from code import InteractiveConsole <EOL> class SymPyConsole ( InteractiveConsole ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> InteractiveConsole . __init__ ( self ) <EOL> try : <EOL> import readline <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> import os <EOL> import atexit <EOL> readline . parse_and_bind ( '<STR_LIT>' ) <EOL> if hasattr ( readline , '<STR_LIT>' ) : <EOL> history = os . path . expanduser ( '<STR_LIT>' ) <EOL> try : <EOL> readline . read_history_file ( history ) <EOL> except IOError : <EOL> pass <EOL> atexit . register ( readline . write_history_file , history ) <EOL> return SymPyConsole ( ) <EOL> def init_session ( ipython = None , pretty_print = True , order = None , <EOL> use_unicode = None , use_latex = None , quiet = False , auto_symbols = False , <EOL> auto_int_to_Integer = False , str_printer = None , pretty_printer = None , <EOL> latex_printer = None , argv = [ ] ) : <EOL> """<STR_LIT>""" <EOL> import sys <EOL> in_ipython = False <EOL> if ipython is not False : <EOL> try : <EOL> import IPython <EOL> except ImportError : <EOL> if ipython is True : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> ip = None <EOL> else : <EOL> if V ( IPython . __version__ ) >= '<STR_LIT>' : <EOL> try : <EOL> ip = get_ipython ( ) <EOL> except NameError : <EOL> ip = None <EOL> else : <EOL> ip = IPython . ipapi . get ( ) <EOL> if ip : <EOL> ip = ip . IP <EOL> in_ipython = bool ( ip ) <EOL> if ipython is None : <EOL> ipython = in_ipython <EOL> if ipython is False : <EOL> ip = init_python_session ( ) <EOL> mainloop = ip . interact <EOL> else : <EOL> if ip is None : <EOL> ip = init_ipython_session ( argv = argv , auto_symbols = auto_symbols , <EOL> auto_int_to_Integer = auto_int_to_Integer ) <EOL> if V ( IPython . __version__ ) >= '<STR_LIT>' : <EOL> ip . runsource = lambda src , symbol = '<STR_LIT>' : ip . run_cell ( src , False ) <EOL> try : <EOL> ip . enable_pylab ( import_all = False ) <EOL> except Exception : <EOL> pass <EOL> if not in_ipython : <EOL> mainloop = ip . mainloop <EOL> readline = import_module ( "<STR_LIT>" ) <EOL> if auto_symbols and ( not ipython or V ( IPython . __version__ ) < '<STR_LIT>' or not readline ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if auto_int_to_Integer and ( not ipython or V ( IPython . __version__ ) < '<STR_LIT>' ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> _preexec_source = preexec_source <EOL> ip . runsource ( _preexec_source , symbol = '<STR_LIT>' ) <EOL> init_printing ( pretty_print = pretty_print , order = order , <EOL> use_unicode = use_unicode , use_latex = use_latex , ip = ip , <EOL> str_printer = str_printer , pretty_printer = pretty_printer , <EOL> latex_printer = latex_printer ) <EOL> message = _make_message ( ipython , quiet , _preexec_source ) <EOL> if not in_ipython : <EOL> mainloop ( message ) <EOL> sys . exit ( '<STR_LIT>' ) <EOL> else : <EOL> ip . write ( message ) <EOL> import atexit <EOL> atexit . register ( lambda ip : ip . write ( "<STR_LIT>" ) , ip ) </s>
