| 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": |