New upstream snapshot.
Debian Janitor
2 years ago
0 | Metadata-Version: 1.1 | |
0 | Metadata-Version: 2.1 | |
1 | 1 | Name: Flask-Sockets |
2 | Version: 0.2.1 | |
2 | Version: 0.2.1.1 | |
3 | 3 | Summary: Elegant WebSockets for your Flask apps. |
4 | 4 | Home-page: https://github.com/kennethreitz/flask-sockets |
5 | 5 | Author: Kenneth Reitz |
6 | 6 | Author-email: _@kennethreitz.com |
7 | 7 | License: See License |
8 | Description: | |
9 | Flask-Sockets | |
10 | ------------- | |
11 | ||
12 | Elegant WebSockets for your Flask apps. | |
13 | ||
14 | 8 | Platform: any |
15 | 9 | Classifier: Environment :: Web Environment |
16 | 10 | Classifier: Intended Audience :: Developers |
19 | 13 | Classifier: Programming Language :: Python |
20 | 14 | Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content |
21 | 15 | 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 | 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 | |
1 | 1 | Name: Flask-Sockets |
2 | Version: 0.2.1 | |
2 | Version: 0.2.1.1 | |
3 | 3 | Summary: Elegant WebSockets for your Flask apps. |
4 | 4 | Home-page: https://github.com/kennethreitz/flask-sockets |
5 | 5 | Author: Kenneth Reitz |
6 | 6 | Author-email: _@kennethreitz.com |
7 | 7 | License: See License |
8 | Description: | |
9 | Flask-Sockets | |
10 | ------------- | |
11 | ||
12 | Elegant WebSockets for your Flask apps. | |
13 | ||
14 | 8 | Platform: any |
15 | 9 | Classifier: Environment :: Web Environment |
16 | 10 | Classifier: Intended Audience :: Developers |
19 | 13 | Classifier: Programming Language :: Python |
20 | 14 | Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content |
21 | 15 | 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 |
71 | 71 | from geventwebsocket.handler import WebSocketHandler |
72 | 72 | server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler) |
73 | 73 | 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. | |
74 | 76 | |
75 | 77 | |
76 | 78 | 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 | ||
0 | 6 | python-flask-sockets (0.2.1-4) unstable; urgency=medium |
1 | 7 | |
2 | 8 | * Update upstream homepage. |
1 | 1 | |
2 | 2 | from werkzeug.routing import Map, Rule |
3 | 3 | 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 | |
13 | 6 | |
14 | 7 | |
15 | 8 | # Monkeys are made for freedom. |
16 | 9 | try: |
10 | from geventwebsocket.gunicorn.workers import GeventWebSocketWorker as Worker | |
11 | from geventwebsocket.handler import WebSocketHandler | |
12 | from gunicorn.workers.ggevent import PyWSGIHandler | |
13 | ||
17 | 14 | import gevent |
18 | from geventwebsocket.gunicorn.workers import GeventWebSocketWorker as Worker | |
19 | 15 | except ImportError: |
20 | 16 | 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 | |
27 | 17 | |
28 | 18 | |
29 | 19 | class SocketMiddleware(object): |
38 | 28 | try: |
39 | 29 | handler, values = adapter.match() |
40 | 30 | environment = environ['wsgi.websocket'] |
31 | cookie = None | |
32 | if 'HTTP_COOKIE' in environ: | |
33 | cookie = parse_cookie(environ['HTTP_COOKIE']) | |
41 | 34 | |
42 | 35 | with self.app.app_context(): |
43 | 36 | with self.app.request_context(environ): |
37 | # add cookie to the request to have correct session handling | |
38 | request.cookie = cookie | |
39 | ||
44 | 40 | handler(environment, **values) |
45 | 41 | return [] |
46 | 42 | except (NotFound, KeyError): |
104 | 100 | |
105 | 101 | |
106 | 102 | # 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 | |
108 | 112 | worker = Worker |