MCPcopy
hub / github.com/reflex-dev/reflex / _deserialize

Method _deserialize

reflex/state.py:2195–2222  ·  view source on GitHub ↗

Deserialize the state from redis/disk. data and fp are mutually exclusive, but one must be provided. Args: data: The serialized state data. fp: The file pointer to the serialized state data. Returns: The deserialized state. Rais

(
        cls, data: bytes | None = None, fp: BinaryIO | None = None
    )

Source from the content-addressed store, hash-verified

2193
2194 @classmethod
2195 def _deserialize(
2196 cls, data: bytes | None = None, fp: BinaryIO | None = None
2197 ) -> BaseState:
2198 """Deserialize the state from redis/disk.
2199
2200 data and fp are mutually exclusive, but one must be provided.
2201
2202 Args:
2203 data: The serialized state data.
2204 fp: The file pointer to the serialized state data.
2205
2206 Returns:
2207 The deserialized state.
2208
2209 Raises:
2210 ValueError: If both data and fp are provided, or neither are provided.
2211 StateSchemaMismatchError: If the state schema does not match the expected schema.
2212 """
2213 if data is not None and fp is None:
2214 (substate_schema, state) = pickle.loads(data)
2215 elif fp is not None and data is None:
2216 (substate_schema, state) = pickle.load(fp)
2217 else:
2218 msg = "Only one of `data` or `fp` must be provided"
2219 raise ValueError(msg)
2220 if substate_schema != state._to_schema():
2221 raise StateSchemaMismatchError
2222 return state
2223
2224
2225def _serialize_type(type_: Any) -> str:

Callers 3

test_fallback_pickleFunction · 0.80
get_stateMethod · 0.80
deserializeMethod · 0.80

Calls 1

_to_schemaMethod · 0.80

Tested by 1

test_fallback_pickleFunction · 0.64