Codebase list python-flask-sockets / fresh-snapshots/main
New upstream snapshot. Debian Janitor 2 years ago
9 changed file(s) with 60 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
0 Metadata-Version: 1.1
0 Metadata-Version: 2.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
66 Author-email: _@kennethreitz.com
77 License: See License
8 Description:
9 Flask-Sockets
10 -------------
11
12 Elegant WebSockets for your Flask apps.
13
148 Platform: any
159 Classifier: Environment :: Web Environment
1610 Classifier: Intended Audience :: Developers
1913 Classifier: Programming Language :: Python
2014 Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
2115 Classifier: Topic :: Software Development :: Libraries :: Python Modules
16 License-File: LICENSE
17
18
19 Flask-Sockets
20 -------------
21
22 Elegant WebSockets for your Flask apps.
23
24
0 LICENSE
01 README.rst
12 flask_sockets.py
23 setup.py
0 Copyright (C) 2013 Kenneth Reitz
1
2 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
4 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
6 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 Metadata-Version: 1.1
0 Metadata-Version: 2.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
66 Author-email: _@kennethreitz.com
77 License: See License
8 Description:
9 Flask-Sockets
10 -------------
11
12 Elegant WebSockets for your Flask apps.
13
148 Platform: any
159 Classifier: Environment :: Web Environment
1610 Classifier: Intended Audience :: Developers
1913 Classifier: Programming Language :: Python
2014 Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
2115 Classifier: Topic :: Software Development :: Libraries :: Python Modules
16 License-File: LICENSE
17
18
19 Flask-Sockets
20 -------------
21
22 Elegant WebSockets for your Flask apps.
23
24
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> Mon, 04 Apr 2022 17:55:54 -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',