home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / traceback.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  8.7 KB  |  279 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import linecache
  5. import sys
  6. import types
  7. __all__ = [
  8.     'extract_stack',
  9.     'extract_tb',
  10.     'format_exception',
  11.     'format_exception_only',
  12.     'format_list',
  13.     'format_stack',
  14.     'format_tb',
  15.     'print_exc',
  16.     'print_exception',
  17.     'print_last',
  18.     'print_stack',
  19.     'print_tb',
  20.     'tb_lineno']
  21.  
  22. def _print(file, str = '', terminator = '\n'):
  23.     file.write(str + terminator)
  24.  
  25.  
  26. def print_list(extracted_list, file = None):
  27.     if not file:
  28.         file = sys.stderr
  29.     
  30.     for filename, lineno, name, line in extracted_list:
  31.         _print(file, '  File "%s", line %d, in %s' % (filename, lineno, name))
  32.         if line:
  33.             _print(file, '    %s' % line.strip())
  34.         
  35.     
  36.  
  37.  
  38. def format_list(extracted_list):
  39.     list = []
  40.     for filename, lineno, name, line in extracted_list:
  41.         item = '  File "%s", line %d, in %s\n' % (filename, lineno, name)
  42.         if line:
  43.             item = item + '    %s\n' % line.strip()
  44.         
  45.         list.append(item)
  46.     
  47.     return list
  48.  
  49.  
  50. def print_tb(tb, limit = None, file = None):
  51.     if not file:
  52.         file = sys.stderr
  53.     
  54.     if limit is None:
  55.         if hasattr(sys, 'tracebacklimit'):
  56.             limit = sys.tracebacklimit
  57.         
  58.     
  59.     n = 0
  60.     while tb is not None and limit is None or n < limit:
  61.         f = tb.tb_frame
  62.         lineno = tb_lineno(tb)
  63.         co = f.f_code
  64.         filename = co.co_filename
  65.         name = co.co_name
  66.         _print(file, '  File "%s", line %d, in %s' % (filename, lineno, name))
  67.         line = linecache.getline(filename, lineno)
  68.         if line:
  69.             _print(file, '    ' + line.strip())
  70.         
  71.         tb = tb.tb_next
  72.         n = n + 1
  73.  
  74.  
  75. def format_tb(tb, limit = None):
  76.     return format_list(extract_tb(tb, limit))
  77.  
  78.  
  79. def extract_tb(tb, limit = None):
  80.     if limit is None:
  81.         if hasattr(sys, 'tracebacklimit'):
  82.             limit = sys.tracebacklimit
  83.         
  84.     
  85.     list = []
  86.     n = 0
  87.     while tb is not None and limit is None or n < limit:
  88.         f = tb.tb_frame
  89.         lineno = tb_lineno(tb)
  90.         co = f.f_code
  91.         filename = co.co_filename
  92.         name = co.co_name
  93.         line = linecache.getline(filename, lineno)
  94.         if line:
  95.             line = line.strip()
  96.         else:
  97.             line = None
  98.         list.append((filename, lineno, name, line))
  99.         tb = tb.tb_next
  100.         n = n + 1
  101.     return list
  102.  
  103.  
  104. def print_exception(etype, value, tb, limit = None, file = None):
  105.     if not file:
  106.         file = sys.stderr
  107.     
  108.     if tb:
  109.         _print(file, 'Traceback (most recent call last):')
  110.         print_tb(tb, limit, file)
  111.     
  112.     lines = format_exception_only(etype, value)
  113.     for line in lines[:-1]:
  114.         _print(file, line, ' ')
  115.     
  116.     _print(file, lines[-1], '')
  117.  
  118.  
  119. def format_exception(etype, value, tb, limit = None):
  120.     if tb:
  121.         list = [
  122.             'Traceback (most recent call last):\n']
  123.         list = list + format_tb(tb, limit)
  124.     else:
  125.         list = []
  126.     list = list + format_exception_only(etype, value)
  127.     return list
  128.  
  129.  
  130. def format_exception_only(etype, value):
  131.     list = []
  132.     if type(etype) == types.ClassType:
  133.         stype = etype.__name__
  134.     else:
  135.         stype = etype
  136.     if value is None:
  137.         list.append(str(stype) + '\n')
  138.     elif etype is SyntaxError:
  139.         
  140.         try:
  141.             (filename, lineno, offset, line) = (msg,)
  142.         except:
  143.             pass
  144.  
  145.         if not filename:
  146.             filename = '<string>'
  147.         
  148.         list.append('  File "%s", line %d\n' % (filename, lineno))
  149.         if line is not None:
  150.             i = 0
  151.             while i < len(line) and line[i].isspace():
  152.                 i = i + 1
  153.             list.append('    %s\n' % line.strip())
  154.             if offset is not None:
  155.                 s = '    '
  156.                 for c in line[i:offset - 1]:
  157.                     if c.isspace():
  158.                         s = s + c
  159.                     else:
  160.                         s = s + ' '
  161.                 
  162.                 list.append('%s^\n' % s)
  163.             
  164.             value = msg
  165.         
  166.     
  167.     s = _some_str(value)
  168.     if s:
  169.         list.append('%s: %s\n' % (str(stype), s))
  170.     else:
  171.         list.append('%s\n' % str(stype))
  172.     return list
  173.  
  174.  
  175. def _some_str(value):
  176.     
  177.     try:
  178.         return str(value)
  179.     except:
  180.         return '<unprintable %s object>' % type(value).__name__
  181.  
  182.  
  183.  
  184. def print_exc(limit = None, file = None):
  185.     if not file:
  186.         file = sys.stderr
  187.     
  188.     
  189.     try:
  190.         (etype, value, tb) = sys.exc_info()
  191.         print_exception(etype, value, tb, limit, file)
  192.     finally:
  193.         etype = value = tb = None
  194.  
  195.  
  196.  
  197. def print_last(limit = None, file = None):
  198.     if not file:
  199.         file = sys.stderr
  200.     
  201.     print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)
  202.  
  203.  
  204. def print_stack(f = None, limit = None, file = None):
  205.     if f is None:
  206.         
  207.         try:
  208.             raise ZeroDivisionError
  209.         except ZeroDivisionError:
  210.             f = sys.exc_info()[2].tb_frame.f_back
  211.  
  212.     
  213.     print_list(extract_stack(f, limit), file)
  214.  
  215.  
  216. def format_stack(f = None, limit = None):
  217.     if f is None:
  218.         
  219.         try:
  220.             raise ZeroDivisionError
  221.         except ZeroDivisionError:
  222.             f = sys.exc_info()[2].tb_frame.f_back
  223.  
  224.     
  225.     return format_list(extract_stack(f, limit))
  226.  
  227.  
  228. def extract_stack(f = None, limit = None):
  229.     if f is None:
  230.         
  231.         try:
  232.             raise ZeroDivisionError
  233.         except ZeroDivisionError:
  234.             f = sys.exc_info()[2].tb_frame.f_back
  235.  
  236.     
  237.     if limit is None:
  238.         if hasattr(sys, 'tracebacklimit'):
  239.             limit = sys.tracebacklimit
  240.         
  241.     
  242.     list = []
  243.     n = 0
  244.     while f is not None and limit is None or n < limit:
  245.         lineno = f.f_lineno
  246.         co = f.f_code
  247.         filename = co.co_filename
  248.         name = co.co_name
  249.         line = linecache.getline(filename, lineno)
  250.         if line:
  251.             line = line.strip()
  252.         else:
  253.             line = None
  254.         list.append((filename, lineno, name, line))
  255.         f = f.f_back
  256.         n = n + 1
  257.     list.reverse()
  258.     return list
  259.  
  260.  
  261. def tb_lineno(tb):
  262.     c = tb.tb_frame.f_code
  263.     if not hasattr(c, 'co_lnotab'):
  264.         return tb.tb_lineno
  265.     
  266.     tab = c.co_lnotab
  267.     line = c.co_firstlineno
  268.     stopat = tb.tb_lasti
  269.     addr = 0
  270.     for i in range(0, len(tab), 2):
  271.         addr = addr + ord(tab[i])
  272.         if addr > stopat:
  273.             break
  274.         
  275.         line = line + ord(tab[i + 1])
  276.     
  277.     return line
  278.  
  279.