Codebase list python-flask-sockets / 4f60051
New upstream snapshot. Debian Janitor 2 years ago
7 changed file(s) with 32 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 1.1
11 Name: Flask-Sockets
2 Version: 0.2.1
2 Version: 0.2.1.1
33 Summary: Elegant WebSockets for your Flask apps.
44 Home-page: https://github.com/kennethreitz/flask-sockets
55 Author: Kenneth Reitz
00 Metadata-Version: 1.1
11 Name: Flask-Sockets
2 Version: 0.2.1
2 Version: 0.2.1.1
33 Summary: Elegant WebSockets for your Flask apps.
44 Home-page: https://github.com/kennethreitz/flask-sockets
55 Author: Kenneth Reitz
7171 from geventwebsocket.handler import WebSocketHandler
7272 server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
7373 server.serve_forever()
74
75 Combining WebSockets with Ajax (XHR) endpoints also comes handy with the support of session handling built-in to sockets as well. As an example you could use an Ajax login call which would create a new session and accordingly set a secure HttpOnly cookie to the browser. After authorization, you can connect to the WebSocket endpoint and reuse the session handling from Flask there as well (as shown here: https://pythonhosted.org/Flask-Session/). Access to other custom cookies is also possible via Flasks ``request.cookies`` property.
7476
7577
7678 Serving WebSockets in Python was really difficult. Now it's not.
0 python-flask-sockets (0.2.1+git20170530.1.003660b-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Sun, 06 Jun 2021 12:12:45 -0000
5
06 python-flask-sockets (0.2.1-4) unstable; urgency=medium
17
28 * Update upstream homepage.
11
22 from werkzeug.routing import Map, Rule
33 from werkzeug.exceptions import NotFound
4
5
6 def log_request(self):
7 log = self.server.log
8 if log:
9 if hasattr(log, 'info'):
10 log.info(self.format_request() + '\n')
11 else:
12 log.write(self.format_request() + '\n')
4 from werkzeug.http import parse_cookie
5 from flask import request
136
147
158 # Monkeys are made for freedom.
169 try:
10 from geventwebsocket.gunicorn.workers import GeventWebSocketWorker as Worker
11 from geventwebsocket.handler import WebSocketHandler
12 from gunicorn.workers.ggevent import PyWSGIHandler
13
1714 import gevent
18 from geventwebsocket.gunicorn.workers import GeventWebSocketWorker as Worker
1915 except ImportError:
2016 pass
21
22
23 if 'gevent' in locals():
24 # Freedom-Patch logger for Gunicorn.
25 if hasattr(gevent, 'pywsgi'):
26 gevent.pywsgi.WSGIHandler.log_request = log_request
2717
2818
2919 class SocketMiddleware(object):
3828 try:
3929 handler, values = adapter.match()
4030 environment = environ['wsgi.websocket']
31 cookie = None
32 if 'HTTP_COOKIE' in environ:
33 cookie = parse_cookie(environ['HTTP_COOKIE'])
4134
4235 with self.app.app_context():
4336 with self.app.request_context(environ):
37 # add cookie to the request to have correct session handling
38 request.cookie = cookie
39
4440 handler(environment, **values)
4541 return []
4642 except (NotFound, KeyError):
104100
105101
106102 # CLI sugar.
107 if 'Worker' in locals():
103 if ('Worker' in locals() and 'PyWSGIHandler' in locals() and
104 'gevent' in locals()):
105
106 class GunicornWebSocketHandler(PyWSGIHandler, WebSocketHandler):
107 def log_request(self):
108 if '101' not in self.status:
109 super(GunicornWebSocketHandler, self).log_request()
110
111 Worker.wsgi_handler = GunicornWebSocketHandler
108112 worker = Worker
00 [egg_info]
11 tag_build =
22 tag_date = 0
3 tag_svn_revision = 0
43
1010
1111 setup(
1212 name='Flask-Sockets',
13 version='0.2.1',
13 version='0.2.1.1',
1414 url='https://github.com/kennethreitz/flask-sockets',
1515 license='See License',
1616 author='Kenneth Reitz',