def test_run_asynchronous_query_ResponseNotReady(self): """BigQueryCall should wrap ResponseNotReady to a BigQueryCommunicationError.""" mock_job_collection = mock.Mock() mock_job_collection_insert = mock.Mock() self.mock_authenticated_service.jobs.return_value = mock_job_collection mock_job_collection.insert.return_value = mock_job_collection_insert mock_job_collection_insert.execute.side_effect = httplib.ResponseNotReady( ) with self.assertRaises(external.BigQueryCommunicationError): self.call.run_asynchronous_query('dummy_query_string')
def getresponse(self): if self._current_response is None: raise httplib.ResponseNotReady() r = self._current_response while r.headers is None: r._select() if r.will_close: self.sock = None self._current_response = None elif r.complete(): self._current_response = None else: self._current_response_taken = True return r
def getresponse(self): """Returns the response to the most recent request.""" if self._current_response is None: raise httplib.ResponseNotReady() r = self._current_response while r.headers is None: # We're a friend of the response class, so let us use the # private attribute. # pylint: disable=W0212 if not r._select() and not r.complete(): raise _readers.HTTPRemoteClosedError() if r.will_close: self.sock = None self._current_response = None elif r.complete(): self._current_response = None else: self._current_response_taken = True return r
def HTTPResponse__getheaders(self): """Return list of (header, value) tuples.""" if self.msg is None: raise httplib.ResponseNotReady() return self.msg.items()
def getheaders(self): if self.headers is None: raise httplib.ResponseNotReady() return self.headers.items()
def getheader(self, name, default=None): if self.headers is None: raise httplib.ResponseNotReady() return self.headers.getheader(name, default)
def side_effect(mo, **kwargs): self.assertEqual(managed_object, mo._type) self.assertEqual(managed_object, mo.value) raise httplib.ResponseNotReady()
def getresponse_static(self): """Get the response from the server. This is a static method used by getresponse in http and https""" #modified to read any extra data from pipe # if a prior response has been completed, then forget about it. if self._HTTPConnection__response: closed = self._HTTPConnection__response.isclosed() if not closed: self._HTTPConnection__response.read() self._HTTPConnection__response = None # # if a prior response exists, then it must be completed (otherwise, we # cannot read this response's header to determine the connection-close # behavior) # # note: if a prior response existed, but was connection-close, then the # socket and response were made independent of this HTTPConnection # object since a new request requires that we open a whole new # connection # # this means the prior response had one of two states: # 1) will_close: this connection was reset and the prior socket and # response operate independently # 2) persistent: the response was retained and we await its # isclosed() status to become true. # if self._HTTPConnection__state != httplib._CS_REQ_SENT or self._HTTPConnection__response: #print 'not ready %s %s' % (self._HTTPConnection__state, self._HTTPConnection__response) raise httplib.ResponseNotReady('State is %s' % self._HTTPConnection__state) if self.debuglevel > 0: response = self.response_class(self.sock, self.debuglevel, strict=self.strict, method=self._method) else: response = self.response_class(self.sock, strict=self.strict, method=self._method) response.begin() assert response.will_close != httplib._UNKNOWN self._HTTPConnection__state = httplib._CS_IDLE if response.will_close: # this effectively passes the connection to the response self.close() #hax: #self._HTTPConnection__response = response else: # remember this, so we can tell when it is complete self._HTTPConnection__response = response return response
def read(self, amt=None): if self._content is None: raise httplib.ResponseNotReady() return self._content.read(amt)