Пример #1
0
 def save_dictproxy(pickler, obj):
     log.info("Dp: %s" % obj)
     attr = obj.get('__dict__')
     #pickler.save_reduce(_create_dictproxy, (attr,'nested'), obj=obj)
     if type(attr) == GetSetDescriptorType and attr.__name__ == "__dict__" \
     and getattr(attr.__objclass__, "__dict__", None) == obj:
         pickler.save_reduce(getattr, (attr.__objclass__, "__dict__"),
                             obj=obj)
         log.info("# Dp")
         return
     # all bad below... so throw ReferenceError or TypeError
     from weakref import ReferenceError
     raise ReferenceError("%s does not reference a class __dict__" % obj)
Пример #2
0
def _locate_object(address, module=None):
    """get object located at the given memory address (inverse of id(obj))"""
    special = [None, True, False] #XXX: more...?
    for obj in special:
        if address == id(obj): return obj
    if module:
        if PY3:
            objects = iter(module.__dict__.values())
        else:
            objects = module.__dict__.itervalues()
    else: objects = iter(gc.get_objects())
    for obj in objects:
        if address == id(obj): return obj
    # all bad below... nothing found so throw ReferenceError or TypeError
    from weakref import ReferenceError
    try: address = hex(address)
    except TypeError:
        raise TypeError("'%s' is not a valid memory address" % str(address))
    raise ReferenceError("Cannot reference object at '%s'" % address)
Пример #3
0
 def __eq__(self, other):
     if isinstance(other, WeakMethodProxy):
         a, b = self.weak_method(), other.weak_method()
         if a is None or b is None:
             raise ReferenceError("weakly-referenced object no longer exists")
         return a == b