本文整理匯總了Python中pymongo.helpers._unpack_response方法的典型用法代碼示例。如果您正苦於以下問題:Python helpers._unpack_response方法的具體用法?Python helpers._unpack_response怎麽用?Python helpers._unpack_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymongo.helpers
的用法示例。
在下文中一共展示了helpers._unpack_response方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write_command
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_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: _check_with_socket
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def _check_with_socket(self, sock_info, metadata=None):
"""Return (IsMaster, round_trip_time).
Can raise ConnectionFailure or OperationFailure.
"""
cmd = SON([('ismaster', 1)])
if metadata is not None:
cmd['client'] = metadata
start = _time()
request_id, msg, max_doc_size = message.query(
0, 'admin.$cmd', 0, -1, cmd,
None, DEFAULT_CODEC_OPTIONS)
# TODO: use sock_info.command()
sock_info.send_message(msg, max_doc_size)
raw_response = sock_info.receive_message(1, request_id)
result = helpers._unpack_response(raw_response)
return IsMaster(result['data'][0]), _time() - start
示例3: _check_with_socket
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def _check_with_socket(self, sock_info):
"""Return (IsMaster, round_trip_time).
Can raise ConnectionFailure or OperationFailure.
"""
start = _time()
request_id, msg, max_doc_size = message.query(
0, 'admin.$cmd', 0, -1, {'ismaster': 1},
None, DEFAULT_CODEC_OPTIONS)
# TODO: use sock_info.command()
sock_info.send_message(msg, max_doc_size)
raw_response = sock_info.receive_message(1, request_id)
result = helpers._unpack_response(raw_response)
return IsMaster(result['data'][0]), _time() - start
示例4: __send_message
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def __send_message(self, msg):
"""Send a getmore message and handle the response.
"""
client = self.__collection.database.connection
try:
res = client._send_message_with_response(
msg, _connection_to_use=self.__conn_id)
self.__conn_id, (response, dummy0, dummy1) = res
except AutoReconnect:
# Don't try to send kill cursors on another socket
# or to another server. It can cause a _pinValue
# assertion on some server releases if we get here
# due to a socket timeout.
self.__killed = True
raise
try:
response = helpers._unpack_response(response,
self.__id,
*self.__decode_opts)
except CursorNotFound:
self.__killed = True
raise
except AutoReconnect:
# Don't send kill cursors to another server after a "not master"
# error. It's completely pointless.
self.__killed = True
client.disconnect()
raise
self.__id = response["cursor_id"]
assert response["starting_from"] == self.__retrieved, (
"Result batch started from %s, expected %s" % (
response['starting_from'], self.__retrieved))
self.__retrieved += response["number_returned"]
self.__data = deque(response["data"])
示例5: _parse_response
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def _parse_response (self, response):
self.length = -1
self.asyncon.set_terminator (16)
request_id = self.request_id
self.request_id = 0
try:
response = helpers._unpack_response(response, request_id)
except:
self.asyncon.handle_error ()
if response and response['data'] and response['data'][0].get('err') and response['data'][0].get('code'):
raise MongoDBError ("[%s] %s" % (response['data'][0]['code'], response['data'][0]['err']))
else:
self.asyncon.handle_response (response)
示例6: write_command
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_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
示例7: _unpack_response
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def _unpack_response(response, *args, **kwargs):
result = _original_methods['_unpack_response'](
response,
*args,
**kwargs
)
response_sizes.append(sys.getsizeof(response, len(response)) / 1024.0)
return result
# Wrap Cursor.insert for getting queries
示例8: install_tracker
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def install_tracker():
if pymongo.collection.Collection.insert != _insert:
pymongo.collection.Collection.insert = _insert
if pymongo.collection.Collection.update != _update:
pymongo.collection.Collection.update = _update
if pymongo.collection.Collection.remove != _remove:
pymongo.collection.Collection.remove = _remove
if pymongo.cursor.Cursor._refresh != _cursor_refresh:
pymongo.cursor.Cursor._refresh = _cursor_refresh
if pymongo.helpers._unpack_response != _unpack_response:
pymongo.helpers._unpack_response = _unpack_response
示例9: uninstall_tracker
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_response [as 別名]
def uninstall_tracker():
if pymongo.collection.Collection.insert == _insert:
pymongo.collection.Collection.insert = _original_methods['insert']
if pymongo.collection.Collection.update == _update:
pymongo.collection.Collection.update = _original_methods['update']
if pymongo.collection.Collection.remove == _remove:
pymongo.collection.Collection.remove = _original_methods['remove']
if pymongo.cursor.Cursor._refresh == _cursor_refresh:
pymongo.cursor.Cursor._refresh = _original_methods['cursor_refresh']
if pymongo.helpers._unpack_response == _unpack_response:
pymongo.helpers._unpack_response = _original_methods['_unpack_response']
示例10: _refresh
# 需要導入模塊: from pymongo import helpers [as 別名]
# 或者: from pymongo.helpers import _unpack_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)