本文整理匯總了Python中pymongo.helpers._check_command_response方法的典型用法代碼示例。如果您正苦於以下問題:Python helpers._check_command_response方法的具體用法?Python helpers._check_command_response怎麽用?Python helpers._check_command_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymongo.helpers
的用法示例。
在下文中一共展示了helpers._check_command_response方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write_command
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _check_command_response [as 別名]
def write_command(self, request_id, msg):
"""Send "insert" etc. command, returning response as a dict.
Can raise ConnectionFailure or OperationFailure.
:Parameters:
- `request_id`: an int.
- `msg`: bytes, the command message.
"""
self.send_message(msg, 0)
response = helpers._unpack_response(self.receive_message(1, request_id))
assert response['number_returned'] == 1
result = response['data'][0]
# Raises NotMasterError or OperationFailure.
helpers._check_command_response(result)
return result
示例2: write_command
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _check_command_response [as 別名]
def write_command(self, request_id: int, msg: bytes) -> dict:
response_future = asyncio.Future(loop=self.loop)
self.__request_futures[request_id] = response_future
self.send_message(msg)
response_data = await response_future
response = helpers._unpack_response(response_data)
assert response['number_returned'] == 1
result = response['data'][0]
# Raises NotMasterError or OperationFailure.
helpers._check_command_response(result)
return result
示例3: _refresh
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _check_command_response [as 別名]
def _refresh(self) -> None:
"""Refreshes the cursor with more data from the server.
Returns the length of self.__data after refresh. Will exit early if
self.__data is already non-empty. Raises OperationFailure when the
cursor cannot be refreshed due to an error on the query.
"""
if len(self.__data) or self.__killed:
return len(self.__data)
if self.__id: # Get More
dbname, collname = self.__ns.split('.', 1)
try:
data = await self.__connection.perform_operation(
_GetMore(dbname,
collname,
self.__batch_size,
self.__id,
self.__collection.codec_options))
except EOFError:
self.__killed = True
raise
try:
doc = helpers._unpack_response(data,
self.__id,
self.__collection.codec_options)
helpers._check_command_response(doc['data'][0])
except OperationFailure:
self.__killed = True
raise
cursor = doc['data'][0]['cursor']
documents = cursor['nextBatch']
self.__id = cursor['id']
self.__retrieved += len(documents)
if self.__id == 0:
self.__killed = True
self.__data = deque(documents)
else: # Cursor id is zero nothing else to return
self.__killed = True
return len(self.__data)