diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-04-14 08:48:38 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-04-14 08:48:38 +0200 |
commit | 784b4a6ad8a08b3f5a1ee653b80f13e1c3a30075 (patch) | |
tree | a4e536ce4a3bcf84b1a01c796483cc75e51891f1 /representer.py | |
parent | 00fc3a6a889286bd7e2a0c4fa43945ce1e6bf60c (diff) | |
download | ruamel.yaml-784b4a6ad8a08b3f5a1ee653b80f13e1c3a30075.tar.gz |
fix issue 112: hexadecimal not preserved0.14.6
please **close** this issue if fixed
Diffstat (limited to 'representer.py')
-rw-r--r-- | representer.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/representer.py b/representer.py index 5db1d98..0c19a61 100644 --- a/representer.py +++ b/representer.py @@ -8,7 +8,9 @@ from typing import Dict, List, Any, Union # NOQA from ruamel.yaml.error import * # NOQA from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.compat import text_type, binary_type, to_unicode, PY2, PY3, ordereddict -from ruamel.yaml.scalarstring import * # NOQA +from ruamel.yaml.scalarstring import (PreservedScalarString, SingleQuotedScalarString, + DoubleQuotedScalarString) +from ruamel.yaml.scalarint import BinaryInt, OctalInt, HexInt, HexCapsInt from ruamel.yaml.timestamp import TimeStamp import datetime @@ -676,6 +678,22 @@ class RoundTripRepresenter(SafeRepresenter): tag = u'tag:yaml.org,2002:str' return self.represent_scalar(tag, data, style=style) + def represent_binary_int(self, data): + # type: (Any) -> Any + return self.represent_scalar(u'tag:yaml.org,2002:int', '0b' + format(data, 'b')) + + def represent_octal_int(self, data): + # type: (Any) -> Any + return self.represent_scalar(u'tag:yaml.org,2002:int', '0o' + format(data, 'o')) + + def represent_hex_int(self, data): + # type: (Any) -> Any + return self.represent_scalar(u'tag:yaml.org,2002:int', '0x' + format(data, 'x')) + + def represent_hex_caps_int(self, data): + # type: (Any) -> Any + return self.represent_scalar(u'tag:yaml.org,2002:int', '0x' + format(data, 'X')) + def represent_sequence(self, tag, sequence, flow_style=None): # type: (Any, Any, Any) -> Any value = [] # type: List[Any] @@ -952,6 +970,22 @@ RoundTripRepresenter.add_representer( DoubleQuotedScalarString, RoundTripRepresenter.represent_double_quoted_scalarstring) +RoundTripRepresenter.add_representer( + BinaryInt, + RoundTripRepresenter.represent_binary_int) + +RoundTripRepresenter.add_representer( + OctalInt, + RoundTripRepresenter.represent_octal_int) + +RoundTripRepresenter.add_representer( + HexInt, + RoundTripRepresenter.represent_hex_int) + +RoundTripRepresenter.add_representer( + HexCapsInt, + RoundTripRepresenter.represent_hex_caps_int) + RoundTripRepresenter.add_representer(CommentedSeq, RoundTripRepresenter.represent_list) |