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

Function _parse_canonical_binary

bson/json_util.py:583–595  ·  view source on GitHub ↗
(doc: Any, json_options: JSONOptions)

Source from the content-addressed store, hash-verified

581
582
583def _parse_canonical_binary(doc: Any, json_options: JSONOptions) -> Union[Binary, uuid.UUID]:
584 binary = doc["$binary"]
585 b64 = binary["base64"]
586 subtype = binary["subType"]
587 if not isinstance(b64, str):
588 raise TypeError(f"$binary base64 must be a string: {doc}")
589 if not isinstance(subtype, str) or len(subtype) > 2:
590 raise TypeError(f"$binary subType must be a string at most 2 characters: {doc}")
591 if len(binary) != 2:
592 raise TypeError(f'$binary must include only "base64" and "subType" components: {doc}')
593
594 data = base64.b64decode(b64.encode())
595 return _binary_or_uuid(data, int(subtype, 16), json_options)
596
597
598def _parse_canonical_datetime(

Callers 1

_parse_binaryFunction · 0.85

Calls 2

_binary_or_uuidFunction · 0.85
encodeMethod · 0.80

Tested by

no test coverage detected