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,
)
| 392 | |
| 393 | |
| 394 | def _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 | |
| 426 | def _query_impl( |
no test coverage detected