66# COPYRIGHT : (C) 2004 Ero Carrera, ero@dkbza.org
77# (C) 2012 Adrian Soto
88# (C) 2014 Miguel de Benito Delgado, mdbenito@texmacs.org
9- # (C) 2018-2019 Darcy Shen
9+ # (C) 2018-2020 Darcy Shen
1010#
1111# This software falls under the GNU general public license version 3 or later.
1212# It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
2222 sys .path .append (os .environ .get ("TEXMACS_PATH" ) + "/plugins/" )
2323
2424
25+
2526import traceback
2627import string
2728from inspect import ismodule , getsource , getsourcefile
29+ from tmpy .compat import py_ver
2830from tmpy .capture import CaptureStdout
2931from tmpy .postscript import ps_out
3032from tmpy .completion import parse_complete_command , complete
31- from tmpy .compat import *
3233from tmpy .protocol import *
3334
35+ if py_ver == 2 :
36+ flush_err ("Python 2 is no longer supported, please use Python 3" )
37+ exit (- 1 )
38+
3439# import logging as log
3540# log.basicConfig(filename='/tmp/tm_python.log',level=log.DEBUG)
36- def compose_output (data ):
41+ def compose_output (data ):
3742 """Do some parsing on the output according to its type.
3843
3944 Non printable characters in unicode strings are escaped
4045 and objects of type None are not printed (so that procedure calls,
4146 as opposed to function calls, don't produce any output)."""
4247
43- if py_ver == 3 : cl = str
44- else : cl = unicode
45- if isinstance (data , cl ):
48+ if isinstance (data , str ):
4649 data2 = r''
4750 for c in data :
4851 if c not in string .printable :
@@ -82,8 +85,8 @@ def compile_help (text):
8285
8386 return dict (map (lambda k_v : (k_v [0 ], as_scm_string (k_v [1 ])), out .items ()))
8487
85- __version__ = '1.14 '
86- __author__ = 'Ero Carrera, Adrian Soto, Miguel de Benito Delgado'
88+ __version__ = '3.0 '
89+ __author__ = 'Ero Carrera, Adrian Soto, Miguel de Benito Delgado, Darcy Shen '
8790my_globals = {}
8891
8992# We insert into the session's namespace the 'ps_out' method.
@@ -96,17 +99,10 @@ def compile_help (text):
9699A rudimentary help window is also implemented: type the name of an object
97100with a question mark at the end to use it."""
98101
99- if py_ver == 3 :
100- text = 'import builtins as __builtins__'
101- else :
102- text = 'import __builtin__ as __builtins__'
102+ text = 'import builtins as __builtins__'
103103CaptureStdout .capture (text , my_globals , "tm_python" )
104104
105- if py_ver == 3 :
106- sys .stdout = os .fdopen (sys .stdout .fileno (), 'w' )
107- else :
108- sys .stdout = os .fdopen (sys .stdout .fileno (), 'w' , 0 )
109-
105+ sys .stdout = os .fdopen (sys .stdout .fileno (), 'w' )
110106
111107###############################################################################
112108# Session start
@@ -119,7 +115,7 @@ def compile_help (text):
119115 "Please see the documentation in Help -> Plugins -> Python" )
120116flush_prompt (">>> " )
121117while True :
122- line = tm_input ()
118+ line = input ()
123119 if not line :
124120 continue
125121 if line [0 ] == DATA_COMMAND :
@@ -138,14 +134,13 @@ def compile_help (text):
138134 else :
139135 lines = [line ]
140136 while line != "<EOF>" :
141- line = tm_input ()
137+ line = input ()
142138 if line == '' :
143139 continue
144- lines .append (line )
145- text = '\n ' .join (lines [:- 1 ])
140+ lines .append (line )
141+ text = '\n ' .join (lines [:- 1 ])
146142 try : # Is it an expression?
147- result = eval (text , my_globals )
143+ result = eval (text , my_globals )
148144 except :
149- result = CaptureStdout .capture (text , my_globals , "tm_python" )
145+ result = CaptureStdout .capture (text , my_globals , "tm_python" )
150146 flush_verbatim (compose_output (result ))
151-
0 commit comments