MCPcopy Index your code
hub / github.com/RustPython/RustPython / getresponse

Method getresponse

Lib/http/client.py:1406–1467  ·  view source on GitHub ↗

Get the response from the server. If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by the response_class variable. If a request has not been sent or if a previous response has not be handled

(self)

Source from the content-addressed store, hash-verified

1404 self.endheaders(body, encode_chunked=encode_chunked)
1405
1406 def getresponse(self):
1407 """Get the response from the server.
1408
1409 If the HTTPConnection is in the correct state, returns an
1410 instance of HTTPResponse or of whatever object is returned by
1411 the response_class variable.
1412
1413 If a request has not been sent or if a previous response has
1414 not be handled, ResponseNotReady is raised. If the HTTP
1415 response indicates that the connection should be closed, then
1416 it will be closed before the response is returned. When the
1417 connection is closed, the underlying socket is closed.
1418 """
1419
1420 # if a prior response has been completed, then forget about it.
1421 if self.__response and self.__response.isclosed():
1422 self.__response = None
1423
1424 # if a prior response exists, then it must be completed (otherwise, we
1425 # cannot read this response's header to determine the connection-close
1426 # behavior)
1427 #
1428 # note: if a prior response existed, but was connection-close, then the
1429 # socket and response were made independent of this HTTPConnection
1430 # object since a new request requires that we open a whole new
1431 # connection
1432 #
1433 # this means the prior response had one of two states:
1434 # 1) will_close: this connection was reset and the prior socket and
1435 # response operate independently
1436 # 2) persistent: the response was retained and we await its
1437 # isclosed() status to become true.
1438 #
1439 if self.__state != _CS_REQ_SENT or self.__response:
1440 raise ResponseNotReady(self.__state)
1441
1442 if self.debuglevel > 0:
1443 response = self.response_class(self.sock, self.debuglevel,
1444 method=self._method)
1445 else:
1446 response = self.response_class(self.sock, method=self._method)
1447
1448 try:
1449 try:
1450 response.begin()
1451 except ConnectionError:
1452 self.close()
1453 raise
1454 assert response.will_close != _UNKNOWN
1455 self.__state = _CS_IDLE
1456
1457 if response.will_close:
1458 # this effectively passes the connection to the response
1459 self.close()
1460 else:
1461 # remember this, so we can tell when it is complete
1462 self.__response = response
1463

Callers 8

test_epipeMethod · 0.95
test_response_filenoMethod · 0.95
run_clientMethod · 0.95
emitMethod · 0.45
single_requestMethod · 0.45
do_openMethod · 0.45

Calls 5

closeMethod · 0.95
ResponseNotReadyClass · 0.85
isclosedMethod · 0.80
beginMethod · 0.80
closeMethod · 0.45

Tested by 5

test_epipeMethod · 0.76
test_response_filenoMethod · 0.76
run_clientMethod · 0.76