本文整理匯總了Python中weakref.CallableProxyType方法的典型用法代碼示例。如果您正苦於以下問題:Python weakref.CallableProxyType方法的具體用法?Python weakref.CallableProxyType怎麽用?Python weakref.CallableProxyType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weakref
的用法示例。
在下文中一共展示了weakref.CallableProxyType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_callable_proxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import CallableProxyType [as 別名]
def test_callable_proxy(self):
o = Callable()
ref1 = weakref.proxy(o)
self.check_proxy(o, ref1)
self.assertIs(type(ref1), weakref.CallableProxyType,
"proxy is not of callable type")
ref1('twinkies!')
self.assertEqual(o.bar, 'twinkies!',
"call through proxy not passed through to original")
ref1(x='Splat.')
self.assertEqual(o.bar, 'Splat.',
"call through proxy not passed through to original")
# expect due to too few args
self.assertRaises(TypeError, ref1)
# expect due to too many args
self.assertRaises(TypeError, ref1, 1, 2, 3)
示例2: test_callable_proxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import CallableProxyType [as 別名]
def test_callable_proxy(self):
o = Callable()
ref1 = weakref.proxy(o)
self.check_proxy(o, ref1)
self.assertTrue(type(ref1) is weakref.CallableProxyType,
"proxy is not of callable type")
ref1('twinkies!')
self.assertTrue(o.bar == 'twinkies!',
"call through proxy not passed through to original")
ref1(x='Splat.')
self.assertTrue(o.bar == 'Splat.',
"call through proxy not passed through to original")
# expect due to too few args
self.assertRaises(TypeError, ref1)
# expect due to too many args
self.assertRaises(TypeError, ref1, 1, 2, 3)
示例3: test_callable_proxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import CallableProxyType [as 別名]
def test_callable_proxy(self):
o = Callable()
ref1 = weakref.proxy(o)
self.check_proxy(o, ref1)
self.assert_(type(ref1) is weakref.CallableProxyType,
"proxy is not of callable type")
ref1('twinkies!')
self.assert_(o.bar == 'twinkies!',
"call through proxy not passed through to original")
ref1(x='Splat.')
self.assert_(o.bar == 'Splat.',
"call through proxy not passed through to original")
# expect due to too few args
self.assertRaises(TypeError, ref1)
# expect due to too many args
self.assertRaises(TypeError, ref1, 1, 2, 3)
示例4: save_weakproxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import CallableProxyType [as 別名]
def save_weakproxy(pickler, obj):
refobj = _locate_object(_proxy_helper(obj))
try: log.info("R2: %s" % obj)
except ReferenceError: log.info("R3: %s" % sys.exc_info()[1])
#callable = bool(getattr(refobj, '__call__', None))
if type(obj) is CallableProxyType: callable = True
else: callable = False
pickler.save_reduce(_create_weakproxy, (refobj, callable), obj=obj)
return
示例5: CheckCursorConnection
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import CallableProxyType [as 別名]
def CheckCursorConnection(self):
if not isinstance(self.cur.connection, weakref.ProxyType) and \
not isinstance(self.cur.connection, weakref.CallableProxyType):
fail("cursor.connection doesn't return the correct type")