| 118 | self._yaml.representer.default_flow_style = False |
| 119 | |
| 120 | def dump(self, value, stream): |
| 121 | if self._is_json_scalar(value) or isinstance(value, datetime): |
| 122 | # YAML will attempt to disambiguate scalars by ending the stream |
| 123 | # with an elipsis. While this is technically valid YAML, |
| 124 | # it's not particularly useful. Unfortunately there's no |
| 125 | # universal way around this, so instead we just json dump the |
| 126 | # values. Also note that datetimes are explicitly not supported |
| 127 | # - the json dumper will complain if you pass them in. datetime |
| 128 | # values should respect the cli timestamp format, which is |
| 129 | # impossible to do from the Formatter. |
| 130 | json.dump(value, stream, ensure_ascii=False, default=json_encoder) |
| 131 | stream.write('\n') |
| 132 | else: |
| 133 | self._yaml.dump(value, stream) |
| 134 | |
| 135 | def _is_json_scalar(self, value): |
| 136 | if value is None: |