response.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright 2014-2015 MongoDB, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Represent a response from the server."""
  15. class Response(object):
  16. __slots__ = ('_data', '_address')
  17. def __init__(self, data, address):
  18. """Represent a response from the server.
  19. :Parameters:
  20. - `data`: Raw BSON bytes.
  21. - `address`: (host, port) of the source server.
  22. """
  23. self._data = data
  24. self._address = address
  25. @property
  26. def data(self):
  27. """Server response's raw BSON bytes."""
  28. return self._data
  29. @property
  30. def address(self):
  31. """(host, port) of the source server."""
  32. return self._address
  33. class ExhaustResponse(Response):
  34. __slots__ = ('_socket_info', '_pool')
  35. def __init__(self, data, address, socket_info, pool):
  36. """Represent a response to an exhaust cursor's initial query.
  37. :Parameters:
  38. - `data`: Raw BSON bytes.
  39. - `address`: (host, port) of the source server.
  40. - `socket_info`: The SocketInfo used for the initial query.
  41. - `pool`: The Pool from which the SocketInfo came.
  42. """
  43. super(ExhaustResponse, self).__init__(data, address)
  44. self._socket_info = socket_info
  45. self._pool = pool
  46. @property
  47. def socket_info(self):
  48. """The SocketInfo used for the initial query.
  49. The server will send batches on this socket, without waiting for
  50. getMores from the client, until the result set is exhausted or there
  51. is an error.
  52. """
  53. return self._socket_info
  54. @property
  55. def pool(self):
  56. """The Pool from which the SocketInfo came."""
  57. return self._pool