2
2
#
3
3
# Based on https://github.com/MagicStack/httptools
4
4
#
5
- from __future__ import absolute_import, print_function
6
5
7
6
from cpython cimport (
8
7
Py_buffer,
@@ -813,7 +812,9 @@ cdef parser_error_from_errno(cparser.llhttp_t* parser, data, pointer):
813
812
cdef cparser.llhttp_errno_t errno = cparser.llhttp_get_errno(parser)
814
813
cdef bytes desc = cparser.llhttp_get_error_reason(parser)
815
814
816
- if errno in (cparser.HPE_CB_MESSAGE_BEGIN,
815
+ err_msg = " {}:\n\n {!r}\n {}" .format(desc.decode(" latin-1" ), data, pointer)
816
+
817
+ if errno in {cparser.HPE_CB_MESSAGE_BEGIN,
817
818
cparser.HPE_CB_HEADERS_COMPLETE,
818
819
cparser.HPE_CB_MESSAGE_COMPLETE,
819
820
cparser.HPE_CB_CHUNK_HEADER,
@@ -823,22 +824,13 @@ cdef parser_error_from_errno(cparser.llhttp_t* parser, data, pointer):
823
824
cparser.HPE_INVALID_CONTENT_LENGTH,
824
825
cparser.HPE_INVALID_CHUNK_SIZE,
825
826
cparser.HPE_INVALID_EOF_STATE,
826
- cparser.HPE_INVALID_TRANSFER_ENCODING):
827
- cls = BadHttpMessage
828
-
829
- elif errno == cparser.HPE_INVALID_STATUS:
830
- cls = BadStatusLine
831
-
832
- elif errno == cparser.HPE_INVALID_METHOD:
833
- cls = BadStatusLine
834
-
835
- elif errno == cparser.HPE_INVALID_VERSION:
836
- cls = BadStatusLine
837
-
827
+ cparser.HPE_INVALID_TRANSFER_ENCODING}:
828
+ return BadHttpMessage(err_msg)
829
+ elif errno in {cparser.HPE_INVALID_STATUS,
830
+ cparser.HPE_INVALID_METHOD,
831
+ cparser.HPE_INVALID_VERSION}:
832
+ return BadStatusLine(error = err_msg)
838
833
elif errno == cparser.HPE_INVALID_URL:
839
- cls = InvalidURLError
840
-
841
- else :
842
- cls = BadHttpMessage
834
+ return InvalidURLError(err_msg)
843
835
844
- return cls ( " {}: \n\n {!r} \n {} " .format(desc.decode( " latin-1 " ), data, pointer) )
836
+ return BadHttpMessage(err_msg )
0 commit comments