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

Method handle

Lib/test/test_urllib2.py:410–431  ·  view source on GitHub ↗
(self, fn_name, action, *args, **kwds)

Source from the content-addressed store, hash-verified

408 setattr(self.__class__, name, meth)
409
410 def handle(self, fn_name, action, *args, **kwds):
411 self.parent.calls.append((self, fn_name, args, kwds))
412 if action is None:
413 return None
414 elif action == "return self":
415 return self
416 elif action == "return response":
417 res = MockResponse(200, "OK", {}, "")
418 return res
419 elif action == "return request":
420 return Request("http://blah/")
421 elif action.startswith("error"):
422 code = action[action.rfind(" ")+1:]
423 try:
424 code = int(code)
425 except ValueError:
426 pass
427 res = MockResponse(200, "OK", {}, "")
428 return self.parent.error("http", args[0], res, code, "", {})
429 elif action == "raise":
430 raise urllib.error.URLError("blah")
431 assert False
432
433 def close(self):
434 pass

Callers 2

test_close_connectionMethod · 0.45
__call__Method · 0.45

Calls 6

RequestClass · 0.90
MockResponseClass · 0.85
appendMethod · 0.45
startswithMethod · 0.45
rfindMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected