def safe_ref(target, on_delete=None):
 if (getattr(target, 'im_self', None) is not None):
  assert hasattr(target, 'im_func'), ('safe_ref target %r has im_self, but no im_func, "             "don\'t know how to create reference' % (target,))
  return get_bound_method_weakref(target=target, on_delete=on_delete)
 if callable(on_delete):
  return weakref.ref(target, on_delete)
 else:
  return weakref.ref(target)

def safe_ref ( target , on_delete = None ) : if ( getattr ( target , 'im_self' , None ) is not None ) : assert hasattr ( target , 'im_func' ) , ( 'safe_ref target %r has im_self, but no im_func, "             "don\'t know how to create reference' % ( target , ) ) return get_bound_method_weakref ( target = target , on_delete = on_delete ) if callable ( on_delete ) : return weakref . ref ( target , on_delete ) else : return weakref . ref ( target )
return a *safe* weak reference to a callable target .