def weakref_proxy(obj):
    """returns either a weakref.proxy for the object, or if object is already a proxy,
    returns itself."""
    if type(obj) in weakref.ProxyTypes:
        return obj
    else:
        return weakref.proxy(obj)