| 1 |
# coding: utf-8 |
| 2 |
|
| 3 |
from __future__ import absolute_import |
| 4 |
|
| 5 |
from strictyaml.ruamel.representer import RoundTripRepresenter |
| 6 |
from strictyaml.ruamel.scalarstring import ScalarString |
| 7 |
from strictyaml.ruamel.emitter import Emitter |
| 8 |
from strictyaml.ruamel.serializer import Serializer |
| 9 |
from strictyaml.ruamel.resolver import BaseResolver |
| 10 |
import sys |
| 11 |
|
| 12 |
if sys.version_info[0] == 3: |
| 13 |
RoundTripRepresenter.add_representer( |
| 14 |
ScalarString, RoundTripRepresenter.represent_str |
| 15 |
) |
| 16 |
else: |
| 17 |
RoundTripRepresenter.add_representer( |
| 18 |
ScalarString, RoundTripRepresenter.represent_unicode |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
class StrictYAMLResolver(BaseResolver): |
| 23 |
def __init__(self, version=None, loader=None): |
| 24 |
BaseResolver.__init__(self, loader) |
| 25 |
|
| 26 |
|
| 27 |
class StrictYAMLDumper(Emitter, Serializer, RoundTripRepresenter, StrictYAMLResolver): |
| 28 |
def __init__( |
| 29 |
self, |
| 30 |
stream, |
| 31 |
default_style=None, |
| 32 |
default_flow_style=None, |
| 33 |
canonical=None, |
| 34 |
indent=None, |
| 35 |
width=None, |
| 36 |
allow_unicode=None, |
| 37 |
line_break=None, |
| 38 |
encoding=None, |
| 39 |
explicit_start=None, |
| 40 |
explicit_end=None, |
| 41 |
version=None, |
| 42 |
tags=None, |
| 43 |
block_seq_indent=None, |
| 44 |
top_level_colon_align=None, |
| 45 |
prefix_colon=None, |
| 46 |
): |
| 47 |
# type: (Any, StreamType, Any, bool, Union[None, int], Union[None, int], bool, Any, Any, Union[None, bool], Union[None, bool], Any, Any, Any, Any, Any) -> None # NOQA |
| 48 |
Emitter.__init__( |
| 49 |
self, |
| 50 |
stream, |
| 51 |
canonical=canonical, |
| 52 |
indent=indent, |
| 53 |
width=width, |
| 54 |
allow_unicode=allow_unicode, |
| 55 |
line_break=line_break, |
| 56 |
block_seq_indent=block_seq_indent, |
| 57 |
top_level_colon_align=top_level_colon_align, |
| 58 |
prefix_colon=prefix_colon, |
| 59 |
dumper=self, |
| 60 |
) |
| 61 |
Serializer.__init__( |
| 62 |
self, |
| 63 |
encoding=encoding, |
| 64 |
explicit_start=explicit_start, |
| 65 |
explicit_end=explicit_end, |
| 66 |
version=version, |
| 67 |
tags=tags, |
| 68 |
dumper=self, |
| 69 |
) |
| 70 |
RoundTripRepresenter.__init__( |
| 71 |
self, |
| 72 |
default_style=default_style, |
| 73 |
default_flow_style=default_flow_style, |
| 74 |
dumper=self, |
| 75 |
) |
| 76 |
StrictYAMLResolver.__init__(self, loader=self) |