diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-14 21:00:50 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-14 21:00:50 +0200 |
commit | 3a1db0b45daaf5cf7d3587170f9571691cd82bf5 (patch) | |
tree | 8d9b9aa9a7af768e29b1398acaa4aca34fc36f8a /constructor.py | |
parent | ecd5f8dbaf580fa618205845374256a301d0675f (diff) | |
download | ruamel.yaml-3a1db0b45daaf5cf7d3587170f9571691cd82bf5.tar.gz |
fix issue #165 Python2 raising error when Unicode text involved in duplicate key warning.0.15.55
I could only reproduce this in Python2, finally fixed it.
*When this change indeed resolves your problem, please **Close** this issue*.
*(You can do so using the WorkFlow pull-down (close to the top right of this page))*
Diffstat (limited to 'constructor.py')
-rw-r--r-- | constructor.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/constructor.py b/constructor.py index 9de28d0..8e1da70 100644 --- a/constructor.py +++ b/constructor.py @@ -248,11 +248,19 @@ class BaseConstructor(object): # type: (Any, Any, Any, Any, Any) -> None if key in mapping: if not self.allow_duplicate_keys: + mk = mapping.get(key) + if PY2: + if isinstance(key, unicode): + key = key.encode('utf-8') + if isinstance(value, unicode): + value = value.encode('utf-8') + if isinstance(mk, unicode): + mk = mk.encode('utf-8') args = [ 'while constructing a mapping', node.start_mark, 'found duplicate key "{}" with value "{}" ' - '(original value: "{}")'.format(key, value, mapping.get(key)), + '(original value: "{}")'.format(key, value, mk), key_node.start_mark, """ To suppress this check see: @@ -272,6 +280,9 @@ class BaseConstructor(object): # type: (Any, Any, Any, Any, Any) -> None if key in setting: if not self.allow_duplicate_keys: + if PY2: + if isinstance(key, unicode): + key = key.encode('utf-8') args = [ 'while constructing a set', node.start_mark, |