MCPcopy Create free account
hub / github.com/cdgriffith/Box / from_msgpack

Method from_msgpack

box/box.py:1176–1198  ·  view source on GitHub ↗

Transforms msgpack bytes or file into a Box object :param msgpack_bytes: string to pass to `msgpack.unpackb` :param filename: filename to open and pass to `msgpack.unpack` :param kwargs: parameters to pass to `Box()` :return: Box object

(
            cls,
            msgpack_bytes: bytes | None = None,
            filename: str | PathLike | None = None,
            **kwargs,
        )

Source from the content-addressed store, hash-verified

1174
1175 @classmethod
1176 def from_msgpack(
1177 cls,
1178 msgpack_bytes: bytes | None = None,
1179 filename: str | PathLike | None = None,
1180 **kwargs,
1181 ) -> Box:
1182 """
1183 Transforms msgpack bytes or file into a Box object
1184
1185 :param msgpack_bytes: string to pass to `msgpack.unpackb`
1186 :param filename: filename to open and pass to `msgpack.unpack`
1187 :param kwargs: parameters to pass to `Box()`
1188 :return: Box object
1189 """
1190 box_args = {}
1191 for arg in kwargs.copy():
1192 if arg in BOX_PARAMETERS:
1193 box_args[arg] = kwargs.pop(arg)
1194
1195 data = _from_msgpack(msgpack_bytes=msgpack_bytes, filename=filename, **kwargs)
1196 if not isinstance(data, dict):
1197 raise BoxError(f"msgpack data not returned as a dictionary but rather a {type(data).__name__}")
1198 return cls(data, **box_args)
1199
1200 else:
1201

Callers 5

test_msgpack_stringsMethod · 0.45
test_msgpack_filesMethod · 0.45
test_msgpack_no_inputMethod · 0.45
_to_msgpackFunction · 0.45

Calls 4

_from_msgpackFunction · 0.90
BoxErrorClass · 0.90
popMethod · 0.80
copyMethod · 0.45

Tested by 4

test_msgpack_stringsMethod · 0.36
test_msgpack_filesMethod · 0.36
test_msgpack_no_inputMethod · 0.36