def get_identity(identity):
 if isinstance(identity, AnonymousUser):
  identity = get_anonymous_user()
 if isinstance(identity, get_user_model()):
  return (identity, None)
 elif isinstance(identity, Group):
  return (None, identity)
 raise NotUserNorGroup((u'User/AnonymousUser or Group instance is required (got %s)' % identity))

def get_identity ( identity ) : if isinstance ( identity , AnonymousUser ) : identity = get_anonymous_user ( ) if isinstance ( identity , get_user_model ( ) ) : return ( identity , None ) elif isinstance ( identity , Group ) : return ( None , identity ) raise NotUserNorGroup ( ( u'User/AnonymousUser or Group instance is required (got %s)' % identity ) )
returns or tuple depending on what is given .