当前位置: 首页>>代码示例>>Python>>正文


Python User.find_user_by_name方法代码示例

本文整理汇总了Python中user.User.find_user_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_user_by_name方法的具体用法?Python User.find_user_by_name怎么用?Python User.find_user_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.find_user_by_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: monitor

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_user_by_name [as 别名]
def monitor(sock, data):


    u = User.find_user_by_sock(sock)
    print 'command from:', u.username
    command = data['command']
    room_name = data['destination']

    if command == 'users':
        li = []
        for el in User.users:
            if el.username:
                li.append([el.username, el.network])
        print 'Number users on:', len(li), '---', len(User.users)
        for el in li:
            print el
    if command == 'rooms':
        r = Room.find_room_by_name(room_name)
        try:
            print 'room alias:', r.alias
            print 'room users_name:', adapter(r.users_name)
        except:
            print 'no room'
    if command == 'message':
        u = User.find_user_by_name('[email protected]', 'dev-socialbase')

        info = {"type": "chat", "payload": {"command": "test_user",
                                            "details": str(u)}}

        u.connection.write_message(info)
        print 'B.sended to ', u.username, info
开发者ID:AlexandreProenca,项目名称:chat2.0,代码行数:33,代码来源:manager.py

示例2: room_create

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_user_by_name [as 别名]
def room_create(sock, data):
    user = User.find_user_by_sock(sock)
    target_name = data['details']['new_user']

    echo = None
    if "echo" in data:
        echo = data['echo']

    target_resource = user.resource
    target_online = User.find_user_by_name(target_name, user.resource)  # sock de outro usuario conectado
    target_offline = None
    if not target_online:
        api_mongo.insert_user(target_name, target_resource)
        target_offline = target_name

    if user == target_online:
        info = {"type": "chat", "payload": {"command": "error", "details": "choose_another_less_you"}}
        send(user, info)
    else:
        second_user = None
        if target_online:
            second_user = target_online.username
        if not second_user:
            second_user = target_offline

        if second_user:
            if not Room.check_exist_room([user.username, second_user], user.resource):  # se sala nao existe

                user_temp = []
                for username in [user.username, second_user]:
                    user_temp.append({"username": username, "seen": None, "received": None})

                room_name = Room.open(user_temp, target_resource)  # cria a sala e recebe nome unico a sala
                new_room = Room.find_room_by_name(room_name)  # sock para o nova sala criada
                new_room.users_name = user_temp  # insert two news name users
                new_room.alias = 'DEFAULT'  # insert alias
                alias = new_room.alias
                api_mongo.insert_room(user_temp, room_name, alias, target_resource, False, None)
                info = {"type": "chat", "payload": {"command": "room_id",
                                                    "alias": new_room.alias,
                                                    "room_id": room_name,
                                                    "users": user_temp,
                                                    "echo": echo,
                                                    "is_group": False}}
                send(user, info)
            else:  # se sala ja existe
                user_temp = []
                for username in [user.username, second_user]:
                    user_temp.append({"username": username, "seen": None, "received": None})

                room_to_append = Room.find_room_by_users([user.username, second_user], user.resource)
                room_restore(room_to_append)
                new_room = Room.find_room_by_name(room_to_append)  # sock para o nova sala criada
                info = {"type": "chat", "payload": {"command": "room_id",
                                                    "alias": new_room.alias,
                                                    "room_id": room_to_append,
                                                    "users": user_temp,
                                                    "is_group": new_room.is_group}}
                send(user, info)
开发者ID:AlexandreProenca,项目名称:chat2.0,代码行数:61,代码来源:manager.py

示例3: room_enter

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_user_by_name [as 别名]
def room_enter(sock, data):
    logging.info(' room_enter data{}: %r', data)
    user = User.find_user_by_sock(sock)
    alias = data['alias']
    room_sock = Room.find_room_by_alias(alias)  # objeto da sala com esse alias

    if room_sock:
        if user.username in adapter(room_sock.users_name):  # verifica se esse usuario esta nessa sala
            room_restore(room_sock.name)  # coloca na memoria a sala encontrada

            info = {"type": "chat", "payload": {"command": "room_id",
                                                "room_id": room_sock.name,
                                                "alias": room_sock.alias}}
            for el in adapter(room_sock.users_name):  # envia room_id para todos os users do room
                u = User.find_user_by_name(el, user.resource)
                if u:
                    send(u, info)
开发者ID:AlexandreProenca,项目名称:chat2.0,代码行数:19,代码来源:manager.py

示例4: user_remove

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import find_user_by_name [as 别名]
def user_remove(sock, data):
    # logging.info(' room_leave data{}:\n %r', data)

    users_to_remove = data['user_remove']
    if type(users_to_remove) is unicode:
        users_to_remove = [data['user_remove']]

    u = User.find_user_by_sock(sock)

    users_remove = data['user_remove']
    if type(users_remove) is unicode:
        users_remove = [data['user_remove']]

    print("USERS REMOVE ", users_remove)

    destination = data['destination']  # id de sala a ser alterada
    room_users = Room.find_users_by_room(destination)  # Lista de usuarios em uma sala

    print("ROOOMS USERS", room_users)

    for el in users_remove:  # envia mensagem dos novos nomes
        send_system_info(sock, destination, 'USER REMOVE', el)  # envia message para grupo da saida do user

    u_list = []  # lista final
    for el in room_users:
        if not (el in users_remove):
            u_list.append(el)

    new_room = Room.find_room_by_name(destination)  # sock para o nova sala alterada
    new_room.users_name = [{"username": _u, "seen": None, "received": None} for _u in u_list]

    current_user = User.find_user_by_sock(sock)

    for uremove in users_to_remove:
        api_mongo.remove_user_room(destination, uremove)
        u = User.find_user_by_name(uremove, u.resource)
        if u:
            info = {"type": "chat", "payload": {"command": "user_remove",
                                                "room_id": destination}}
            send(u, info)
开发者ID:AlexandreProenca,项目名称:chat2.0,代码行数:42,代码来源:manager.py


注:本文中的user.User.find_user_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。