MCPcopy Create free account
hub / github.com/Freedium-cfd/web / CacheData

Class CacheData

database-lib/database_lib/main.py:22–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22class CacheData:
23 __slots__ = ("data",)
24
25 def __init__(self, data: str):
26 self.data = data
27
28 def json(self):
29 try:
30 return json.loads(self.data)
31 except json.JSONDecodeError:
32 logger.warning(
33 f"Failed to decode JSON data: {self.data[:100]}... Trying workaround"
34 )
35 return self.workaround_decode_json()
36
37 def workaround_decode_json(self):
38 if self.data.startswith("\\x"):
39 s = self.data[2:]
40 else:
41 s = self.data
42
43 byte_string = codecs.decode(s, "hex")
44 json_string = byte_string.decode("utf-8")
45
46 return json.loads(json_string)
47
48 def __repr__(self):
49 return self.data
50
51 def __str__(self):
52 return self.data
53
54 def has_data(self):
55 return self.data is not None and self.data != ""
56
57
58class CacheResponse:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected