Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Properties
MoinMoin.support.werkzeug.debug.tbtools.Frame Class Reference

List of all members.

Public Member Functions

def __init__
def render
def render_source
def eval
def sourcelines
def current_line
def console

Public Attributes

 lineno
 function_name
 locals
 globals
 filename
 module
 loader
 code
 hide
 info

Properties

 id = property(lambda x: id(x))

Detailed Description

A single frame in a traceback.

Definition at line 163 of file tbtools.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.debug.tbtools.Frame.__init__ (   self,
  exc_type,
  exc_value,
  tb 
)

Definition at line 166 of file tbtools.py.

00166 
00167     def __init__(self, exc_type, exc_value, tb):
00168         self.lineno = tb.tb_lineno
00169         self.function_name = tb.tb_frame.f_code.co_name
00170         self.locals = tb.tb_frame.f_locals
00171         self.globals = tb.tb_frame.f_globals
00172 
00173         fn = inspect.getsourcefile(tb) or inspect.getfile(tb)
00174         if fn[-4:] in ('.pyo', '.pyc'):
00175             fn = fn[:-1]
00176         # if it's a file on the file system resolve the real filename.
00177         if os.path.isfile(fn):
00178             fn = os.path.realpath(fn)
00179         self.filename = fn
00180         self.module = self.globals.get('__name__')
00181         self.loader = self.globals.get('__loader__')
00182         self.code = tb.tb_frame.f_code
00183 
00184         # support for paste's traceback extensions
00185         self.hide = self.locals.get('__traceback_hide__', False)
00186         info = self.locals.get('__traceback_info__')
00187         if info is not None:
00188             try:
00189                 info = unicode(info)
00190             except UnicodeError:
00191                 info = str(info).decode('utf-8', 'replace')
00192         self.info = info


Member Function Documentation

Definition at line 294 of file tbtools.py.

00294 
00295     def console(self):
00296         return Console(self.globals, self.locals)

Definition at line 287 of file tbtools.py.

00287 
00288     def current_line(self):
00289         try:
00290             return self.sourcelines[self.lineno - 1]
00291         except IndexError:
00292             return u''

Here is the call graph for this function:

def MoinMoin.support.werkzeug.debug.tbtools.Frame.eval (   self,
  code,
  mode = 'single' 
)
Evaluate code in the context of the frame.

Definition at line 224 of file tbtools.py.

00224 
00225     def eval(self, code, mode='single'):
00226         """Evaluate code in the context of the frame."""
00227         if isinstance(code, basestring):
00228             if isinstance(code, unicode):
00229                 code = UTF8_COOKIE + code.encode('utf-8')
00230             code = compile(code, '<interactive>', mode)
00231         if mode != 'exec':
00232             return eval(code, self.globals, self.locals)
00233         exec code in self.globals, self.locals

Render a single frame in a traceback.

Definition at line 193 of file tbtools.py.

00193 
00194     def render(self):
00195         """Render a single frame in a traceback."""
00196         return render_template('frame.html', frame=self)

Here is the call graph for this function:

Render the sourcecode.

Definition at line 197 of file tbtools.py.

00197 
00198     def render_source(self):
00199         """Render the sourcecode."""
00200         lines = [Line(idx + 1, x) for idx, x in enumerate(self.sourcelines)]
00201 
00202         # find function definition and mark lines
00203         if hasattr(self.code, 'co_firstlineno'):
00204             lineno = self.code.co_firstlineno - 1
00205             while lineno > 0:
00206                 if _funcdef_re.match(lines[lineno].code):
00207                     break
00208                 lineno -= 1
00209             try:
00210                 offset = len(inspect.getblock([x.code + '\n' for x
00211                                                in lines[lineno:]]))
00212             except TokenError:
00213                 offset = 0
00214             for line in lines[lineno:lineno + offset]:
00215                 line.in_frame = True
00216 
00217         # mark current line
00218         try:
00219             lines[self.lineno - 1].current = True
00220         except IndexError:
00221             pass
00222 
00223         return render_template('source.html', frame=self, lines=lines)

Here is the call graph for this function:

The sourcecode of the file as list of unicode strings.

Definition at line 235 of file tbtools.py.

00235 
00236     def sourcelines(self):
00237         """The sourcecode of the file as list of unicode strings."""
00238         # get sourcecode from loader or file
00239         source = None
00240         if self.loader is not None:
00241             try:
00242                 if hasattr(self.loader, 'get_source'):
00243                     source = self.loader.get_source(self.module)
00244                 elif hasattr(self.loader, 'get_source_by_code'):
00245                     source = self.loader.get_source_by_code(self.code)
00246             except:
00247                 # we munch the exception so that we don't cause troubles
00248                 # if the loader is broken.
00249                 pass
00250 
00251         if source is None:
00252             try:
00253                 f = file(self.filename)
00254             except IOError:
00255                 return []
00256             try:
00257                 source = f.read()
00258             finally:
00259                 f.close()
00260 
00261         # already unicode?  return right away
00262         if isinstance(source, unicode):
00263             return source.splitlines()
00264 
00265         # yes. it should be ascii, but we don't want to reject too many
00266         # characters in the debugger if something breaks
00267         charset = 'utf-8'
00268         if source.startswith(UTF8_COOKIE):
00269             source = source[3:]
00270         else:
00271             for idx, match in enumerate(_line_re.finditer(source)):
00272                 match = _line_re.search(match.group())
00273                 if match is not None:
00274                     charset = match.group(1)
00275                     break
00276                 if idx > 1:
00277                     break
00278 
00279         # on broken cookies we fall back to utf-8 too
00280         try:
00281             codecs.lookup(charset)
00282         except LookupError:
00283             charset = 'utf-8'
00284 
00285         return source.decode(charset, 'replace').splitlines()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 181 of file tbtools.py.

Definition at line 178 of file tbtools.py.

Definition at line 168 of file tbtools.py.

Definition at line 170 of file tbtools.py.

Definition at line 184 of file tbtools.py.

Definition at line 191 of file tbtools.py.

Definition at line 167 of file tbtools.py.

Definition at line 180 of file tbtools.py.

Definition at line 169 of file tbtools.py.

Definition at line 179 of file tbtools.py.


Property Documentation

MoinMoin.support.werkzeug.debug.tbtools.Frame.id = property(lambda x: id(x)) [static]

Definition at line 297 of file tbtools.py.


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