本文整理汇总了Python中copy.Error方法的典型用法代码示例。如果您正苦于以下问题:Python copy.Error方法的具体用法?Python copy.Error怎么用?Python copy.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类copy
的用法示例。
在下文中一共展示了copy.Error方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def copy(x):
"""Shallow copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
"""
cls = type(x)
copier = _copy_dispatch.get(cls)
if copier:
return copier(x)
copier = getattr(cls, "__copy__", None)
if copier:
return copier(x)
reductor = dispatch_table.get(cls)
if reductor:
rv = reductor(x)
else:
reductor = getattr(x, "__reduce_ex__", None)
if reductor:
rv = reductor(2)
else:
reductor = getattr(x, "__reduce__", None)
if reductor:
rv = reductor()
else:
raise Error("un(shallow)copyable object of type %s" % cls)
return _reconstruct(x, rv, 0)
示例2: test_infix_binops
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_infix_binops(self):
for ia, a in enumerate(candidates):
for ib, b in enumerate(candidates):
results = infix_results[(ia, ib)]
for op, res, ires in zip(infix_binops, results[0], results[1]):
if res is TE:
self.assertRaises(TypeError, eval,
'a %s b' % op, {'a': a, 'b': b})
else:
self.assertEqual(format_result(res),
format_result(eval('a %s b' % op)),
'%s %s %s == %s failed' % (a, op, b, res))
try:
z = copy.copy(a)
except copy.Error:
z = a # assume it has no inplace ops
if ires is TE:
try:
exec 'z %s= b' % op
except TypeError:
pass
else:
self.fail("TypeError not raised")
else:
exec('z %s= b' % op)
self.assertEqual(ires, z)
示例3: test_exceptions
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_exceptions(self):
self.assertTrue(copy.Error is copy.error)
self.assertTrue(issubclass(copy.Error, Exception))
# The copy() method
示例4: test_copy_cant
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_copy_cant(self):
class C(object):
def __getattribute__(self, name):
if name.startswith("__reduce"):
raise AttributeError, name
return object.__getattribute__(self, name)
x = C()
self.assertRaises(copy.Error, copy.copy, x)
# Type-specific _copy_xxx() methods
示例5: copy
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def copy(x):
"""Shallow copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
"""
cls = type(x)
copier = _copy_dispatch.get(cls)
if copier:
return copier(x)
try:
issc = issubclass(cls, type)
except TypeError: # cls is not a class
issc = False
if issc:
# treat it as a regular class:
return _copy_immutable(x)
copier = getattr(cls, "__copy__", None)
if copier:
return copier(x)
reductor = dispatch_table.get(cls)
if reductor:
rv = reductor(x)
else:
reductor = getattr(x, "__reduce_ex__", None)
if reductor:
rv = reductor(4)
else:
reductor = getattr(x, "__reduce__", None)
if reductor:
rv = reductor()
else:
raise Error("un(shallow)copyable object of type %s" % cls)
return _reconstruct(x, rv, 0)
示例6: copy
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def copy(x):
"""Shallow copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
"""
cls = type(x)
copier = _copy_dispatch.get(cls)
if copier:
return copier(x)
try:
issc = issubclass(cls, type)
except TypeError: # cls is not a class
issc = False
if issc:
# treat it as a regular class:
return _copy_immutable(x)
copier = getattr(cls, "__copy__", None)
if copier:
return copier(x)
reductor = dispatch_table.get(cls)
if reductor:
rv = reductor(x)
else:
reductor = getattr(x, "__reduce_ex__", None)
if reductor:
rv = reductor(4)
else:
reductor = getattr(x, "__reduce__", None)
if reductor:
rv = reductor()
else:
raise Error("un(shallow)copyable object of type %s" % cls)
if isinstance(rv, str):
return x
return _reconstruct(x, None, *rv)
示例7: test_exceptions
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_exceptions(self):
self.assertIs(copy.Error, copy.error)
self.assertTrue(issubclass(copy.Error, Exception))
# The copy() method
示例8: test_copy_cant
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_copy_cant(self):
class C(object):
def __getattribute__(self, name):
if name.startswith("__reduce"):
raise AttributeError(name)
return object.__getattribute__(self, name)
x = C()
self.assertRaises(copy.Error, copy.copy, x)
# Type-specific _copy_xxx() methods
示例9: test_deepcopy_cant
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def test_deepcopy_cant(self):
class C(object):
def __getattribute__(self, name):
if name.startswith("__reduce"):
raise AttributeError(name)
return object.__getattribute__(self, name)
x = C()
self.assertRaises(copy.Error, copy.deepcopy, x)
# Type-specific _deepcopy_xxx() methods
示例10: copy
# 需要导入模块: import copy [as 别名]
# 或者: from copy import Error [as 别名]
def copy(x):
"""Shallow copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
"""
cls = type(x)
copier = _copy_dispatch.get(cls)
if copier:
return copier(x)
try:
issc = issubclass(cls, type)
except TypeError: # cls is not a class
issc = False
if issc:
# treat it as a regular class:
return _copy_immutable(x)
copier = getattr(cls, "__copy__", None)
if copier:
return copier(x)
reductor = dispatch_table.get(cls)
if reductor:
rv = reductor(x)
else:
reductor = getattr(x, "__reduce_ex__", None)
if reductor:
rv = reductor(2)
else:
reductor = getattr(x, "__reduce__", None)
if reductor:
rv = reductor()
else:
raise Error("un(shallow)copyable object of type %s" % cls)
return _reconstruct(x, rv, 0)