home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / fix_sys_exc.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  1.0 KB  |  30 lines

  1. """Fixer for sys.exc_{type, value, traceback}
  2.  
  3. sys.exc_type -> sys.exc_info()[0]
  4. sys.exc_value -> sys.exc_info()[1]
  5. sys.exc_traceback -> sys.exc_info()[2]
  6. """
  7.  
  8. # By Jeff Balogh and Benjamin Peterson
  9.  
  10. # Local imports
  11. from .. import fixer_base
  12. from ..fixer_util import Attr, Call, Name, Number, Subscript, Node, syms
  13.  
  14. class FixSysExc(fixer_base.BaseFix):
  15.     # This order matches the ordering of sys.exc_info().
  16.     exc_info = ["exc_type", "exc_value", "exc_traceback"]
  17.     PATTERN = """
  18.               power< 'sys' trailer< dot='.' attribute=(%s) > >
  19.               """ % '|'.join("'%s'" % e for e in exc_info)
  20.  
  21.     def transform(self, node, results):
  22.         sys_attr = results["attribute"][0]
  23.         index = Number(self.exc_info.index(sys_attr.value))
  24.  
  25.         call = Call(Name("exc_info"), prefix=sys_attr.get_prefix())
  26.         attr = Attr(Name("sys"), call)
  27.         attr[1].children[0].set_prefix(results["dot"].get_prefix())
  28.         attr.append(Subscript(index))
  29.         return Node(syms.power, attr, prefix=node.get_prefix())
  30.