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

Function _make_c_string

bson/__init__.py:681–692  ·  view source on GitHub ↗

Make a 'C' string.

(string: Union[str, bytes])

Source from the content-addressed store, hash-verified

679
680
681def _make_c_string(string: Union[str, bytes]) -> bytes:
682 """Make a 'C' string."""
683 if isinstance(string, bytes):
684 try:
685 _utf_8_decode(string, None, True)
686 return string + b"\x00"
687 except UnicodeError:
688 raise InvalidStringData(
689 "strings in documents must be valid UTF-8: %r" % string
690 ) from None
691 else:
692 return _utf_8_encode(string)[0] + b"\x00"
693
694
695def _make_name(string: str) -> bytes:

Callers 2

_op_msg_no_headerFunction · 0.90
_encode_codeFunction · 0.85

Calls 1

InvalidStringDataClass · 0.90

Tested by

no test coverage detected