Python copyreg.foo() Examples
The following are 30
code examples of copyreg.foo().
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
copyreg
, or try the search function
.
Example #1
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_while(self): b = """while 1: foo()""" a = """while True: foo()""" self.check(b, a) b = """while 1: foo()""" a = """while True: foo()""" self.check(b, a) b = """ while 1: foo() """ a = """ while True: foo() """ self.check(b, a)
Example #2
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_tuple_unpack(self): b = """ def foo(): try: pass except Exception, (f, e): pass except ImportError, e: pass""" a = """ def foo(): try: pass except Exception as xxx_todo_changeme: (f, e) = xxx_todo_changeme.args pass except ImportError as e: pass""" self.check(b, a)
Example #3
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_remove_multiple_items(self): b = """isinstance(x, (int, int, int))""" a = """isinstance(x, int)""" self.check(b, a) b = """isinstance(x, (int, float, int, int, float))""" a = """isinstance(x, (int, float))""" self.check(b, a) b = """isinstance(x, (int, float, int, int, float, str))""" a = """isinstance(x, (int, float, str))""" self.check(b, a) b = """isinstance(foo() + bar(), (x(), y(), x(), int, int))""" a = """isinstance(foo() + bar(), (x(), y(), x(), int))""" self.check(b, a)
Example #4
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_wrap_in_list(self): b = """x = range(10, 3, 9)""" a = """x = list(range(10, 3, 9))""" self.check(b, a) b = """x = foo(range(10, 3, 9))""" a = """x = foo(list(range(10, 3, 9)))""" self.check(b, a) b = """x = range(10, 3, 9) + [4]""" a = """x = list(range(10, 3, 9)) + [4]""" self.check(b, a) b = """x = range(10)[::-1]""" a = """x = list(range(10))[::-1]""" self.check(b, a) b = """x = range(10) [3]""" a = """x = list(range(10)) [3]""" self.check(b, a)
Example #5
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_import_from(self): for old, changes in self.modules.items(): all_members = [] for new, members in changes: for member in members: all_members.append(member) b = "from %s import %s" % (old, member) a = "from %s import %s" % (new, member) self.check(b, a) s = "from foo import %s" % member self.unchanged(s) b = "from %s import %s" % (old, ", ".join(members)) a = "from %s import %s" % (new, ", ".join(members)) self.check(b, a) s = "from foo import %s" % ", ".join(members) self.unchanged(s) # test the breaking of a module into multiple replacements b = "from %s import %s" % (old, ", ".join(all_members)) a = "\n".join(["from %s import %s" % (new, ", ".join(members)) for (new, members) in changes]) self.check(b, a)
Example #6
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_indented(self): b = """ def foo(): from urllib import urlencode, urlopen """ a = """ def foo(): from urllib.parse import urlencode from urllib.request import urlopen """ self.check(b, a) b = """ def foo(): other() from urllib import urlencode, urlopen """ a = """ def foo(): other() from urllib.parse import urlencode from urllib.request import urlopen """ self.check(b, a)
Example #7
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_import_module_usage(self): for old, changes in self.modules.items(): for new, members in changes: for member in members: new_import = ", ".join([n for (n, mems) in self.modules[old]]) b = """ import %s foo(%s.%s) """ % (old, old, member) a = """ import %s foo(%s.%s) """ % (new_import, new, member) self.check(b, a) b = """ import %s %s.%s(%s.%s) """ % (old, old, member, old, member) a = """ import %s %s.%s(%s.%s) """ % (new_import, new, member, new, member) self.check(b, a)
Example #8
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_prefix_preservation_4(self): b = """ next = 5 for a in b: foo(a) # abc # def a.next() """ a = """ next = 5 for a in b: foo(a) # abc # def a.__next__() """ self.check(b, a, ignore_warnings=True)
Example #9
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 6 votes |
def test_method_4(self): b = """ class A: def __init__(self, foo): self.foo = foo def next(self): pass def __iter__(self): return self """ a = """ class A: def __init__(self, foo): self.foo = foo def __next__(self): pass def __iter__(self): return self """ self.check(b, a)
Example #10
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_prefix_preservation(self): b = """x = filter( foo, 'abc' )""" a = """x = list(filter( foo, 'abc' ))""" self.check(b, a) b = """x = filter( None , 'abc' )""" a = """x = [_f for _f in 'abc' if _f]""" self.check(b, a)
Example #11
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_trailing_comment(self): b = """x = map(f, 'abc') # foo""" a = """x = list(map(f, 'abc')) # foo""" self.check(b, a)
Example #12
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def XXX_test_from_import_usage(self): # not implemented yet for mod, (old, new) in list(self.modules.items()): b = """ from %s import %s foo(%s, %s) """ % (mod, old, mod, old) a = """ from %s import %s foo(%s, %s) """ % (mod, new, mod, new) self.check(b, a)
Example #13
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_shadowing_assign_tuple_2(self): s = """ (a, (b, (next, c)), a) = foo class A: def next(self, a, b): pass """ self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
Example #14
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_shadowing_assign_tuple_1(self): s = """ (next, a) = foo class A: def next(self, a, b): pass """ self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
Example #15
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_weird_target_2(self): b = """ try: pass except Exception, a.foo: pass""" a = """ try: pass except Exception as xxx_todo_changeme: a.foo = xxx_todo_changeme pass""" self.check(b, a)
Example #16
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_prefix_preservation_6(self): b = """ for a in b: foo(foo(a), # abc a.next()) """ a = """ for a in b: foo(foo(a), # abc next(a)) """ self.check(b, a)
Example #17
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_prefix_preservation_5(self): b = """ next = 5 for a in b: foo(foo(a), # abc a.next()) """ a = """ next = 5 for a in b: foo(foo(a), # abc a.__next__()) """ self.check(b, a, ignore_warnings=True)
Example #18
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_weird_target_3(self): b = """ try: pass except Exception, a().foo: pass""" a = """ try: pass except Exception as xxx_todo_changeme: a().foo = xxx_todo_changeme pass""" self.check(b, a)
Example #19
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_prefix_preservation_3(self): b = """ next = 5 for a in b: foo(a) a.next() """ a = """ next = 5 for a in b: foo(a) a.__next__() """ self.check(b, a, ignore_warnings=True)
Example #20
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_prefix_preservation_1(self): b = """ for a in b: foo(a) a.next() """ a = """ for a in b: foo(a) next(a) """ self.check(b, a)
Example #21
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_unchanged(self): for attr in self.attrs: s = "foo(im_%s + 5)" % attr self.unchanged(s) s = "f(foo.__%s__)" % attr self.unchanged(s) s = "f(foo.__%s__.foo)" % attr self.unchanged(s)
Example #22
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test(self): for attr in self.attrs: b = "a.im_%s" % attr if attr == "class": a = "a.__self__.__class__" else: a = "a.__%s__" % attr self.check(b, a) b = "self.foo.im_%s.foo_bar" % attr if attr == "class": a = "self.foo.__self__.__class__.foo_bar" else: a = "self.foo.__%s__.foo_bar" % attr self.check(b, a)
Example #23
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_docstring(self): b = """ def foo(((a, b), c), (d, e, f)) -> z: "foo foo foo foo" x = 5""" a = """ def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z: "foo foo foo foo" ((a, b), c) = xxx_todo_changeme (d, e, f) = xxx_todo_changeme1 x = 5""" self.check(b, a)
Example #24
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_multi_2(self): b = """ def foo(x, ((a, b), c), d, (e, f, g), y) -> z: x = 5""" a = """ def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z: ((a, b), c) = xxx_todo_changeme (e, f, g) = xxx_todo_changeme1 x = 5""" self.check(b, a)
Example #25
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_varargs(self): b = """ def foo(((a, b), c), d, *vargs, **kwargs) -> z: x = 5""" a = """ def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z: ((a, b), c) = xxx_todo_changeme x = 5""" self.check(b, a)
Example #26
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_keywords(self): b = """ def foo(((a, b), c), d, e=5) -> z: x = 5""" a = """ def foo(xxx_todo_changeme, d, e=5) -> z: ((a, b), c) = xxx_todo_changeme x = 5""" self.check(b, a)
Example #27
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_semicolon(self): b = """ def foo(((a, b), c)): x = 5; y = 7""" a = """ def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7""" self.check(b, a)
Example #28
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_3(self): b = """ def foo(((a, b), c), d) -> e: x = 5""" a = """ def foo(xxx_todo_changeme, d) -> e: ((a, b), c) = xxx_todo_changeme x = 5""" self.check(b, a)
Example #29
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_2(self): b = """ def foo(((a, b), c), d): x = 5""" a = """ def foo(xxx_todo_changeme, d): ((a, b), c) = xxx_todo_changeme x = 5""" self.check(b, a)
Example #30
Source File: test_fixers.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def test_shadowing_assign_list_1(self): s = """ [next, a] = foo class A: def next(self, a, b): pass """ self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")