MCPcopy Index your code
hub / github.com/googleapis/google-api-python-client / JsonModel

Class JsonModel

googleapiclient/model.py:267–311  ·  view source on GitHub ↗

Model class for JSON. Serializes and de-serializes between JSON and the Python object representation of HTTP request and response bodies.

Source from the content-addressed store, hash-verified

265
266
267class JsonModel(BaseModel):
268 """Model class for JSON.
269
270 Serializes and de-serializes between JSON and the Python
271 object representation of HTTP request and response bodies.
272 """
273
274 accept = "application/json"
275 content_type = "application/json"
276 alt_param = "json"
277
278 def __init__(self, data_wrapper=False):
279 """Construct a JsonModel.
280
281 Args:
282 data_wrapper: boolean, wrap requests and responses in a data wrapper
283 """
284 self._data_wrapper = data_wrapper
285
286 def serialize(self, body_value):
287 if (
288 isinstance(body_value, dict)
289 and "data" not in body_value
290 and self._data_wrapper
291 ):
292 body_value = {"data": body_value}
293 return json.dumps(body_value)
294
295 def deserialize(self, content):
296 try:
297 content = content.decode("utf-8")
298 except AttributeError:
299 pass
300 try:
301 body = json.loads(content)
302 except json.decoder.JSONDecodeError:
303 body = content
304 else:
305 if self._data_wrapper and "data" in body:
306 body = body["data"]
307 return body
308
309 @property
310 def no_content_response(self):
311 return {}
312
313
314class RawModel(JsonModel):

Callers 15

__call__Method · 0.90
build_from_documentFunction · 0.90
test_json_no_bodyMethod · 0.90
test_json_bodyMethod · 0.90
test_json_build_queryMethod · 0.90
test_user_agentMethod · 0.90
test_bad_responseMethod · 0.90
test_good_responseMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_json_no_bodyMethod · 0.72
test_json_bodyMethod · 0.72
test_json_build_queryMethod · 0.72
test_user_agentMethod · 0.72
test_bad_responseMethod · 0.72
test_good_responseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…