Python flask.request.sid() Examples
The following are 30
code examples of flask.request.sid().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.request
, or try the search function
.
Example #1
Source File: socketserver.py From docassemble with MIT License | 6 votes |
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)))
Example #2
Source File: socketserver.py From docassemble with MIT License | 6 votes |
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)))
Example #3
Source File: web.py From W.I.L.L with MIT License | 6 votes |
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))
Example #4
Source File: web.py From W.I.L.L with MIT License | 6 votes |
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"})
Example #5
Source File: reseed.py From Reseed-backend with GNU Affero General Public License v3.0 | 6 votes |
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})
Example #6
Source File: reseed.py From Reseed-backend with GNU Affero General Public License v3.0 | 6 votes |
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'])
Example #7
Source File: socketserver.py From docassemble with MIT License | 6 votes |
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()
Example #8
Source File: socketserver.py From docassemble with MIT License | 6 votes |
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)
Example #9
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def on_interview_reconnect(data): with session_scope() as dbsession: sys.stderr.write("Client reconnected on interview\n") interview_connect(data['i']) rr.publish('da:monitor', json.dumps(dict(messagetype='refreshsessions'))) socketio.emit('reconnected', {}, namespace='/wsinterview', room=request.sid)
Example #10
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def terminate_interview_connection(): sys.stderr.write("terminate_interview_connection\n") # hopefully the disconnect will be triggered # if request.sid in threads: # rr.publish(request.sid, json.dumps(dict(origin='client', message='KILL', sid=request.sid))) socketio.emit('terminate', {}, namespace='/wsinterview', room=request.sid) #disconnect()
Example #11
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def on_interview_manual_disconnect(data): sys.stderr.write("Client manual disconnect\n") yaml_filename = data['i'] session_info = get_session(yaml_filename) session_id = session_info['uid'] the_user_id = session.get('user_id', 't' + str(session.get('tempuser', None))) if request.sid in secrets: del secrets[request.sid] if session_id is not None: rr.delete('da:interviewsession:uid:' + str(session_id) + ':i:' + str(yaml_filename) + ':userid:' + str(the_user_id)) key = 'da:session:uid:' + str(session_id) + ':i:' + str(yaml_filename) + ':userid:' + str(the_user_id) rr.expire(key, 10) rr.publish(request.sid, json.dumps(dict(origin='client', message='KILL', sid=request.sid)))
Example #12
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def on_monitor_connect(): if 'monitor' not in session: socketio.emit('terminate', {}, namespace='/monitor', room=request.sid) return sys.stderr.write('Client connected on monitor and will join room monitor\n') key = 'da:monitor:' + str(request.sid) pipe = rr.pipeline() pipe.set(key, 1) pipe.expire(key, 60) pipe.execute() join_room('monitor') join_room(request.sid) user_id = session.get('user_id', None) if request.sid not in threads: threads[request.sid] = socketio.start_background_task(target=monitor_thread, sid=request.sid, user_id=user_id)
Example #13
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def terminate_monitor_connection(): sys.stderr.write("terminate_monitor_connection\n") # hopefully the disconnect will be triggered # if request.sid in threads: # rr.publish(request.sid, json.dumps(dict(origin='client', message='KILL', sid=request.sid))) socketio.emit('terminate', {}, namespace='/monitor', room=request.sid) #disconnect()
Example #14
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def monitor_unblock(data): if 'monitor' not in session: socketio.emit('terminate', {}, namespace='/monitor', room=request.sid) return key = data.get('key', None) if key is None: sys.stderr.write("No key provided\n") return sys.stderr.write("Unblocking\n") rr.delete(re.sub(r'^da:session:', 'da:block:', key)) sid = rr.get(re.sub(r'^da:session:', 'da:interviewsession:', key)) if sid is not None: sid = sid.decode() rr.publish(sid, json.dumps(dict(messagetype='chatpartner', sid=request.sid))) socketio.emit('unblock', {'key': key}, namespace='/monitor', room=request.sid)
Example #15
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def observer_thread(sid=None, key=None): sys.stderr.write("Started observer thread for " + str(sid) + "\n") r = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_offset) pubsub = r.pubsub() pubsub.subscribe([key, sid]) for item in pubsub.listen(): sys.stderr.write("2\n" + repr(item) + "\n") if item['type'] != 'message': continue #sys.stderr.write("observer sid: " + str(sid) + ":\n") data = None try: data = json.loads(item['data'].decode()) except: sys.stderr.write(" observer JSON parse error: " + item['data'].decode() + "\n") continue if 'message' in data and data['message'] == "KILL" and (('sid' in data and data['sid'] == sid) or 'sid' not in data): pubsub.unsubscribe() sys.stderr.write(" observer unsubscribed and finished for " + str(sid) + "\n") break elif 'message' in data: if data['message'] == "newpage": #sys.stderr.write(" Got new page for observer\n") try: obj = json.loads(r.get(data['key']).decode()) except: sys.stderr.write(" newpage JSON parse error\n") continue socketio.emit('newpage', {'obj': obj}, namespace='/observer', room=sid) elif data['message'] == "start_being_controlled": #sys.stderr.write(" got start_being_controlled message with key " + str(data['key']) + "\n") socketio.emit('start_being_controlled', {'key': data['key']}, namespace='/observer', room=sid) else: #sys.stderr.write(" Got parameters for observer\n") socketio.emit('pushchanges', {'parameters': data}, namespace='/observer', room=sid) sys.stderr.write(' exiting observer thread for sid ' + str(sid) + '\n')
Example #16
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def on_observer_connect(): if 'observer' not in session: socketio.emit('terminate', {}, namespace='/observer', room=request.sid) return join_room(request.sid)
Example #17
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def observer_changes(message): sys.stderr.write('observerChanges\n') if 'observer' not in session: socketio.emit('terminate', {}, namespace='/observer', room=request.sid) return sid = rr.get('da:interviewsession:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid'])) if sid is None: key = 'da:session:uid:' + str(message['uid']) + ':i:' + str(message['i']) + ':userid:' + str(message['userid']) sys.stderr.write('observerChanges: sid is none.\n') if rr.get(key) is None: sys.stderr.write('observerChanges: session has gone away for good. Sending stopcontrolling.\n') socketio.emit('stopcontrolling', {'key': key}, namespace='/observer', room=request.sid) else: socketio.emit('noconnection', {'key': key}, namespace='/observer', room=request.sid) else: sid = sid.decode() sys.stderr.write('observerChanges: sid exists at ' + time.strftime("%Y-%m-%d %H:%M:%S") + '\n') rr.publish(sid, json.dumps(dict(messagetype='controllerchanges', sid=request.sid, clicked=message.get('clicked', None), parameters=message['parameters']))) # sid=request.sid, yaml_filename=str(message['i']), uid=str(message['uid']), user_id=str(message['userid']) 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('Controlling ' + key + '\n') pipe = rr.pipeline() pipe.set(self_key, key) pipe.expire(key, 12) pipe.set(key, request.sid) pipe.expire(key, 12) pipe.execute()
Example #18
Source File: socketserver.py From docassemble with MIT License | 5 votes |
def terminate_observer_connection(): sys.stderr.write("terminate_observer_connection\n") # hopefully the disconnect will be triggered # if request.sid in threads: # rr.publish(request.sid, json.dumps(dict(origin='client', message='KILL', sid=request.sid))) socketio.emit('terminate', {}, namespace='/observer', room=request.sid) #disconnect()
Example #19
Source File: __init__.py From python-admin with MIT License | 5 votes |
def on_connect(self): client.append(request.sid) print client emit('my_response', 'θΏζ₯ζε')
Example #20
Source File: __init__.py From python-admin with MIT License | 5 votes |
def on_disconnect(self): sid = request.sid if sid in client: client.remove(sid) print client
Example #21
Source File: app_namespace.py From Flask-SocketIO with MIT License | 5 votes |
def on_disconnect(self): print('Client disconnected', request.sid)
Example #22
Source File: views.py From posio with MIT License | 5 votes |
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)
Example #23
Source File: views.py From posio with MIT License | 5 votes |
def leave_games(): app.logger.info('A player has left the game') game_master.game.remove_player(request.sid)
Example #24
Source File: views.py From posio with MIT License | 5 votes |
def store_answer(latitude, longitude): game_master.game.store_answer(request.sid, latitude, longitude)
Example #25
Source File: namespace.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #26
Source File: namespace.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_disconnect(self): sid = request.sid bui.logger.debug('Someone just disconnected! {}'.format(sid))
Example #27
Source File: follow_server.py From listenbrainz-server with GNU General Public License v2.0 | 5 votes |
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)
Example #28
Source File: gui.py From adviser with GNU General Public License v3.0 | 5 votes |
def handle_connect(): print('Client connected') clients.append(request.sid) socketio.send("Welcome!")
Example #29
Source File: gui.py From adviser with GNU General Public License v3.0 | 5 votes |
def handle_connect(): print('Client disconnected') clients.remove(request.sid)
Example #30
Source File: api.py From halocoin with Apache License 2.0 | 5 votes |
def connect(): print("%s connected" % request.sid) return ""