本文整理汇总了Python中weakref.weakref函数的典型用法代码示例。如果您正苦于以下问题:Python weakref函数的具体用法?Python weakref怎么用?Python weakref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了weakref函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, channel, level, msg, args=None, kwargs=None,
exc_info=None, extra=None, frame=None, dispatcher=None):
#: the name of the logger that created it or any other textual
#: channel description. This is a descriptive name and should not
#: be used for filtering. A log record might have a
#: :attr:`dispatcher` defined which provides more information for
#: filtering if this is absolutely necessary.
self.channel = channel
#: The message of the log record as new-style format string.
self.msg = msg
#: the positional arguments for the format string.
self.args = args or ()
#: the keyword arguments for the format string.
self.kwargs = kwargs or {}
#: the level of the log record as integer.
self.level = level
#: optional exception information. If set, this is a tuple in the
#: form ``(exc_type, exc_value, tb)`` as returned by
#: :func:`sys.exc_info`.
self.exc_info = exc_info
#: optional extra information as dictionary. This is the place
#: where custom log processors can attach custom context sensitive
#: data.
self.extra = ExtraDict(extra or ())
#: If available, optionally the interpreter frame that created the
#: log record. Might not be available for all calls and is removed
#: when the log record is closed.
self.frame = frame
#: the PID of the current process
self.process = os.getpid()
if dispatcher is not None:
dispatcher = weakref(dispatcher)
self._dispatcher = dispatcher
示例2: __init__
def __init__(self, ayum):
self.repos = {} # list of repos by repoid pointing a repo object
# of repo options/misc data
self.callback = None # progress callback used for populateSack() for importing the xml files
self.cache = 0
self.pkgSack = MetaSack()
self.logger = logging.getLogger("yum.RepoStorage")
self._setup = False
self.ayum = weakref(ayum)
# callbacks for handling gpg key imports for repomd.xml sig checks
# need to be set from outside of the repos object to do anything
# even quasi-useful
# defaults to what is probably sane-ish
self.gpg_import_func = _wrap_ayum_getKeyForRepo(ayum)
self.gpgca_import_func = _wrap_ayum_getKeyForRepo(ayum, ca=True)
self.confirm_func = None
# This allow listEnabled() to be O(1) most of the time.
self._cache_enabled_repos = []
self.quick_enable_disable = {}
# This allows plugins to setup a repo. just before the first
# listEnabled() call.
self._list_enabled_hasrun = False
示例3: __init__
def __init__(self, *args, **kwargs):
super(Kannel, self).__init__(*args, **kwargs)
reference = weakref(self)
# set up event handler for incoming messages
def on_incoming(sender=None, request=None, response=None, **kwargs):
transport = reference()
if transport is not None:
body, status_code = transport.handle(request)
response.write(body)
response.status_code = status_code
kannel_event.connect(on_incoming, sender=self.name, weak=False)
del on_incoming
# set up event handler for outgoing messages
def on_outgoing(sender=None, instance=None, created=False, **kwargs):
transport = reference()
if transport is not None:
if created is True and instance.transport == transport.name:
transport.send(instance)
signals.post_save.connect(on_outgoing, sender=Outgoing, weak=False)
del on_outgoing
示例4: __init__
def __init__(self, treeConfig: TreeConfig, nameTuple: Tuple[str, ...], description: str,
msgArgsInfo: ArgsInfo, parent: Topic = None):
"""
Create a topic. Should only be called by TopicManager via its
getOrCreateTopic() method (which gets called in several places
in pubsub, such as sendMessage, subscribe, and newTopic).
:param treeConfig: topic tree configuration settings
:param nameTuple: topic name, in tuple format (no dots)
:param description: "docstring" for topic
:param ArgsInfo msgArgsInfo: object that defines MDS for topic
:param parent: parent of topic
:raises ValueError: invalid topic name
"""
if parent is None:
if nameTuple != (ALL_TOPICS,):
msg = 'Only one topic, named %s, can be root of topic tree'
raise ValueError(msg % 'pub.ALL_TOPICS')
else:
validateName(nameTuple)
self.__tupleName = nameTuple
self.__handlingUncaughtListenerExc = False
self._treeConfig = treeConfig
self.__validator = None
# Registered listeners were originally kept in a Python list; however
# a few methods require lookup of the Listener for the given callable,
# which is an O(n) operation. A set() could have been more suitable but
# there is no way of retrieving an element from a set without iterating
# over the set, again an O(n) operation. A dict() is ok too. Because
# Listener.__eq__(callable) returns true if the Listener instance wraps
# the given callable, and because Listener.__hash__ produces the hash
# value of the wrapped callable, calling dict[callable] on a
# dict(Listener -> Listener) mapping will be O(1) in most cases:
# the dict will take the callables hash, find the list of Listeners that
# have that hash, and then iterate over that inner list to find the
# Listener instance which satisfies Listener == callable, and will return
# the Listener.
self.__listeners = dict()
# specification:
self.__description = None
self.setDescription(description)
self.__msgArgs = msgArgsInfo
if msgArgsInfo.isComplete():
self.__finalize()
else:
assert not self._treeConfig.raiseOnTopicUnspecified
# now that we know the args are fine, we can link to parent
self.__parentTopic = None
self.__subTopics = {}
if parent is None:
assert self.hasMDS()
else:
self.__parentTopic = weakref(parent)
assert self.__msgArgs.parentAI() is parent.__msgArgs
parent.__adoptSubtopic(self)
示例5: __init__
def __init__(self, *args, **kwargs):
super(HTTP, self).__init__(*args, **kwargs)
reference = weakref(self)
# set up event handler for incoming messages
def on_incoming(sender=None, name=None, request=None, response=None, **kwargs):
transport = reference()
if transport is not None and name == transport.name:
body, status_code = transport.handle(request)
response.write(body)
response.status_code = status_code
http_event.connect(on_incoming, weak=False)
del on_incoming
# set up event handler for outgoing messages
def on_outgoing(sender=None, instance=None, created=False, **kwargs):
transport = reference()
if transport is not None:
if created is True and instance.connection.transport == transport.name:
try:
suppress = instance.in_response_to.message.suppress_responses
except:
pass
else:
if suppress:
return
transport.send(instance)
signals.post_save.connect(on_outgoing, sender=Outgoing, weak=False)
del on_outgoing
示例6: __init__
def __init__(self, history, row):
self._history = weakref(history)
self.tid = row[0]
self.beg_timestamp = row[1]
self.beg_rpmdbversion = row[2]
self.end_timestamp = row[3]
self.end_rpmdbversion = row[4]
self.loginuid = row[5]
self.return_code = row[6]
self._loaded_TW = None
self._loaded_TD = None
self._loaded_TS = None
self._loaded_PROB = None
self._have_loaded_CMD = False # cmdline can validly be None
self._loaded_CMD = None
self._loaded_ER = None
self._loaded_OT = None
self.altered_lt_rpmdb = None
self.altered_gt_rpmdb = None
示例7: __init__
def __init__(self, channel, level, msg, args=None, kwargs=None,
exc_info=None, extra=None, frame=None, dispatcher=None):
#: the name of the logger that created it or any other textual
#: channel description. This is a descriptive name and can be
#: used for filtering.
self.channel = channel
#: The message of the log record as new-style format string.
self.msg = msg
#: the positional arguments for the format string.
self.args = args or ()
#: the keyword arguments for the format string.
self.kwargs = kwargs or {}
#: the level of the log record as integer.
self.level = level
#: optional exception information. If set, this is a tuple in the
#: form ``(exc_type, exc_value, tb)`` as returned by
#: :func:`sys.exc_info`.
#: This parameter can also be ``True``, which would cause the exception info tuple
#: to be fetched for you.
self.exc_info = exc_info
#: optional extra information as dictionary. This is the place
#: where custom log processors can attach custom context sensitive
#: data.
self.extra = ExtraDict(extra or ())
#: If available, optionally the interpreter frame that pulled the
#: heavy init. This usually points to somewhere in the dispatcher.
#: Might not be available for all calls and is removed when the log
#: record is closed.
self.frame = frame
#: the PID of the current process
self.process = None
if dispatcher is not None:
dispatcher = weakref(dispatcher)
self._dispatcher = dispatcher
示例8: __init__
def __init__(s, debug_name, debug_locals):
super().__init__()
s.debug_name = debug_name
s.debug_locals = weakref(debug_locals) if debug_locals != None else None
if debug_locals != None:
s.kbdbg_name = debug_locals.kbdbg_frame
s.kbdbg_name += "_" + urllib.parse.quote_plus(debug_name)
示例9: __init__
def __init__(self, source, extra_params, record):
self.source = source
self.extra_params = extra_params
self.__record = weakref(record) if record is not None else lambda: None
self.__cached_for_ctx = None
self.__html = None
self.__meta = None
示例10: prepare_grammar
def prepare_grammar(s, scope):
#s.marpa.t.input.clear()
log("prepare grammar..")
for i in s.editor.root.flatten():
i.forget_symbols() # todo:start using visitors
s.marpa.collect_grammar(scope)
assert s.current_parser_node
s.marpa.enqueue_precomputation(weakref(s.current_parser_node))
示例11: __init__
def __init__(
self,
channel,
level,
msg,
args=None,
kwargs=None,
exc_info=None,
extra=None,
frame=None,
dispatcher=None,
frame_correction=0,
):
#: the name of the logger that created it or any other textual
#: channel description. This is a descriptive name and can be
#: used for filtering.
self.channel = channel
#: The message of the log record as new-style format string.
self.msg = msg
#: the positional arguments for the format string.
self.args = args or ()
#: the keyword arguments for the format string.
self.kwargs = kwargs or {}
#: the level of the log record as integer.
self.level = level
#: optional exception information. If set, this is a tuple in the
#: form ``(exc_type, exc_value, tb)`` as returned by
#: :func:`sys.exc_info`.
#: This parameter can also be ``True``, which would cause the exception
#: info tuple to be fetched for you.
if not exc_info:
# this is a special case where exc_info=False can be passed in
# theory, and it should be the same as exc_info=None
exc_info = None
self.exc_info = exc_info
#: optional extra information as dictionary. This is the place
#: where custom log processors can attach custom context sensitive
#: data.
# TODO: Replace the lambda with str when we remove support for python 2
self.extra = defaultdict(lambda: u"", extra or ())
#: If available, optionally the interpreter frame that pulled the
#: heavy init. This usually points to somewhere in the dispatcher.
#: Might not be available for all calls and is removed when the log
#: record is closed.
self.frame = frame
#: A positive integer telling the number of frames to go back from
#: the frame which triggered the log entry. This is mainly useful
#: for decorators that want to show that the log was emitted from
#: form the function they decorate
self.frame_correction = frame_correction
#: the PID of the current process
self.process = None
if dispatcher is not None:
dispatcher = weakref(dispatcher)
self._dispatcher = dispatcher
示例12: contribute_to_class
def contribute_to_class(self, ModelClass, name):
# Use weakref because of possible memory leak / circular reference.
self._model = weakref(ModelClass)
original_save = ModelClass.save
def save_and_clear_cache(instance, *args, **kwargs):
original_save(instance, *args, **kwargs)
self.clear(instance=instance)
setattr(ModelClass, name, self)
示例13: get_connection
def get_connection(self, command_name, shard_hint=None):
host_id = shard_hint
if host_id is None:
raise RuntimeError('The routing pool requires the host id '
'as shard hint')
real_pool = self.cluster.get_pool_for_host(host_id)
con = real_pool.get_connection(command_name)
con.__creating_pool = weakref(real_pool)
return con
示例14: __init__
def __init__(self, topicMgr, nameTuple, description, parent=None,
argsSpec=None, reqdArgs=(), msgArgs=None, deadListenerCB=None):
'''Specify the name, description, and parent of this Topic. Any remaining
keyword arguments (which will be put in msgArgs) describe the arguments that
a listener of this topic must support (i.e., the key is the argument name and
the value is a documentation string explaining what the argument is for).
The reqdArgs is an optional list of names identifying which variables in
msgArgs keys are required arguments. E.g.
Topic(('a','b'), 'what is topic for', parentTopic, _reqdArgs=('c','d'),
c='what is c for', d='what is d for', e='what is e for')
would create a Topic whose listeners would have to be of the form
callable(c, d, e=...)
ie
callable(c, d, e=...)
callable(self, c, d, e=..., **kwargs) (method)
would all be valid listeners but
callable(c, e=...) # error: required d is missing
callable(c, d, e) # error: e is optional
would not be valid listeners of this topic.
The _useKwa is only used by the package to indicate whether the arguments are
specified as part of __init__ (there is no other way since msgArgs cannot be None).
'''
self.__validateName(nameTuple, parent is None)
self.__tupleName = nameTuple
self.__validator = None
self.__listeners = []
self.__deadListenerCB = deadListenerCB
# specification:
self.__description = None
self.setDescription(description)
getArgsSpec = topicMgr._getDefnProvider_().getSubSpec
self.__msgArgs = ArgsInfo(getArgsSpec, nameTuple,
parent, msgArgs, reqdArgs, argsSpec)
if self.__msgArgs.isComplete():
self.__finalize()
self.argsSpec = self.__msgArgs
# now that we know the args are fine, we can link to parent
self.__parentTopic = None
if parent is None:
assert self.isSendable()
else:
self.__parentTopic = weakref(parent)
parent.__setSubtopic( self.getTailName(), self )
示例15: __init__
def __init__(self, client=None):
breadcrumbs = raven.breadcrumbs.make_buffer(
client is None or client.enable_breadcrumbs)
if client is not None:
client = weakref(client)
self._client = client
# Because the thread auto activates the thread local this also
# means that we auto activate this thing. Only if someone decides
# to deactivate manually later another call to activate is
# technically necessary.
self.activate()
self.data = {}
self.exceptions_to_skip = set()
self.breadcrumbs = breadcrumbs