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

Function _binary_or_uuid

bson/json_util.py:552–570  ·  view source on GitHub ↗
(data: Any, subtype: int, json_options: JSONOptions)

Source from the content-addressed store, hash-verified

550
551
552def _binary_or_uuid(data: Any, subtype: int, json_options: JSONOptions) -> Union[Binary, uuid.UUID]:
553 # special handling for UUID
554 if subtype in ALL_UUID_SUBTYPES:
555 uuid_representation = json_options.uuid_representation
556 binary_value = Binary(data, subtype)
557 if uuid_representation == UuidRepresentation.UNSPECIFIED:
558 return binary_value
559 if subtype == UUID_SUBTYPE:
560 # Legacy behavior: use STANDARD with binary subtype 4.
561 uuid_representation = UuidRepresentation.STANDARD
562 elif uuid_representation == UuidRepresentation.STANDARD:
563 # subtype == OLD_UUID_SUBTYPE
564 # Legacy behavior: STANDARD is the same as PYTHON_LEGACY.
565 uuid_representation = UuidRepresentation.PYTHON_LEGACY
566 return binary_value.as_uuid(uuid_representation)
567
568 if subtype == 0:
569 return cast(uuid.UUID, data)
570 return Binary(data, subtype)
571
572
573def _parse_legacy_binary(doc: Any, json_options: JSONOptions) -> Union[Binary, uuid.UUID]:

Callers 2

_parse_legacy_binaryFunction · 0.85
_parse_canonical_binaryFunction · 0.85

Calls 2

as_uuidMethod · 0.95
BinaryClass · 0.90

Tested by

no test coverage detected