home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd2.bin / convert / eJayMp3Pro / mp3pro_demo.exe / TRACEBACK.PYC (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-05  |  8.8 KB  |  237 lines

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