Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parser_response_3(self):
callbacks = {'on_header', 'on_headers_complete', 'on_body',
'on_message_complete'}
for cbname in callbacks:
with self.subTest('{} callback fails correctly'.format(cbname)):
with self.assertRaisesRegex(httptools.HttpParserCallbackError,
'callback failed'):
m = mock.Mock()
getattr(m, cbname).side_effect = Exception()
p = httptools.HttpResponseParser(m)
p.feed_data(RESPONSE1_HEAD + RESPONSE1_BODY)
def test_parser_request_error_in_on_message_begin(self):
class Error(Exception):
pass
m = mock.Mock()
m.on_message_begin.side_effect = Error()
p = httptools.HttpRequestParser(m)
try:
p.feed_data(UPGRADE_REQUEST1)
except httptools.HttpParserCallbackError as ex:
self.assertIsInstance(ex.__context__, Error)
else:
self.fail('HttpParserCallbackError was not raised')
def data_received(self, data):
try:
self.parser.feed_data(data)
except HttpParserCallbackError:
self.close()
raise
except HttpParserError as pex:
raise InvalidResponseFromServer(pex)