2 This module is imported by the loader and serves to control
3 the execution of the user program. It presently executes files
4 and reports exceptions to IDLE. It could be extended to provide
5 other services, such as interactive mode and debugging. To that
6 end, it could be a subclass of e.g. InteractiveInterpreter.
8 Two other classes, pseudoIn and pseudoOut, are file emulators also
15 def __init__(self
, main
, master
):
18 self
.this_file
= self
.canonic( self
.__init
__.im_func
.func_code
.co_filename
)
20 def canonic(self
, path
):
21 return os
.path
.normcase(os
.path
.abspath(path
))
25 args
= self
.master
.get_command()
28 f
= getattr(self
,args
[0])
31 if not self
.report_exception(): raise
39 path
= self
.canonic( argv
[0] )
40 dir = self
.dir = os
.path
.dirname(path
)
46 exec usercode
in self
.main
48 def report_exception(self
):
50 type, value
, tb
= sys
.exc_info()
52 sys
.last_value
= value
53 sys
.last_traceback
= tb
55 tblist
= traceback
.extract_tb(tb
)
57 # Look through the traceback, canonicalizing filenames and
58 # eliminating leading and trailing system modules.
60 for i
in range(len(tblist
)):
61 filename
, lineno
, name
, line
= tblist
[i
]
62 filename
= self
.canonic(filename
)
63 tblist
[i
] = filename
, lineno
, name
, line
65 dir = os
.path
.dirname(filename
)
66 if filename
== self
.this_file
:
71 # Canonicalize the filename in a syntax error, too:
72 if type is SyntaxError:
74 msg
, (filename
, lineno
, offset
, line
) = value
75 filename
= self
.canonic(filename
)
76 value
= msg
, (filename
, lineno
, offset
, line
)
80 return self
.master
.program_exception( type, value
, tblist
, first
, last
)
82 # avoid any circular reference through the traceback
86 def __init__(self
, readline
):
87 self
.readline
= readline
92 def __init__(self
, func
, **kw
):
95 def write(self
, *args
):
96 return apply( self
.func
, args
, self
.kw
)
97 def writelines(self
, l
):