53
53
from bson import CodecOptions
54
54
from pymongo .asynchronous .client_session import AsyncClientSession
55
55
from pymongo .asynchronous .mongo_client import AsyncMongoClient
56
- from pymongo .asynchronous .pool import AsyncConnection , AsyncStreamConnection , AsyncConnectionStream
56
+ from pymongo .asynchronous .pool import AsyncConnection , AsyncStreamConnection , AsyncConnectionProtocol
57
57
from pymongo .compression_support import SnappyContext , ZlibContext , ZstdContext
58
58
from pymongo .monitoring import _EventListeners
59
59
from pymongo .read_concern import ReadConcern
70
70
71
71
72
72
async def command_stream (
73
- conn : AsyncConnectionStream ,
73
+ conn : AsyncConnectionProtocol ,
74
74
dbname : str ,
75
75
spec : MutableMapping [str , Any ],
76
76
is_mongos : bool ,
@@ -317,7 +317,7 @@ async def command_stream(
317
317
318
318
319
319
async def receive_message (
320
- conn : AsyncConnectionStream , request_id : Optional [int ], max_message_size : int = MAX_MESSAGE_SIZE
320
+ conn : AsyncConnectionProtocol , request_id : Optional [int ], max_message_size : int = MAX_MESSAGE_SIZE
321
321
) -> Union [_OpReply , _OpMsg ]:
322
322
"""Receive a raw BSON message or raise socket.error."""
323
323
# if _csot.get_timeout():
@@ -330,28 +330,28 @@ async def receive_message(
330
330
# deadline = None
331
331
deadline = None
332
332
# Ignore the response's request id.
333
- length , _ , response_to , op_code = _UNPACK_HEADER (await async_receive_data (conn , 16 , deadline ))
333
+ data , op_code = await async_receive_data (conn , 0 , deadline )
334
+ # length, _, response_to, op_code = _UNPACK_HEADER(await async_receive_data(conn, 16, deadline))
334
335
# No request_id for exhaust cursor "getMore".
335
- if request_id is not None :
336
- if request_id != response_to :
337
- raise ProtocolError (f"Got response id { response_to !r} but expected { request_id !r} " )
338
- if length <= 16 :
339
- raise ProtocolError (
340
- f"Message length ({ length !r} ) not longer than standard message header size (16)"
341
- )
342
- if length > max_message_size :
343
- raise ProtocolError (
344
- f"Message length ({ length !r} ) is larger than server max "
345
- f"message size ({ max_message_size !r} )"
346
- )
347
- if op_code == 2012 :
348
- op_code , _ , compressor_id = _UNPACK_COMPRESSION_HEADER (
349
- await async_receive_data (conn , 9 , deadline )
350
- )
351
- data = decompress (await async_receive_data (conn , length - 25 , deadline ), compressor_id )
352
- else :
353
- data = await async_receive_data (conn , length - 16 , deadline )
354
-
336
+ # if request_id is not None:
337
+ # if request_id != response_to:
338
+ # raise ProtocolError(f"Got response id {response_to!r} but expected {request_id!r}")
339
+ # if length <= 16:
340
+ # raise ProtocolError(
341
+ # f"Message length ({length!r}) not longer than standard message header size (16)"
342
+ # )
343
+ # if length > max_message_size:
344
+ # raise ProtocolError(
345
+ # f"Message length ({length!r}) is larger than server max "
346
+ # f"message size ({max_message_size!r})"
347
+ # )
348
+ # if op_code == 2012:
349
+ # op_code, _, compressor_id = _UNPACK_COMPRESSION_HEADER(
350
+ # await async_receive_data(conn, 9, deadline)
351
+ # )
352
+ # data = decompress(await async_receive_data(conn, length - 25, deadline), compressor_id)
353
+ # else:
354
+ # data = await async_receive_data(conn, length - 16, deadline)
355
355
try :
356
356
unpack_reply = _UNPACK_REPLY [op_code ]
357
357
except KeyError :
0 commit comments