def _format_response(self, operation, response, stream): # For operations that have no response body (e.g. s3 put-object) # the response will be an empty string. We don't want to print # that out to the user but other "falsey" values like an empty # dictionary should be printed. if response: json.dump(response, stream, indent=4, default=json_encoder, ensure_ascii=False) stream.write('\n')
def dump(self, value, stream): if self._is_json_scalar(value) or isinstance(value, datetime): # YAML will attempt to disambiguate scalars by ending the stream # with an elipsis. While this is technically valid YAML, # it's not particularly useful. Unfortunately there's no # universal way around this, so instead we just json dump the # values. Also note that datetimes are explicitly not supported # - the json dumper will complain if you pass them in. datetime # values should respect the cli timestamp format, which is # impossible to do from the Formatter. json.dump(value, stream, ensure_ascii=False) stream.write('\n') else: self._yaml.dump(value, stream)