PHP 7.4.33
Preview: fix_raise.py Size: 2.86 KB
/home/godevadmin/public_html/upload_images/home/000~ROOT~000/lib64/python3.6/lib2to3/fixes/fix_raise.py

"""Fixer for 'raise E, V, T'

raise         -> raise
raise E       -> raise E
raise E, V    -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)

raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T               -> warns about string exceptions


CAVEATS:
1) "raise E, V" will be incorrectly translated if V is an exception
   instance. The correct Python 3 idiom is

        raise E from V

   but since we can't detect instance-hood by syntax alone and since
   any client code would have to be changed as well, we don't automate
   this.
"""
# Author: Collin Winter

# Local imports
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
from ..fixer_util import Name, Call, Attr, ArgList, is_tuple

class FixRaise(fixer_base.BaseFix):

    BM_compatible = True
    PATTERN = """
    raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] >
    """

    def transform(self, node, results):
        syms = self.syms

        exc = results["exc"].clone()
        if exc.type == token.STRING:
            msg = "Python 3 does not support string exceptions"
            self.cannot_convert(node, msg)
            return

        # Python 2 supports
        #  raise ((((E1, E2), E3), E4), E5), V
        # as a synonym for
        #  raise E1, V
        # Since Python 3 will not support this, we recurse down any tuple
        # literals, always taking the first element.
        if is_tuple(exc):
            while is_tuple(exc):
                # exc.children[1:-1] is the unparenthesized tuple
                # exc.children[1].children[0] is the first element of the tuple
                exc = exc.children[1].children[0].clone()
            exc.prefix = " "

        if "val" not in results:
            # One-argument raise
            new = pytree.Node(syms.raise_stmt, [Name("raise"), exc])
            new.prefix = node.prefix
            return new

        val = results["val"].clone()
        if is_tuple(val):
            args = [c.clone() for c in val.children[1:-1]]
        else:
            val.prefix = ""
            args = [val]

        if "tb" in results:
            tb = results["tb"].clone()
            tb.prefix = ""

            e = exc
            # If there's a traceback and None is passed as the value, then don't
            # add a call, since the user probably just wants to add a
            # traceback. See issue #9661.
            if val.type != token.NAME or val.value != "None":
                e = Call(exc, args)
            with_tb = Attr(e, Name('with_traceback')) + [ArgList([tb])]
            new = pytree.Node(syms.simple_stmt, [Name("raise")] + with_tb)
            new.prefix = node.prefix
            return new
        else:
            return pytree.Node(syms.raise_stmt,
                               [Name("raise"), Call(exc, args)],
                               prefix=node.prefix)

Directory Contents

Dirs: 1 × Files: 53

Name Size Perms Modified Actions
- drwxr-xr-x 2025-07-03 05:10:07
Edit Download
2.37 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
984 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
320 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
590 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.67 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.27 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
979 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.00 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.44 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.59 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
644 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
547 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
451 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.12 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
4.76 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.18 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
5.55 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
289 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
708 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.21 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.57 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.51 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.04 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
476 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.55 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
8.00 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
606 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
571 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.10 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
591 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
768 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
3.39 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.20 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.78 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.86 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
454 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
837 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.13 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.17 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
613 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.66 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
449 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.01 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.54 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
5.43 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.73 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.23 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
8.16 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.06 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
2.63 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
689 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download
1.26 KB lrw-r--r-- 2018-12-23 21:37:14
Edit Download
47 B lrw-r--r-- 2018-12-23 21:37:14
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).