MCPcopy Index your code
hub / github.com/python/cpython / MockHTTPHandlerRedirect

Class MockHTTPHandlerRedirect

Lib/test/test_urllib2.py:499–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

497
498
499class MockHTTPHandlerRedirect(urllib.request.BaseHandler):
500 # useful for testing redirections and auth
501 # sends supplied headers and code as first response
502 # sends 200 OK as second response
503 def __init__(self, code, headers):
504 self.code = code
505 self.headers = headers
506 self.reset()
507
508 def reset(self):
509 self._count = 0
510 self.requests = []
511
512 def http_open(self, req):
513 import email, copy
514 self.requests.append(copy.deepcopy(req))
515 if self._count == 0:
516 self._count = self._count + 1
517 name = http.client.responses[self.code]
518 msg = email.message_from_string(self.headers)
519 return self.parent.error(
520 "http", req, MockFile(), self.code, name, msg)
521 else:
522 self.req = req
523 msg = email.message_from_string("\r\n\r\n")
524 return MockResponse(200, "OK", msg, "", req.get_full_url())
525
526
527if hasattr(http.client, 'HTTPSConnection'):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…