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


Python request.sid方法代码示例

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


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

示例1: update_loop

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def update_loop(session_id, sid):
    """
    :param session_id: W.I.L.L session id
    :param sid: Flask session id
    Update thread that will emit socket.io updates to the user while they're connected

    :return:
    """
    while session_id in core.sessions.keys():
        try:
            session_data = core.sessions[session_id]
        except KeyError:
            #Session ended while loop was sleeping
            break
        session_updates = session_data["updates"]
        while not session_updates.empty():
            update = session_updates.get()
            log.debug("Pushing update {0}".format(update))
            socketio.emit('update', update, room=sid)
        time.sleep(1)
    log.info(":{0}:Ending updates for finished session".format(session_id)) 
开发者ID:ironman5366,项目名称:W.I.L.L,代码行数:23,代码来源:web.py

示例2: get_updates

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def get_updates(data):
    """
    :param data: socket.io data about the update thread:
    Authenticate and start the update thread
    :return:
    """
    log.info(":SOCKET:get_updates")
    session_id = data["session_id"]
    if session_id:
        if session_id in core.sessions.keys():
            #If the session id is valid
            log.debug("{1}:Subscribing client {0} to updates for session_id".format(
                request.environ["REMOTE_ADDR"], session_id
            ))
            #Keep running this loop while the session is active
            log.info(":{0}:Starting update loop".format(session_id))
            update_thread = threading.Thread(target=update_loop, args=(session_id, request.sid))
            update_thread.start()
        else:
            log.debug("Session id {0} is invalid".format(session_id))
            socketio.emit("update", {"value": "Error, invalid session id"})
    else:
        socketio.emit("update", {"value": "Error, couldn't find session id in update request"}) 
开发者ID:ironman5366,项目名称:W.I.L.L,代码行数:25,代码来源:web.py

示例3: upload_file

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def upload_file():
    file = request.files['file']
    sites = request.form['sites']
    sites = sites.split(',')
    try:
        t_json = json.loads((file.read().decode('utf-8')))
    except json.decoder.JSONDecodeError:
        return jsonify({'success': False, 'msg': "Format JSON error!"}), 500
    file_hash = hashlib.md5(json.dumps(t_json['result']).encode('utf-8')).hexdigest()
    cache = mysql.get_result_cache(file_hash)
    if cache is not None:
        result = json.loads(cache)
    else:
        result = []
        for name, files in t_json['result'].items():
            result.append(compare_torrents(name, files))
        mysql.record_upload_data(current_user.id, file_hash, json.dumps(result), request.remote_addr)

    for torrent in result:
        for t in chain(torrent['cmp_warning'], torrent['cmp_success']):
            torrents = filter(lambda k: k['site'] in sites, find_torrents_by_id(t['id']))
            t['sites'] = ",".join(["{}-{}".format(t['site'], t['sid']) for t in torrents])
        torrent['cmp_success'] = list(filter(lambda k: k['sites'] != '', torrent['cmp_success']))
        torrent['cmp_warning'] = list(filter(lambda k: k['sites'] != '', torrent['cmp_warning']))
    return jsonify({'success': True, 'base_dir': t_json['base_dir'], 'result': result}) 
开发者ID:tongyifan,项目名称:Reseed-backend,代码行数:27,代码来源:reseed.py

示例4: find_torrents_by_file_socket

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def find_torrents_by_file_socket(files: dict):
    def send_result(torrent):
        for t in chain(torrent['cmp_warning'], torrent['cmp_success']):
            torrents = find_torrents_by_id(t['id'])
            t['sites'] = ",".join(["{}-{}".format(t['site'], t['sid']) for t in torrents])
        torrent['cmp_success'] = list(filter(lambda k: k['sites'] != '', torrent['cmp_success']))
        torrent['cmp_warning'] = list(filter(lambda k: k['sites'] != '', torrent['cmp_warning']))
        emit('reseed result', torrent, json=True)

    file_hash = hashlib.md5(json.dumps(files).encode('utf-8')).hexdigest()
    cache = mysql.get_result_cache(file_hash)
    if cache is not None:
        result = json.loads(cache)
        for torrent in result:
            send_result(torrent)
    else:
        result = []
        for name, file in files.items():
            torrent = compare_torrents(name, file)
            result.append(torrent)
            send_result(torrent)
        mysql.record_upload_data(current_user.id, file_hash, json.dumps(result),
                                 socketio.server.environ[request.sid]['HTTP_X_REAL_IP']) 
开发者ID:tongyifan,项目名称:Reseed-backend,代码行数:25,代码来源:reseed.py

示例5: on_monitor_disconnect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def on_monitor_disconnect():
    user_id = session.get('user_id', None)
    sys.stderr.write('Client disconnected from monitor\n')
    rr.delete('da:monitor:' + str(request.sid))
    rr.expire('da:monitor:available:' + str(user_id), 5)
    for key in rr.keys('da:monitor:role:*:userid:' + str(user_id)):
        key = key.decode()
        rr.expire(key, 5)
    for key in rr.keys('da:phonecode:monitor:' + str(user_id) + ':uid:*'):
        key = key.decode()
        the_code = rr.get(key)
        if the_code is not None:
            the_code = the_code.decode()
            rr.expire('da:callforward:' + the_code, 5)
        rr.expire(key, 5)
    rr.expire('da:monitor:chatpartners:' + str(user_id), 5)
    rr.publish(request.sid, json.dumps(dict(message='KILL', sid=request.sid))) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:19,代码来源:socketserver.py

示例6: start_control

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def start_control(message):
    if 'observer' not in session:
        socketio.emit('terminate', {}, namespace='/observer', room=request.sid)
        return
    self_key = 'da:control:sid:' + str(request.sid)
    key = 'da:control:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid'])
    existing_sid = rr.get(key)
    if existing_sid is None or existing_sid.decode() == request.sid:
        #sys.stderr.write('Controlling ' + key + '\n')
        pipe = rr.pipeline()
        pipe.set(self_key, key)
        pipe.expire(self_key, 12)
        pipe.set(key, request.sid)
        pipe.expire(key, 12)
        pipe.execute()
        int_key = 'da:interviewsession:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid'])
        int_sid = rr.get(int_key)
        if int_sid is not None:
            int_sid = int_sid.decode()
            rr.publish(int_sid, json.dumps(dict(messagetype='controllerstart')))
    else:
        sys.stderr.write('That key ' + key + ' is already taken\n')
        key = 'da:session:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid'])
        #rr.publish('da:monitor', json.dumps(dict(messagetype='abortcontroller', key=key)))
        socketio.emit('abortcontrolling', {'key': key}, namespace='/observer', room=request.sid) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:27,代码来源:socketserver.py

示例7: stop_control

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def stop_control(message):
    if 'observer' not in session:
        socketio.emit('terminate', {}, namespace='/observer', room=request.sid)
        return
    self_key = 'da:control:sid:' + str(request.sid)
    key = 'da:control:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid'])
    sys.stderr.write('Stop controlling ' + key + '\n')
    existing_sid = rr.get(key)
    pipe = rr.pipeline()
    pipe.delete(self_key)
    if existing_sid is not None and existing_sid.decode() == request.sid:
        pipe.delete(key)
        pipe.execute()
        sid = rr.get('da:interviewsession:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid']))
        if sid is not None:
            sid = sid.decode()
            sys.stderr.write("Calling controllerexit 1");
            rr.publish(sid, json.dumps(dict(messagetype='controllerexit', sid=request.sid)))
    else:
        pipe.execute() 
开发者ID:jhpyle,项目名称:docassemble,代码行数:22,代码来源:socketserver.py

示例8: on_observer_disconnect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def on_observer_disconnect():
    sys.stderr.write('Client disconnected from observer\n')
    self_key = 'da:control:sid:' + str(request.sid)
    int_key = rr.get(self_key)
    if int_key is not None:
        int_key = int_key.decode()
        rr.delete(int_key)
        other_sid = rr.get(re.sub(r'^da:control:uid:', 'da:interviewsession:uid:', int_key))
    else:
        other_sid = None
    rr.delete(self_key)
    if other_sid is not None:
        other_sid = other_sid.decode()
        sys.stderr.write("Calling controllerexit 2");
        rr.publish(other_sid, json.dumps(dict(messagetype='controllerexit', sid=request.sid)))
    rr.publish(request.sid, json.dumps(dict(message='KILL', sid=request.sid))) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:18,代码来源:socketserver.py

示例9: on_disconnect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def on_disconnect() -> (int, None):
    """
    when a client disconnects or the server no longer gets a ping response from the client

    :return json if ok, {'status_code': 200}
    """
    user_id = str(environ.env.session.get(SessionKeys.user_id.value))
    try:
        sid = request.sid
    except Exception as e:
        logger.error('could not get sid from request: {}'.format(str(e)))
        logger.exception(traceback.format_exc())
        environ.env.capture_exception(sys.exc_info())
        sid = ''

    data = {
        'verb': 'disconnect',
        'actor': {
            'id': user_id,
            'content': sid
        }
    }
    if not environ.env.config.get(ConfigKeys.TESTING):
        # only used for single-session restrictions
        if environ.env.connected_user_ids.get(user_id) == sid:
            del environ.env.connected_user_ids[user_id]

    activity = as_parser(data)
    environ.env.observer.emit('on_disconnect', (data, activity))
    return ECodes.OK, None 
开发者ID:thenetcircle,项目名称:dino,代码行数:32,代码来源:api.py

示例10: join_game

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def join_game(player_name):
    app.logger.info('{player_name} has joined the game'.format(
        player_name=player_name))

    # Add the player to the game
    game_master.game.add_player(request.sid, player_name) 
开发者ID:abrenaut,项目名称:posio,代码行数:8,代码来源:views.py

示例11: leave_games

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def leave_games():
    app.logger.info('A player has left the game')
    game_master.game.remove_player(request.sid) 
开发者ID:abrenaut,项目名称:posio,代码行数:5,代码来源:views.py

示例12: store_answer

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def store_answer(latitude, longitude):
    game_master.game.store_answer(request.sid, latitude, longitude) 
开发者ID:abrenaut,项目名称:posio,代码行数:4,代码来源:views.py

示例13: on_connect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def on_connect(self):
        sid = request.sid
        # if current_user.is_authenticated:
        bui.logger.debug('Someone just connected! {}'.format(sid))
        # else:
        #    bui.logger.debug('Illegal connection')
        #    disconnect()
        #    return False 
开发者ID:ziirish,项目名称:burp-ui,代码行数:10,代码来源:namespace.py

示例14: on_disconnect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def on_disconnect(self):
        sid = request.sid
        bui.logger.debug('Someone just disconnected! {}'.format(sid)) 
开发者ID:ziirish,项目名称:burp-ui,代码行数:5,代码来源:namespace.py

示例15: handle_json

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import sid [as 别名]
def handle_json(data):

    try:
        user = data['user']
    except KeyError:
        raise BadRequest("Missing key 'user'")

    try:
        follow_list = data['follow']
    except KeyError:
        raise BadRequest("Missing key 'follow'")

    if len(follow_list) <= 0:
        raise BadRequest("Follow list must have one or more users.")

    current_rooms = rooms()
    for user in rooms():
         
        # Don't remove the user from its own room
        if user == request.sid:
            continue

        if user not in follow_list:
            leave_room(user)

    for user in follow_list:
        if user not in current_rooms:
            join_room(user) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:30,代码来源:follow_server.py


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