Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
InteractiveInterpreter Class Reference
Inheritance diagram for InteractiveInterpreter:
InteractiveConsole

Public Member Functions

def __init__
 
def runsource
 
def runcode
 
def showsyntaxerror
 
def showtraceback
 
def write
 

Data Fields

 locals
 
 compile
 

Detailed Description

Base class for InteractiveConsole.

This class deals with parsing and interpreter state (the user's
namespace); it doesn't deal with input buffering or prompting or
input file naming (the filename is always passed in explicitly).

Definition at line 28 of file code.py.

Constructor & Destructor Documentation

def __init__ (   self,
  locals = None 
)
Constructor.

The optional 'locals' argument specifies the dictionary in
which code will be executed; it defaults to a newly created
dictionary with key "__name__" set to "__console__" and key
"__doc__" set to None.

Definition at line 37 of file code.py.

37 
38  def __init__(self, locals=None):
39  """Constructor.
40 
41  The optional 'locals' argument specifies the dictionary in
42  which code will be executed; it defaults to a newly created
43  dictionary with key "__name__" set to "__console__" and key
44  "__doc__" set to None.
45 
46  """
47  if locals is None:
48  locals = {"__name__": "__console__", "__doc__": None}
49  self.locals = locals
50  self.compile = CommandCompiler()

Member Function Documentation

def runcode (   self,
  code 
)
Execute a code object.

When an exception occurs, self.showtraceback() is called to
display a traceback.  All exceptions are caught except
SystemExit, which is reraised.

A note about KeyboardInterrupt: this exception may occur
elsewhere in this code, and may not always be caught.  The
caller should be prepared to deal with it.

Definition at line 90 of file code.py.

References InteractiveInterpreter.locals, InteractiveInterpreter.showtraceback(), and code.softspace().

90 
91  def runcode(self, code):
92  """Execute a code object.
93 
94  When an exception occurs, self.showtraceback() is called to
95  display a traceback. All exceptions are caught except
96  SystemExit, which is reraised.
97 
98  A note about KeyboardInterrupt: this exception may occur
99  elsewhere in this code, and may not always be caught. The
100  caller should be prepared to deal with it.
101 
102  """
103  try:
104  exec code in self.locals
105  except SystemExit:
106  raise
107  except:
108  self.showtraceback()
109  else:
110  if softspace(sys.stdout, 0):
111  print
def runsource (   self,
  source,
  filename = "<input>",
  symbol = "single" 
)
Compile and run some source in the interpreter.

Arguments are as for compile_command().

One several things can happen:

1) The input is incorrect; compile_command() raised an
exception (SyntaxError or OverflowError).  A syntax traceback
will be printed by calling the showsyntaxerror() method.

2) The input is incomplete, and more input is required;
compile_command() returned None.  Nothing happens.

3) The input is complete; compile_command() returned a code
object.  The code is executed by calling self.runcode() (which
also handles run-time exceptions, except for SystemExit).

The return value is 1 in case 2, 0 in the other cases (unless
an exception is raised).  The return value can be used to
decide whether to use sys.ps1 or sys.ps2 to prompt the next
line.

Definition at line 51 of file code.py.

References InteractiveInterpreter.compile, InteractiveInterpreter.runcode(), and InteractiveInterpreter.showsyntaxerror().

51 
52  def runsource(self, source, filename="<input>", symbol="single"):
53  """Compile and run some source in the interpreter.
54 
55  Arguments are as for compile_command().
56 
57  One several things can happen:
58 
59  1) The input is incorrect; compile_command() raised an
60  exception (SyntaxError or OverflowError). A syntax traceback
61  will be printed by calling the showsyntaxerror() method.
62 
63  2) The input is incomplete, and more input is required;
64  compile_command() returned None. Nothing happens.
65 
66  3) The input is complete; compile_command() returned a code
67  object. The code is executed by calling self.runcode() (which
68  also handles run-time exceptions, except for SystemExit).
69 
70  The return value is 1 in case 2, 0 in the other cases (unless
71  an exception is raised). The return value can be used to
72  decide whether to use sys.ps1 or sys.ps2 to prompt the next
73  line.
74 
75  """
76  try:
77  code = self.compile(source, filename, symbol)
78  except (OverflowError, SyntaxError, ValueError):
79  # Case 1
80  self.showsyntaxerror(filename)
81  return 0
82 
83  if code is None:
84  # Case 2
85  return 1
86 
87  # Case 3
88  self.runcode(code)
89  return 0
def showsyntaxerror (   self,
  filename = None 
)
Display the syntax error that just occurred.

This doesn't display a stack trace because there isn't one.

If a filename is given, it is stuffed in the exception instead
of what was there before (because Python's parser always uses
"<string>" when reading from a string).

The output is written by self.write(), below.

Definition at line 112 of file code.py.

References traceback.format_exception_only(), Pickler.write, openrsrc.write(), _Hqxcoderengine.write(), _Rlecoderengine.write(), InteractiveInterpreter.write(), BinHex.write(), Marshaller.write, and file_wrapper.write.

113  def showsyntaxerror(self, filename=None):
114  """Display the syntax error that just occurred.
115 
116  This doesn't display a stack trace because there isn't one.
117 
118  If a filename is given, it is stuffed in the exception instead
119  of what was there before (because Python's parser always uses
120  "<string>" when reading from a string).
121 
122  The output is written by self.write(), below.
123 
124  """
125  type, value, sys.last_traceback = sys.exc_info()
126  sys.last_type = type
127  sys.last_value = value
128  if filename and type is SyntaxError:
129  # Work hard to stuff the correct filename in the exception
130  try:
131  msg, (dummy_filename, lineno, offset, line) = value
132  except:
133  # Not the format we expect; leave it alone
134  pass
135  else:
136  # Stuff in the right filename
137  try:
138  # Assume SyntaxError is a class exception
139  value = SyntaxError(msg, (filename, lineno, offset, line))
140  except:
141  # If that failed, assume SyntaxError is a string
142  value = msg, (filename, lineno, offset, line)
143  sys.last_value = value
144  list = traceback.format_exception_only(type, value)
145  map(self.write, list)
def showtraceback (   self)
Display the exception that just occurred.

We remove the first stack item because it is our own code.

The output is written by self.write(), below.

Definition at line 146 of file code.py.

References traceback.extract_tb(), traceback.format_exception_only(), traceback.format_list(), Pickler.write, openrsrc.write(), _Hqxcoderengine.write(), _Rlecoderengine.write(), InteractiveInterpreter.write(), BinHex.write(), Marshaller.write, and file_wrapper.write.

147  def showtraceback(self):
148  """Display the exception that just occurred.
149 
150  We remove the first stack item because it is our own code.
151 
152  The output is written by self.write(), below.
153 
154  """
155  try:
156  type, value, tb = sys.exc_info()
157  sys.last_type = type
158  sys.last_value = value
159  sys.last_traceback = tb
160  tblist = traceback.extract_tb(tb)
161  del tblist[:1]
162  list = traceback.format_list(tblist)
163  if list:
164  list.insert(0, "Traceback (most recent call last):\n")
165  list[len(list):] = traceback.format_exception_only(type, value)
166  finally:
167  tblist = tb = None
168  map(self.write, list)
def write (   self,
  data 
)
Write a string.

The base implementation writes to sys.stderr; a subclass may
replace this with a different implementation.

Definition at line 169 of file code.py.

170  def write(self, data):
171  """Write a string.
172 
173  The base implementation writes to sys.stderr; a subclass may
174  replace this with a different implementation.
175 
176  """
177  sys.stderr.write(data)
178 

Field Documentation

compile

Definition at line 49 of file code.py.

locals

Definition at line 48 of file code.py.


The documentation for this class was generated from the following file: