MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / format_response

Method format_response

Algorithmia/handler.py:55–71  ·  view source on GitHub ↗
(self, response)

Source from the content-addressed store, hash-verified

53 return bytearray(data)
54
55 def format_response(self, response):
56 if self.is_binary(response):
57 content_type = 'binary'
58 response = base64.b64encode(response)
59 if not isinstance(response, six.string_types):
60 response = str(response, 'utf-8')
61 elif isinstance(response, six.string_types) or isinstance(response, six.text_type):
62 content_type = 'text'
63 else:
64 content_type = 'json'
65 response_string = json.dumps({
66 'result': response,
67 'metadata': {
68 'content_type': content_type
69 }
70 })
71 return response_string
72
73 def write_to_pipe(self, data_string):
74 if os.name == "posix":

Callers 1

serveMethod · 0.95

Calls 1

is_binaryMethod · 0.95

Tested by

no test coverage detected