~inkscape.dev/inkscape-devlibs/trunk

« back to all changes in this revision

Viewing changes to python/Lib/lib2to3/fixes/fix_sys_exc.py

  • Committer: Eduard Braun
  • Date: 2016-10-22 16:54:41 UTC
  • Revision ID: eduard.braun2@gmx.de-20161022165441-gfp6agtut9nh4p22
Update Python to version 2.7.12

Included modules:
  coverage 4.2
  lxml 3.6.4
  numpy 1.11.2
  scour 0.35
  six 1.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 = [u"exc_type", u"exc_value", u"exc_traceback"]
17
 
    BM_compatible = True
18
 
    PATTERN = """
19
 
              power< 'sys' trailer< dot='.' attribute=(%s) > >
20
 
              """ % '|'.join("'%s'" % e for e in exc_info)
21
 
 
22
 
    def transform(self, node, results):
23
 
        sys_attr = results["attribute"][0]
24
 
        index = Number(self.exc_info.index(sys_attr.value))
25
 
 
26
 
        call = Call(Name(u"exc_info"), prefix=sys_attr.prefix)
27
 
        attr = Attr(Name(u"sys"), call)
28
 
        attr[1].children[0].prefix = results["dot"].prefix
29
 
        attr.append(Subscript(index))
30
 
        return Node(syms.power, attr, prefix=node.prefix)
 
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 = [u"exc_type", u"exc_value", u"exc_traceback"]
 
17
    BM_compatible = True
 
18
    PATTERN = """
 
19
              power< 'sys' trailer< dot='.' attribute=(%s) > >
 
20
              """ % '|'.join("'%s'" % e for e in exc_info)
 
21
 
 
22
    def transform(self, node, results):
 
23
        sys_attr = results["attribute"][0]
 
24
        index = Number(self.exc_info.index(sys_attr.value))
 
25
 
 
26
        call = Call(Name(u"exc_info"), prefix=sys_attr.prefix)
 
27
        attr = Attr(Name(u"sys"), call)
 
28
        attr[1].children[0].prefix = results["dot"].prefix
 
29
        attr.append(Subscript(index))
 
30
        return Node(syms.power, attr, prefix=node.prefix)