MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _op_msg

Function _op_msg

pymongo/message.py:394–423  ·  view source on GitHub ↗

Get a OP_MSG message.

(
    flags: int,
    command: MutableMapping[str, Any],
    dbname: str,
    read_preference: Optional[_ServerMode],
    opts: CodecOptions[Any],
    ctx: Union[SnappyContext, ZlibContext, ZstdContext, None] = None,
)

Source from the content-addressed store, hash-verified

392
393
394def _op_msg(
395 flags: int,
396 command: MutableMapping[str, Any],
397 dbname: str,
398 read_preference: Optional[_ServerMode],
399 opts: CodecOptions[Any],
400 ctx: Union[SnappyContext, ZlibContext, ZstdContext, None] = None,
401) -> tuple[int, bytes, int, int]:
402 """Get a OP_MSG message."""
403 command["$db"] = dbname
404 # getMore commands do not send $readPreference.
405 if read_preference is not None and "$readPreference" not in command:
406 # Only send $readPreference if it's not primary (the default).
407 if read_preference.mode:
408 command["$readPreference"] = read_preference.document
409 name = next(iter(command))
410 try:
411 identifier = _FIELD_MAP[name]
412 docs = command.pop(identifier)
413 except KeyError:
414 identifier = ""
415 docs = None
416 try:
417 if ctx:
418 return _op_msg_compressed(flags, command, identifier, docs, opts, ctx)
419 return _op_msg_uncompressed(flags, command, identifier, docs, opts)
420 finally:
421 # Add the field back to the command.
422 if identifier:
423 command[identifier] = docs
424
425
426def _query_impl(

Callers 2

get_messageMethod · 0.85
get_messageMethod · 0.85

Calls 5

nextFunction · 0.85
iterFunction · 0.85
_op_msg_compressedFunction · 0.85
_op_msg_uncompressedFunction · 0.85
popMethod · 0.45

Tested by

no test coverage detected