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

Function GetRequestHandler

Lib/test/test_urllib2_localnet.py:402–442  ·  view source on GitHub ↗
(responses)

Source from the content-addressed store, hash-verified

400
401
402def GetRequestHandler(responses):
403
404 class FakeHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
405
406 server_version = "TestHTTP/"
407 requests = []
408 headers_received = []
409 port = 80
410
411 def do_GET(self):
412 body = self.send_head()
413 while body:
414 done = self.wfile.write(body)
415 body = body[done:]
416
417 def do_POST(self):
418 content_length = self.headers["Content-Length"]
419 post_data = self.rfile.read(int(content_length))
420 self.do_GET()
421 self.requests.append(post_data)
422
423 def send_head(self):
424 FakeHTTPRequestHandler.headers_received = self.headers
425 self.requests.append(self.path)
426 response_code, headers, body = responses.pop(0)
427
428 self.send_response(response_code)
429
430 for (header, value) in headers:
431 self.send_header(header, value % {'port':self.port})
432 if body:
433 self.send_header("Content-type", "text/plain")
434 self.end_headers()
435 return body
436 self.end_headers()
437
438 def log_message(self, *args):
439 pass
440
441
442 return FakeHTTPRequestHandler
443
444
445class TestUrlopen(unittest.TestCase):

Callers 2

start_serverMethod · 0.85
start_https_serverMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…