This follows the standard python naming convention for exceptions.
try:
(__, __, reason) = httputil.parse_response_start_line(header_line)
header_line = "X-Http-Reason: %s" % reason
- except httputil.HTTPInputException:
+ except httputil.HTTPInputError:
return
if not header_line:
return
self.close()
if self.stream is None:
raise gen.Return(False)
- except httputil.HTTPInputException as e:
+ except httputil.HTTPInputError as e:
gen_log.info("Malformed HTTP message from %s: %s",
self.context, e)
self.close()
if self._expected_content_remaining < 0:
# Close the stream now to stop further framing errors.
self.stream.close()
- raise httputil.HTTPOutputException(
+ raise httputil.HTTPOutputError(
"Tried to write more data than Content-Length")
if self._chunking_output and chunk:
# Don't write out empty chunks because that means END-OF-STREAM
self._expected_content_remaining != 0 and
not self.stream.closed()):
self.stream.close()
- raise httputil.HTTPOutputException(
+ raise httputil.HTTPOutputError(
"Tried to write %d bytes less than Content-Length" %
self._expected_content_remaining)
if self._chunking_output:
headers = httputil.HTTPHeaders.parse(data[eol:])
except ValueError:
# probably form split() if there was no ':' in the line
- raise httputil.HTTPInputException("Malformed HTTP headers: %r" %
- data[eol:100])
+ raise httputil.HTTPInputError("Malformed HTTP headers: %r" %
+ data[eol:100])
return start_line, headers
def _read_body(self, headers, delegate):
if content_length:
content_length = int(content_length)
if content_length > self._max_body_size:
- raise httputil.HTTPInputException("Content-Length too long")
+ raise httputil.HTTPInputError("Content-Length too long")
return self._read_fixed_body(content_length, delegate)
if headers.get("Transfer-Encoding") == "chunked":
return self._read_chunked_body(delegate)
return
total_size += chunk_len
if total_size > self._max_body_size:
- raise httputil.HTTPInputException("chunked body too large")
+ raise httputil.HTTPInputError("chunked body too large")
bytes_to_read = chunk_len
while bytes_to_read:
chunk = yield self.stream.read_bytes(
self.__class__.__name__, args, dict(self.headers))
-class HTTPInputException(Exception):
+class HTTPInputError(Exception):
"""Exception class for malformed HTTP requests or responses
from remote sources.
pass
-class HTTPOutputException(Exception):
+class HTTPOutputError(Exception):
"""Exception class for errors in HTTP output.
.. versionadded:: 4.0
try:
method, path, version = line.split(" ")
except ValueError:
- raise HTTPInputException("Malformed HTTP request line")
+ raise HTTPInputError("Malformed HTTP request line")
if not version.startswith("HTTP/"):
- raise HTTPInputException(
+ raise HTTPInputError(
"Malformed HTTP version in HTTP Request-Line: %r" % version)
return RequestStartLine(method, path, version)
line = native_str(line)
match = re.match("(HTTP/1.[01]) ([0-9]+) ([^\r]*)", line)
if not match:
- raise HTTPInputException("Error parsing response start line")
+ raise HTTPInputError("Error parsing response start line")
return ResponseStartLine(match.group(1), int(match.group(2)),
match.group(3))
if self._expected_content_remaining is not None:
self._expected_content_remaining -= len(chunk)
if self._expected_content_remaining < 0:
- self._error = httputil.HTTPOutputException(
+ self._error = httputil.HTTPOutputError(
"Tried to write more data than Content-Length")
raise self._error
self._write_buffer.append(chunk)
def finish(self):
if (self._expected_content_remaining is not None and
self._expected_content_remaining != 0):
- self._error = httputil.HTTPOutputException(
+ self._error = httputil.HTTPOutputError(
"Tried to write %d bytes less than Content-Length" %
self._expected_content_remaining)
raise self._error