From 0ca5c4eeff5e4eab6f986703acc7f3b7f3ef18c2 Mon Sep 17 00:00:00 2001 From: John Piasetzki Date: Fri, 25 Nov 2016 14:33:17 -0500 Subject: [PATCH] Use explicit import for httptools Explicit importing the parser and the exception to save a name lookup. --- sanic/server.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index b6233031..6301d18f 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -4,7 +4,8 @@ from inspect import isawaitable from multidict import CIMultiDict from signal import SIGINT, SIGTERM from time import time -import httptools +from httptools import HttpRequestParser +from httptools.parser.errors import HttpParserError try: import uvloop as async_loop @@ -94,12 +95,12 @@ class HttpProtocol(asyncio.Protocol): if self.parser is None: assert self.request is None self.headers = [] - self.parser = httptools.HttpRequestParser(self) + self.parser = HttpRequestParser(self) # Parse request chunk or close connection try: self.parser.feed_data(data) - except httptools.parser.errors.HttpParserError as e: + except HttpParserError as e: self.bail_out( "Invalid request data, connection closed ({})".format(e))