|
Server : Apache System : Linux cvar2.toservers.com 3.10.0-962.3.2.lve1.5.73.el7.x86_64 #1 SMP Wed Aug 24 21:31:23 UTC 2022 x86_64 User : njnconst ( 1116) PHP Version : 8.4.18 Disable Function : NONE Directory : /usr/lib64/python2.7/site-packages/django/dispatch/ |
Upload File : |
�
r�\c @ sc d Z d d l Z d d l Z d d � Z d e f d � � YZ d e f d � � YZ d � Z d S( s�
"Safe weakrefs", originally from pyDispatcher.
Provides a way to safely weakref any function, including bound methods (which
aren't handled by the core weakref module).
i����Nc C s� t | d � r\ | j d k r\ t | d � s@ t d | f � � t d | d | � } | Sn t | � rx t j | | � St j | � Sd S( s� Return a *safe* weak reference to a callable target
target -- the object to be weakly referenced, if it's a
bound method reference, will create a BoundMethodWeakref,
otherwise creates a simple weakref.
onDelete -- if provided, will have a hard reference stored
to the callable to be called after the safe reference
goes out of scope with the reference object, (either a
weakref or a BoundMethodWeakref) as argument.
t __self__t __func__sS safeRef target %r has __self__, but no __func__, don't know how to create referencet targett onDeleteN( t hasattrR t Nonet AssertionErrort get_bound_method_weakreft callablet weakreft ref( R R t reference( ( s9 /tmp/pip-install-XxeQeY/django/django/dispatch/saferef.pyt safeRef s " t BoundMethodWeakrefc B s� e Z d Z e j � Z d
d � Z d
d � Z d � Z e
e � Z d � Z e Z d � Z
d � Z d � Z d � Z d � Z RS( s� 'Safe' and reusable weak references to instance methods
BoundMethodWeakref objects provide a mechanism for
referencing a bound method without requiring that the
method object itself (which is normally a transient
object) is kept alive. Instead, the BoundMethodWeakref
object keeps weak references to both the object and the
function which together define the instance method.
Attributes:
key -- the identity key for the reference, calculated
by the class's calculateKey method applied to the
target instance method
deletionMethods -- sequence of callable objects taking
single argument, a reference to this object which
will be called when *either* the target object or
target function is garbage collected (i.e. when
this object becomes invalid). These are specified
as the onDelete parameters of safeRef calls.
weakSelf -- weak reference to the target object
weakFunc -- weak reference to the target function
Class Attributes:
_allInstances -- class attribute pointing to all live
BoundMethodWeakref objects indexed by the class's
calculateKey(target) method applied to the target
objects. This weak value dictionary is used to
short-circuit creation so that multiple references
to the same (object, function) pair produce the
same BoundMethodWeakref instance.
c O s� | j | � } | j j | � } | d k rA | j j | � | St t | � j | � } | | j | <| j | | | | � | Sd S( s� Create new instance or return current instance
Basically this method of construction allows us to
short-circuit creation of references to already-
referenced instance methods. The key corresponding
to the target is calculated, and if there is already
an existing reference, that is returned, with its
deletionMethods attribute updated. Otherwise the
new instance is created and registered in the table
of already-referenced methods.
N(
t calculateKeyt
_allInstancest getR t deletionMethodst appendt superR
t __new__t __init__( t clsR R t argumentst namedt keyt currentt base( ( s9 /tmp/pip-install-XxeQeY/django/django/dispatch/saferef.pyR I s
c C s� | d � } | g | _ | j | � | _ t j | j | � | _ t j | j | � | _ t | j � | _
t | j j � | _ d S( s~ Return a weak-reference-like instance for a bound method
target -- the instance-method target for the weak
reference, must have __self__ and __func__ attributes
and be reconstructable via:
target.__func__.__get__( target.__self__ )
which is true of built-in instance methods.
onDelete -- optional callback which will be called
when this weak reference ceases to be valid
(i.e. either the object or the function is garbage
collected). Should take a single argument,
which will be passed a pointer to this object.
c S s� | j } | j 2y | j j | j =Wn t k
r8 n Xxu | D]m } y t | � rb | | � n Wq@ t k
r� } y t j � Wq� t k
r� d | | | f GHq� Xq@ Xq@ Wd S( s<