Exemplo n.º 1
0
 def __new__(cls, meth, callback=None):
     try:
         obj = meth.__self__
         func = meth.__func__
     except AttributeError:
         raise TypeError("argument should be a bound method, not {}"
                         .format(type(meth))) from None
     def _cb(arg):
         # The self-weakref trick is needed to avoid creating a reference
         # cycle.
         self = self_wr()
         if self._alive:
             self._alive = False
             if callback is not None:
                 callback(self)
     self = ref.__new__(cls, obj, _cb)
     self._func_ref = ref(func, _cb)
     self._meth_type = type(meth)
     self._alive = True
     self_wr = ref(self)
     return self
Exemplo n.º 2
0
Arquivo: weakref.py Projeto: AbuzzT/BR
 def __new__(cls, meth, callback=None):
     try:
         obj = meth.__self__
         func = meth.__func__
     except AttributeError:
         raise TypeError("argument should be a bound method, not {}"
                         .format(type(meth))) from None
     def _cb(arg):
         # The self-weakref trick is needed to avoid creating a reference
         # cycle.
         self = self_wr()
         if self._alive:
             self._alive = False
             if callback is not None:
                 callback(self)
     self = ref.__new__(cls, obj, _cb)
     self._func_ref = ref(func, _cb)
     self._meth_type = type(meth)
     self._alive = True
     self_wr = ref(self)
     return self
Exemplo n.º 3
0
    def __new__(cls, meth, callback=None):
        try:
            obj = meth.__self__
            func = meth.__func__
        except AttributeError:
            raise TypeError('argument should be a bound method, not {}'.format(
                type(meth))) from None

        def _cb(arg):
            self = self_wr()
            if self._alive:
                self._alive = False
                if callback is not None:
                    callback(self)

        self = ref.__new__(cls, obj, _cb)
        self._func_ref = ref(func, _cb)
        self._meth_type = type(meth)
        self._alive = True
        self_wr = ref(self)
        return self
Exemplo n.º 4
0
 def __new__(cls, meth, callback=None):
     try:
         obj = meth.__self__
         func = meth.__func__
     # MODIFIED to return a ref instead of raising an exception
     except AttributeError:
         return ref(meth, callback)
     # END MODIFIED
     def _cb(arg):
         # The self-weakref trick is needed to avoid creating a reference
         # cycle.
         self = self_wr()
         if self._alive:
             self._alive = False
             if callback is not None:
                 callback(self)
     self = ref.__new__(cls, obj, _cb)
     self._func_ref = ref(func, _cb)
     self._meth_type = type(meth)
     self._alive = True
     self_wr = ref(self)
     return self
Exemplo n.º 5
0
 def __new__(type, ob, callback, key):
     self = ref.__new__(type, ob, callback)
     self.key = key
     return self
Exemplo n.º 6
0
 def __new__(type, ob, callback, key):
     self = ref.__new__(type, ob, callback)
     self.key = key
     return self
Exemplo n.º 7
0
 def __new__(cls, method, callback=None):
     self = ref.__new__(cls, method.__self__, callback)
     self.__fnc = method.__func__
     return self