Exemplo n.º 1
0
    def from_anything(data):
        """Return a People instance from any supported representation.

        Supported representation are People instances, userid strings,
        (username, hostname) tuples, and dictionnaries from server reply.

        :param data: A representation of a People object.
        """
        if isinstance(data, People):
            return data
        elif isinstance(data, str) or isinstance(data, unicode):
            try:
                username, hostname = utils.userid2tuple(data)
            except ValueError:
                raise exceptions.PeopleNotInstanciable(
                        _('hostname is missing.'))
            return People(username, hostname)
        elif isinstance(data, tuple) and len(data) == 2:
            return People(*data)
        elif isinstance(data, dict) and 'username' in data and \
                'server' in data and isinstance(data['server'], dict) and \
                'hostname' in data['server']:
            return People(data['username'], data['server']['hostname'])
        else:
            raise ValueError('Invalid representation of People object: %r' %
                    data)
Exemplo n.º 2
0
 def new_callback(new_userid, new_password):
     global username, hostname, password
     try:
         username, hostname = userid2tuple(new_userid)
     except:
         return False
     password = new_password
     if People(username, hostname, password, connect=True).authenticated:
         return callback(new_userid, new_password)
     else:
         return False
Exemplo n.º 3
0
 def new_callback(new_userid, new_password):
     global username, hostname, password
     try:
         username, hostname = userid2tuple(new_userid)
     except:
         return False
     password = new_password
     if People(username, hostname, password, connect=True).authenticated:
         return callback(new_userid, new_password)
     else:
         return False
Exemplo n.º 4
0
def get_people(userid):
    username, servername = utils.userid2tuple(userid,
            settings.WIDIDIT_HOSTNAME)
    server = get_server(servername)
    return People.objects.get(username=username, server=server)