Python lib2to3.fixer_util.is_tuple() Examples
The following are 30
code examples of lib2to3.fixer_util.is_tuple().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lib2to3.fixer_util
, or try the search function
.
Example #1
Source File: test_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #2
Source File: test_util.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #3
Source File: fix_raise.py From blackmamba with MIT License | 5 votes |
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 = u" " if "val" not in results: # One-argument raise new = pytree.Node(syms.raise_stmt, [Name(u"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 = u"" args = [val] return pytree.Node(syms.raise_stmt, [Name(u"raise"), Call(exc, args)], prefix=node.prefix)
Example #4
Source File: test_util.py From datafari with Apache License 2.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #5
Source File: test_util.py From datafari with Apache License 2.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #6
Source File: test_util.py From datafari with Apache License 2.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #7
Source File: test_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #8
Source File: test_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #9
Source File: test_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #10
Source File: test_util.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #11
Source File: test_util.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #12
Source File: test_util.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #13
Source File: test_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #14
Source File: test_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #15
Source File: test_util.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #16
Source File: test_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #17
Source File: test_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #18
Source File: fix_raise.py From gimp-plugin-export-layers with GNU General Public License v3.0 | 5 votes |
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 = u" " if "val" not in results: # One-argument raise new = pytree.Node(syms.raise_stmt, [Name(u"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 = u"" args = [val] return pytree.Node(syms.raise_stmt, [Name(u"raise"), Call(exc, args)], prefix=node.prefix)
Example #19
Source File: fix_raise.py From arissploit with GNU General Public License v3.0 | 5 votes |
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 = u" " if "val" not in results: # One-argument raise new = pytree.Node(syms.raise_stmt, [Name(u"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 = u"" args = [val] return pytree.Node(syms.raise_stmt, [Name(u"raise"), Call(exc, args)], prefix=node.prefix)
Example #20
Source File: test_util.py From android_universal with MIT License | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #21
Source File: test_util.py From android_universal with MIT License | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #22
Source File: test_util.py From android_universal with MIT License | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #23
Source File: test_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #24
Source File: test_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #25
Source File: test_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))
Example #26
Source File: test_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #27
Source File: test_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #28
Source File: test_util.py From oss-ftp with MIT License | 5 votes |
def is_tuple(self, string): return fixer_util.is_tuple(parse(string, strip_levels=2))
Example #29
Source File: test_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_valid(self): self.assertTrue(self.is_tuple("(a, b)")) self.assertTrue(self.is_tuple("(a, (b, c))")) self.assertTrue(self.is_tuple("((a, (b, c)),)")) self.assertTrue(self.is_tuple("(a,)")) self.assertTrue(self.is_tuple("()"))
Example #30
Source File: test_util.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_invalid(self): self.assertFalse(self.is_tuple("(a)")) self.assertFalse(self.is_tuple("('foo') % (b, c)"))