From 3f1b3613ef9631264825692a4041e39a80434cdc Mon Sep 17 00:00:00 2001 From: cr0hn Date: Sun, 29 Mar 2015 16:30:45 +0200 Subject: [PATCH 1/4] Add: new backend that use asyncio python3 framework, throught aiohttp-wsgi module. aiohttp-wsgi module need accept a pull request sent to accept some new features to be compatible with chaussete --- chaussette/backend/__init__.py | 9 +++++++- chaussette/backend/_asyncio3k.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 chaussette/backend/_asyncio3k.py diff --git a/chaussette/backend/__init__.py b/chaussette/backend/__init__.py index cff35ae..bed7f42 100644 --- a/chaussette/backend/__init__.py +++ b/chaussette/backend/__init__.py @@ -23,6 +23,13 @@ pass +try: + from chaussette.backend import _asyncio3k + _backends['asyncio3k'] = _asyncio3k.Server +except ImportError as e: + print(e) + + PY3 = sys.version_info[0] == 3 if not PY3: @@ -49,7 +56,7 @@ try: from chaussette.backend import _eventlet - _backends['eventlet'] = _eventlet.Server + _backends['eventlet'] = _eventlet.d except ImportError: pass diff --git a/chaussette/backend/_asyncio3k.py b/chaussette/backend/_asyncio3k.py new file mode 100644 index 0000000..9fc721f --- /dev/null +++ b/chaussette/backend/_asyncio3k.py @@ -0,0 +1,36 @@ +import socket +import asyncio +import aiohttp_wsgi +from chaussette.util import create_socket + + +class Server(object): + address_family = socket.AF_INET + socket_type = socket.SOCK_STREAM + + def __init__(self, listener, application=None, backlog=2048, + socket_type=socket.SOCK_STREAM, + address_family=socket.AF_INET): + self.address_family = address_family + self.socket_type = socket_type + host, port = listener + self.socket = create_socket(host, port, self.address_family, + self.socket_type, backlog=backlog) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.application = application + self.backlog = backlog + self.port = port + self.host = host + + # P3k asyncio + self.loop = asyncio.new_event_loop() + asyncio.set_event_loop(self.loop) + + def serve_forever(self): + aiohttp_wsgi.serve(self.application, + loop=self.loop, + port=self.port, + host=self.host, + **dict(socket=self.socket, + backlog=self.backlog)) + print("Serving") \ No newline at end of file From ffe995ca82dfac2c590573cd29daa730f8705095 Mon Sep 17 00:00:00 2001 From: cr0hn Date: Sun, 29 Mar 2015 16:48:44 +0200 Subject: [PATCH 2/4] Add: new backend that use asyncio python3 framework, throught aiohttp-wsgi module. aiohttp-wsgi module need accept a pull request sent to accept some new features to be compatible with chaussete --- chaussette/backend/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaussette/backend/__init__.py b/chaussette/backend/__init__.py index bed7f42..2ad5a84 100644 --- a/chaussette/backend/__init__.py +++ b/chaussette/backend/__init__.py @@ -56,7 +56,7 @@ try: from chaussette.backend import _eventlet - _backends['eventlet'] = _eventlet.d + _backends['eventlet'] = _eventlet.Server except ImportError: pass From add72ea37cd8046e320746eafc56e60923cb1b66 Mon Sep 17 00:00:00 2001 From: cr0hn Date: Mon, 15 Jun 2015 13:10:34 +0200 Subject: [PATCH 3/4] Update __init__.py removed print statement --- chaussette/backend/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaussette/backend/__init__.py b/chaussette/backend/__init__.py index 2ad5a84..0e701a0 100644 --- a/chaussette/backend/__init__.py +++ b/chaussette/backend/__init__.py @@ -27,7 +27,7 @@ from chaussette.backend import _asyncio3k _backends['asyncio3k'] = _asyncio3k.Server except ImportError as e: - print(e) + pass PY3 = sys.version_info[0] == 3 From 5e6bf81310f00d402bcd292680b006f9b08b5ca9 Mon Sep 17 00:00:00 2001 From: cr0hn Date: Mon, 15 Jun 2015 13:11:31 +0200 Subject: [PATCH 4/4] Update _asyncio3k.py Removed dict as a parameter. --- chaussette/backend/_asyncio3k.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chaussette/backend/_asyncio3k.py b/chaussette/backend/_asyncio3k.py index 9fc721f..0f709f4 100644 --- a/chaussette/backend/_asyncio3k.py +++ b/chaussette/backend/_asyncio3k.py @@ -31,6 +31,5 @@ def serve_forever(self): loop=self.loop, port=self.port, host=self.host, - **dict(socket=self.socket, - backlog=self.backlog)) - print("Serving") \ No newline at end of file + socket=self.socket, + backlog=self.backlog)