12 except AttributeError:
16 def print_exc(limit
=None, file=None):
19 # we're going to skip the outermost traceback object, we don't
20 # want people to see the line which excecuted their code.
21 tb
= sys
.exc_traceback
25 sys
.last_type
= sys
.exc_type
26 sys
.last_value
= sys
.exc_value
27 sys
.last_traceback
= tb
28 traceback
.print_exception(sys
.last_type
, sys
.last_value
,
29 sys
.last_traceback
, limit
, file)
32 traceback
.print_exception(sys
.exc_type
, sys
.exc_value
,
33 sys
.exc_traceback
, limit
, file)
41 def executeline(self
, stuff
, out
= None, env
= None):
44 env
= __main__
.__dict
__
46 saveerr
, saveout
= sys
.stderr
, sys
.stdout
47 sys
.stderr
= sys
.stdout
= out
50 self
._pybuf
= self
._pybuf
+ '\n' + stuff
54 # Compile three times: as is, with \n, and with \n\n appended.
55 # If it compiles as is, it's complete. If it compiles with
56 # one \n appended, we expect more. If it doesn't compile
57 # either way, we compare the error we get when compiling with
58 # \n or \n\n appended. If the errors are the same, the code
59 # is broken. But if the errors are different, we expect more.
60 # Not intuitive; not even guaranteed to hold in future
61 # releases; but this matches the compiler's behavior in Python
63 err
= err1
= err2
= None
64 code
= code1
= code2
= None
66 # quickly get out of here when the line is 'empty' or is a comment
67 stripped
= string
.strip(self
._pybuf
)
68 if not stripped
or stripped
[0] == '#':
70 sys
.stdout
.write(sys
.ps1
)
75 code
= compile(self
._pybuf
, "<input>", "single")
76 except SyntaxError, err
:
79 # OverflowError. More?
82 sys
.stdout
.write(sys
.ps1
)
87 code1
= compile(self
._pybuf
+ "\n", "<input>", "single")
88 except SyntaxError, err1
:
92 code2
= compile(self
._pybuf
+ "\n\n", "<input>", "single")
93 except SyntaxError, err2
:
104 elif err1
== err2
or (not stuff
and self
._pybuf
):
108 sys
.stdout
.write(sys
.ps2
)
111 sys
.stdout
.write(sys
.ps1
)
115 sys
.stderr
, sys
.stdout
= saveerr
, saveout