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


Python DB.verify方法代码示例

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


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

示例1: run

# 需要导入模块: import DB [as 别名]
# 或者: from DB import verify [as 别名]
def run():
    server.listen(5)
    inputs = [server]
    outputs = []
    message_queues = {}

    while True:
        #print 'waiting for next event...'
        readable, writable, exceptional = select.select(inputs, outputs, inputs)

        if not (readable or writable or exceptional):
            print "time out"
            break

        for s in readable:
            if s is server:
                connection, client_address = server.accept()
                print "connection from ", client_address
                connection.setblocking(0)
                #connection.send('ready for connection')
                inputs.append(connection)
                message_queues[connection] = Queue.Queue()

            else:
                #transfer_message(s)

                #transfer pending msg to websocket client in list

                data = s.recv(1024)
                if data:
                    print "received:", data, "from ", s.getpeername()
                    try:
                        decode = json.loads(data)
                        print "json loaded:", decode
                    except:
                        if not s.getpeername() in CONNECTIONS:
                            handshake(s, data)
                            CONNECTIONS.append(s.getpeername())
                        else:
                            raw_data = parse_data(data)
                            print "parsed:", raw_data
                            #s.send(encaps_data('test from server'))
                        continue
                    function = decode['function']

                    if function == 'login':
                        username = decode['username']
                        password = decode['password']
                        userID = DB.verify(username, password)
                        if username and password and userID > 0:
                            print "'", username, "' logged in from ", s.getpeername()
                            token = hashlib.md5(str(time.time())).hexdigest()
                            TOKEN[str(userID)] = token
                            friends = DB.get_friends(userID)
                            reply = {'function': 'token', 'token': token, 'friends': friends}
                            s.send(json.dumps(reply))

                    elif function == 'appendADDR':
                        token = decode['token']
                        token_received = token.split('_')[0]
                        userid_received = token.split('_')[2]
                        if TOKEN[str(userid_received)] != token_received:
                            s.send('authentication failed')
                        else:
                            sending_addr = (decode['addr'][0], decode['addr'][1])
                            user_connections[str(userID)] = sending_addr

                    elif function == 'send':
                        token = decode['token']
                        token_received = token.split('_')[0]
                        userid_received = token.split('_')[2]
                        username_received = token.split('_')[1]
                        to = str(decode['to'])
                        to_token_received = decode['to_token']
                        to_token = USERS[to][1]
                        print to_token, to_token_received
                        if TOKEN[str(userid_received)] != token_received or to_token != to_token_received:
                            s.send('authentication failed')
                        else:
                            msg = decode['msg']
                            temp = {'from_id': userid_received, 'from_name': username_received, 'msg': msg}
                            if to in PENDING_MSG:
                                PENDING_MSG[to].append(temp)
                            else:
                                PENDING_MSG[to] = [temp]
                            print "pending messages: ", PENDING_MSG

                    message_queues[s].put(data)
                    if s not in outputs:
                        outputs.append(s)
                else:
                    #pass

                    print "closing ", client_address
                    if s in outputs:
                        outputs.remove(s)
                    inputs.remove(s)
                    #s.close()
                    del message_queues[s]

#.........这里部分代码省略.........
开发者ID:Stretford,项目名称:Chattalyze,代码行数:103,代码来源:chatserver.py


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