def safeRef(target, onDelete=None):
 if hasattr(target, '__self__'):
  if (target.__self__ is not None):
   assert hasattr(target, '__func__'), ("safeRef target %r has __self__, but no __func__, don't know how to create reference" % (target,))
   reference = get_bound_method_weakref(target=target, onDelete=onDelete)
   return reference
 if callable(onDelete):
  return weakref.ref(target, onDelete)
 else:
  return weakref.ref(target)

def safeRef ( target , onDelete = None ) : if hasattr ( target , '__self__' ) : if ( target . __self__ is not None ) : assert hasattr ( target , '__func__' ) , ( "safeRef target %r has __self__, but no __func__, don't know how to create reference" % ( target , ) ) reference = get_bound_method_weakref ( target = target , onDelete = onDelete ) return reference if callable ( onDelete ) : return weakref . ref ( target , onDelete ) else : return weakref . ref ( target )
return a *safe* weak reference to a callable target target -- the object to be weakly referenced .