Skip to content

Commit

Permalink
Merge pull request #1341 from ashleysommer/unnecessary_code
Browse files Browse the repository at this point in the history
Fixes #1340
  • Loading branch information
sjsadowski committed Oct 3, 2018
2 parents fafe23d + 790047e commit f742512
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions sanic/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ def request_timeout_callback(self):
self._request_stream_task.cancel()
if self._request_handler_task:
self._request_handler_task.cancel()
try:
raise RequestTimeout('Request Timeout')
except RequestTimeout as exception:
self.write_error(exception)
self.write_error(RequestTimeout('Request Timeout'))

def response_timeout_callback(self):
# Check if elapsed time since response was initiated exceeds our
Expand All @@ -170,10 +167,7 @@ def response_timeout_callback(self):
self._request_stream_task.cancel()
if self._request_handler_task:
self._request_handler_task.cancel()
try:
raise ServiceUnavailable('Response Timeout')
except ServiceUnavailable as exception:
self.write_error(exception)
self.write_error(ServiceUnavailable('Response Timeout'))

def keep_alive_timeout_callback(self):
# Check if elapsed time since last response exceeds our configured
Expand All @@ -199,8 +193,7 @@ def data_received(self, data):
# memory limits
self._total_request_size += len(data)
if self._total_request_size > self.request_max_size:
exception = PayloadTooLarge('Payload Too Large')
self.write_error(exception)
self.write_error(PayloadTooLarge('Payload Too Large'))

# Create parser if this is the first time we're receiving data
if self.parser is None:
Expand All @@ -218,8 +211,7 @@ def data_received(self, data):
message = 'Bad Request'
if self._debug:
message += '\n' + traceback.format_exc()
exception = InvalidUsage(message)
self.write_error(exception)
self.write_error(InvalidUsage(message))

def on_url(self, url):
if not self.url:
Expand All @@ -233,8 +225,7 @@ def on_header(self, name, value):
if value is not None:
if self._header_fragment == b'Content-Length' \
and int(value) > self.request_max_size:
exception = PayloadTooLarge('Payload Too Large')
self.write_error(exception)
self.write_error(PayloadTooLarge('Payload Too Large'))
try:
value = value.decode()
except UnicodeDecodeError:
Expand Down Expand Up @@ -433,7 +424,7 @@ def write_error(self, exception):
self.log_response(response)
try:
self.transport.close()
except AttributeError as e:
except AttributeError:
logger.debug('Connection lost before server could close it.')

def bail_out(self, message, from_error=False):
Expand All @@ -443,8 +434,7 @@ def bail_out(self, message, from_error=False):
self.transport.get_extra_info('peername'))
logger.debug('Exception:\n%s', traceback.format_exc())
else:
exception = ServerError(message)
self.write_error(exception)
self.write_error(ServerError(message))
logger.error(message)

def cleanup(self):
Expand Down

0 comments on commit f742512

Please sign in to comment.