Merge branch 'master' of https://github.com/channelcat/sanic
This commit is contained in:
commit
6fb60ae0b1
|
@ -1,5 +1,6 @@
|
||||||
aiofiles
|
aiofiles
|
||||||
aiohttp==1.3.5
|
aiohttp==1.3.5
|
||||||
|
chardet<=2.3.0
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
coverage
|
coverage
|
||||||
httptools
|
httptools
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from sanic.app import Sanic
|
from sanic.app import Sanic
|
||||||
from sanic.blueprints import Blueprint
|
from sanic.blueprints import Blueprint
|
||||||
|
|
||||||
__version__ = '0.4.1'
|
__version__ = '0.5.0'
|
||||||
|
|
||||||
__all__ = ['Sanic', 'Blueprint']
|
__all__ = ['Sanic', 'Blueprint']
|
||||||
|
|
|
@ -30,7 +30,7 @@ from sanic.websocket import WebSocketProtocol, ConnectionClosed
|
||||||
class Sanic:
|
class Sanic:
|
||||||
|
|
||||||
def __init__(self, name=None, router=None, error_handler=None,
|
def __init__(self, name=None, router=None, error_handler=None,
|
||||||
load_env=True,
|
load_env=True, request_class=None,
|
||||||
log_config_path=os.path.join(lib_path[0], "default.conf")):
|
log_config_path=os.path.join(lib_path[0], "default.conf")):
|
||||||
conf = None
|
conf = None
|
||||||
if log_config_path and os.path.exists(log_config_path):
|
if log_config_path and os.path.exists(log_config_path):
|
||||||
|
@ -55,6 +55,7 @@ class Sanic:
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.router = router or Router()
|
self.router = router or Router()
|
||||||
|
self.request_class = request_class
|
||||||
self.error_handler = error_handler or ErrorHandler()
|
self.error_handler = error_handler or ErrorHandler()
|
||||||
self.config = Config(load_env=load_env)
|
self.config = Config(load_env=load_env)
|
||||||
self.log_config_path = log_config_path
|
self.log_config_path = log_config_path
|
||||||
|
@ -694,6 +695,7 @@ class Sanic:
|
||||||
|
|
||||||
server_settings = {
|
server_settings = {
|
||||||
'protocol': protocol,
|
'protocol': protocol,
|
||||||
|
'request_class': self.request_class,
|
||||||
'host': host,
|
'host': host,
|
||||||
'port': port,
|
'port': port,
|
||||||
'sock': sock,
|
'sock': sock,
|
||||||
|
|
|
@ -65,6 +65,7 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
'parser', 'request', 'url', 'headers',
|
'parser', 'request', 'url', 'headers',
|
||||||
# request config
|
# request config
|
||||||
'request_handler', 'request_timeout', 'request_max_size',
|
'request_handler', 'request_timeout', 'request_max_size',
|
||||||
|
'request_class',
|
||||||
# enable or disable access log / error log purpose
|
# enable or disable access log / error log purpose
|
||||||
'has_log_file',
|
'has_log_file',
|
||||||
# connection management
|
# connection management
|
||||||
|
@ -72,7 +73,7 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
|
|
||||||
def __init__(self, *, loop, request_handler, error_handler,
|
def __init__(self, *, loop, request_handler, error_handler,
|
||||||
signal=Signal(), connections=set(), request_timeout=60,
|
signal=Signal(), connections=set(), request_timeout=60,
|
||||||
request_max_size=None, has_log_file=True):
|
request_max_size=None, request_class=None, has_log_file=True):
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.transport = None
|
self.transport = None
|
||||||
self.request = None
|
self.request = None
|
||||||
|
@ -86,6 +87,7 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
self.error_handler = error_handler
|
self.error_handler = error_handler
|
||||||
self.request_timeout = request_timeout
|
self.request_timeout = request_timeout
|
||||||
self.request_max_size = request_max_size
|
self.request_max_size = request_max_size
|
||||||
|
self.request_class = request_class or Request
|
||||||
self._total_request_size = 0
|
self._total_request_size = 0
|
||||||
self._timeout_handler = None
|
self._timeout_handler = None
|
||||||
self._last_request_time = None
|
self._last_request_time = None
|
||||||
|
@ -155,7 +157,7 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
self.headers.append((name.decode().casefold(), value.decode()))
|
self.headers.append((name.decode().casefold(), value.decode()))
|
||||||
|
|
||||||
def on_headers_complete(self):
|
def on_headers_complete(self):
|
||||||
self.request = Request(
|
self.request = self.request_class(
|
||||||
url_bytes=self.url,
|
url_bytes=self.url,
|
||||||
headers=CIDict(self.headers),
|
headers=CIDict(self.headers),
|
||||||
version=self.parser.get_http_version(),
|
version=self.parser.get_http_version(),
|
||||||
|
@ -355,7 +357,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
request_timeout=60, ssl=None, sock=None, request_max_size=None,
|
request_timeout=60, ssl=None, sock=None, request_max_size=None,
|
||||||
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
|
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
|
||||||
register_sys_signals=True, run_async=False, connections=None,
|
register_sys_signals=True, run_async=False, connections=None,
|
||||||
signal=Signal(), has_log_file=True):
|
signal=Signal(), request_class=None, has_log_file=True):
|
||||||
"""Start asynchronous HTTP Server on an individual process.
|
"""Start asynchronous HTTP Server on an individual process.
|
||||||
|
|
||||||
:param host: Address to host on
|
:param host: Address to host on
|
||||||
|
@ -380,6 +382,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
:param reuse_port: `True` for multiple workers
|
:param reuse_port: `True` for multiple workers
|
||||||
:param loop: asyncio compatible event loop
|
:param loop: asyncio compatible event loop
|
||||||
:param protocol: subclass of asyncio protocol class
|
:param protocol: subclass of asyncio protocol class
|
||||||
|
:param request_class: Request class to use
|
||||||
:param has_log_file: disable/enable access log and error log
|
:param has_log_file: disable/enable access log and error log
|
||||||
:return: Nothing
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
|
@ -402,6 +405,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
error_handler=error_handler,
|
error_handler=error_handler,
|
||||||
request_timeout=request_timeout,
|
request_timeout=request_timeout,
|
||||||
request_max_size=request_max_size,
|
request_max_size=request_max_size,
|
||||||
|
request_class=request_class,
|
||||||
has_log_file=has_log_file
|
has_log_file=has_log_file
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
from sanic.log import log
|
from sanic.log import log
|
||||||
|
|
||||||
HOST = '127.0.0.1'
|
HOST = '127.0.0.1'
|
||||||
|
@ -50,6 +52,8 @@ class SanicTestClient:
|
||||||
**request_kwargs)
|
**request_kwargs)
|
||||||
results[-1] = response
|
results[-1] = response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
log.error(
|
||||||
|
'Exception:\n{}'.format(traceback.format_exc()))
|
||||||
exceptions.append(e)
|
exceptions.append(e)
|
||||||
self.app.stop()
|
self.app.stop()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user