本文整理匯總了Python中weakref.proxy方法的典型用法代碼示例。如果您正苦於以下問題:Python weakref.proxy方法的具體用法?Python weakref.proxy怎麽用?Python weakref.proxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weakref
的用法示例。
在下文中一共展示了weakref.proxy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, path):
package_name = '_jinja2_module_templates_%x' % id(self)
# create a fake module that looks for the templates in the
# path given.
mod = _TemplateModule(package_name)
if isinstance(path, string_types):
path = [path]
else:
path = list(path)
mod.__path__ = path
sys.modules[package_name] = weakref.proxy(mod,
lambda x: sys.modules.pop(package_name, None))
# the only strong reference, the sys.modules entry is weak
# so that the garbage collector can remove it once the
# loader that created it goes out of business.
self.module = mod
self.package_name = package_name
示例2: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, *args, **kwds):
'''Initialize an ordered dictionary. The signature is the same as
regular dictionaries, but keyword arguments are not recommended because
their insertion order is arbitrary.
'''
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__root
except AttributeError:
self.__hardroot = _Link()
self.__root = root = _proxy(self.__hardroot)
root.prev = root.next = root
self.__map = {}
self.__update(*args, **kwds)
示例3: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, connection):
"""Initialize"""
MySQLCursorAbstract.__init__(self)
self._insert_id = 0
self._warning_count = 0
self._warnings = None
self._affected_rows = -1
self._rowcount = -1
self._nextrow = None
self._executed = None
self._executed_list = []
self._stored_results = []
if not isinstance(connection, MySQLConnectionAbstract):
raise errors.InterfaceError(errno=2048)
self._cnx = weakref.proxy(connection)
示例4: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, protocol, _type, _id, name="World Server 1", _max=300, server_protocol = AS3_PROTOCOL):
self.protocol = protocol
self.server_protocol = server_protocol
self.type = _type
self.id = _id
self.logger = logging.getLogger(TIMELINE_LOGGER)
self.name = name
self.users = deque() # Thread safe
self.dbDetails = dict()
self.maximum = _max - 1
self._listening = False
self._portListener = None
self.proxyReference = weakref.proxy(self)
self.redis = Redis(self)
self.log("info", "Timeline Factory Started!")
self.log("info", "Running:", self.name)
self.log("info", "Maximum users:", self.maximum)
if self.type == WORLD_SERVER:
self.initializeWorld()
self.redis.redisConnectionDefer.addCallback(lambda *x: GeneralEvent('onEngine', self))
示例5: buildPenguin
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def buildPenguin(self):
self.handshakeStage = -1
self.canRecvPacket = False
self.ReceivePacketEnabled = True # Penguin can receive packet only if both this and self.canRecvPacket is true.
# Some XT packets are sent before J#JS to make sure client is alive, just to make sure to ignore it ;)
# ('category', 'handler', 0 or 1 : execute : don't execute)
self.ignorableXTPackets = [('s', 'j#js', 1), ('s', 'p#getdigcooldown', 0), ('s', 'u#h', 0), ('s', 'f#epfgf', 0), ('l', 'login', 1)]
self.penguin = PenguinObject()
self.penguin.name = None
self.penguin.id = None
self.penguin.room = None
self.penguin.prevRooms = list()
self.ref = weakref.proxy(self)
# Initiate Packet Handler
self.PacketHandler = PacketHandler(self.ref)
self.CryptoHandler = Crypto(self.ref)
示例6: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(
self, ds,
fp, dtype, channel_count, channels_schema, sr,
compute_array, merge_arrays,
cache_dir, overwrite,
primitives_back, primitives_kwargs, convert_footprint_per_primitive,
computation_pool, merge_pool, io_pool, resample_pool,
cache_tiles, computation_tiles,
max_resampling_size,
debug_observers,
):
back = BackCachedRasterRecipe(
ds._back,
weakref.proxy(self),
fp, dtype, channel_count, channels_schema, sr,
compute_array, merge_arrays,
cache_dir, overwrite,
primitives_back, primitives_kwargs, convert_footprint_per_primitive,
computation_pool, merge_pool, io_pool, resample_pool,
cache_tiles, computation_tiles,
max_resampling_size,
debug_observers,
)
super().__init__(ds=ds, back=back)
示例7: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, max_size=10, kill_cb=None, lock=False):
"""Constructor.
Args:
max_size: The maximum number of objects held in cache.
kill_cb: An optional function which will be called on each
object terminated from cache.
lock: If True this cache will be thread safe.
"""
self._age = LinkedList()
self._hash = {}
self._limit = max_size
self._kill_cb = kill_cb
self.lock = None
if lock:
self.lock = threading.RLock()
self.hits = self.misses = 0
self.creator = GetStack()
self.STORES[id(self)] = weakref.proxy(
self, lambda _, id=id(self), s=self.STORES: s.pop(id))
示例8: logging
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def logging(self):
if self.logger is not None:
return self.logger
logger_name = u"rekall.%s" % self.session_id
if self._logger is None or self._logger.name != logger_name:
# Set up a logging object. All rekall logging must be done
# through the session's logger.
self._logger = logging.getLogger(logger_name)
# A special log handler that hoards all messages until there's a
# renderer that can transport them.
self._log_handler = HoardingLogHandler()
# Since the logger is a global it must not hold a permanent
# reference to the HoardingLogHandler, otherwise we may never be
# collected.
def Remove(_, l=self._log_handler):
l.handlers = []
self._logger.addHandler(weakref.proxy(
self._log_handler, Remove))
return self._logger
示例9: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, application, window):
utilities.assert_arg_type(application, Gtk.Application, arg_pos=1)
utilities.assert_arg_type(window, MainAppWindow, arg_pos=2)
super(MainMenuBar, self).__init__(application)
self.window = weakref.proxy(window)
self._add_accelerators()
graphs_menu_item = self.gtk_builder_get('menuitem_tools_create_graph')
if graphs.has_matplotlib:
graphs_submenu = Gtk.Menu.new()
for graph_name in graphs.get_graphs():
graph = graphs.get_graph(graph_name)
menu_item = Gtk.MenuItem.new_with_label(graph.name_human)
menu_item.connect('activate', self.signal_activate_tools_show_campaign_graph, graph_name)
graphs_submenu.append(menu_item)
graphs_menu_item.set_submenu(graphs_submenu)
graphs_menu_item.show_all()
else:
graphs_menu_item.set_sensitive(False)
示例10: __init__
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def __init__(self, parent_message):
"""Args:
parent_message: The message whose _Modified() method we should call when
we receive Modified() messages.
"""
# This listener establishes a back reference from a child (contained) object
# to its parent (containing) object. We make this a weak reference to avoid
# creating cyclic garbage when the client finishes with the 'parent' object
# in the tree.
if isinstance(parent_message, weakref.ProxyType):
self._parent_message_weakref = parent_message
else:
self._parent_message_weakref = weakref.proxy(parent_message)
# As an optimization, we also indicate directly on the listener whether
# or not the parent message is dirty. This way we can avoid traversing
# up the tree in the common case.
self.dirty = False
示例11: test_ref_reuse
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def test_ref_reuse(self):
o = C()
ref1 = weakref.ref(o)
# create a proxy to make sure that there's an intervening creation
# between these two; it should make no difference
proxy = weakref.proxy(o)
ref2 = weakref.ref(o)
self.assertIs(ref1, ref2,
"reference object w/out callback should be re-used")
o = C()
proxy = weakref.proxy(o)
ref1 = weakref.ref(o)
ref2 = weakref.ref(o)
self.assertIs(ref1, ref2,
"reference object w/out callback should be re-used")
self.assertEqual(weakref.getweakrefcount(o), 2,
"wrong weak ref count for object")
del proxy
self.assertEqual(weakref.getweakrefcount(o), 1,
"wrong weak ref count for object after deleting proxy")
示例12: test_proxy_div
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def test_proxy_div(self):
class C:
def __floordiv__(self, other):
return 42
def __ifloordiv__(self, other):
return 21
o = C()
p = weakref.proxy(o)
self.assertEqual(p // 5, 42)
p //= 5
self.assertEqual(p, 21)
# The PyWeakref_* C API is documented as allowing either NULL or
# None as the value for the callback, where either means "no
# callback". The "no callback" ref and proxy objects are supposed
# to be shared so long as they exist by all callers so long as
# they are active. In Python 2.3.3 and earlier, this guarantee
# was not honored, and was broken in different ways for
# PyWeakref_NewRef() and PyWeakref_NewProxy(). (Two tests.)
示例13: test_callable_proxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [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)
示例14: check_proxy
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def check_proxy(self, o, proxy):
o.foo = 1
self.assertEqual(proxy.foo, 1,
"proxy does not reflect attribute addition")
o.foo = 2
self.assertEqual(proxy.foo, 2,
"proxy does not reflect attribute modification")
del o.foo
self.assertFalse(hasattr(proxy, 'foo'),
"proxy does not reflect attribute removal")
proxy.foo = 1
self.assertEqual(o.foo, 1,
"object does not reflect attribute addition via proxy")
proxy.foo = 2
self.assertEqual(o.foo, 2,
"object does not reflect attribute modification via proxy")
del proxy.foo
self.assertFalse(hasattr(o, 'foo'),
"object does not reflect attribute removal via proxy")
示例15: test_getweakrefcount
# 需要導入模塊: import weakref [as 別名]
# 或者: from weakref import proxy [as 別名]
def test_getweakrefcount(self):
o = C()
ref1 = weakref.ref(o)
ref2 = weakref.ref(o, self.callback)
self.assertEqual(weakref.getweakrefcount(o), 2,
"got wrong number of weak reference objects")
proxy1 = weakref.proxy(o)
proxy2 = weakref.proxy(o, self.callback)
self.assertEqual(weakref.getweakrefcount(o), 4,
"got wrong number of weak reference objects")
del ref1, ref2, proxy1, proxy2
self.assertEqual(weakref.getweakrefcount(o), 0,
"weak reference objects not unlinked from"
" referent when discarded.")
# assumes ints do not support weakrefs
self.assertEqual(weakref.getweakrefcount(1), 0,
"got wrong number of weak reference objects for int")