From 713d6c65fd545c6ad38d73686cfb040fd6dc217d Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 16 Jan 2019 08:14:14 +0100 Subject: insert merge key in old (absolute) position --- CHANGES | 16 ++++++++++++++++ README.rst | 22 +++++++++++++++------- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/test_z_data.py | 6 +++++- constructor.py | 8 ++++++++ representer.py | 3 ++- setup.py | 1 + timestamp.py | 3 +++ 9 files changed, 53 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index bb25af7..d56f30e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,19 @@ +[0, 15, 86]: 2019-01-16 + - reinsert merge key in its old position (reported by grumbler on + `__) + - fix for issue with non-ASCII anchor names (reported and fix + provided by Dandaleon Flux via email) + - fix for issue when parsing flow mapping value starting with colon (in pure Python only) + (reported by `FichteFoll `__) + +[0, 15, 86]: 2019-01-15 + - reinsert merge key in its old position (reported by grumbler on + `__) + - fix for issue with non-ASCII anchor names (reported and fix + provided by Dandaleon Flux via email) + - fix for issue when parsing flow mapping value starting with colon (in pure Python only) + (reported by `FichteFoll `__) + [0, 15, 85]: 2019-01-08 - the types used by `SafeConstructor` for mappings and sequences can now by set by assigning to `XXXConstructor.yaml_base_dict_type` diff --git a/README.rst b/README.rst index 7f929bb..809dd10 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.85 -:updated: 2019-01-08 +:version: 0.15.86 +:updated: 2019-01-16 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,16 +54,24 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.86 (2019-01-16): + - reinsert merge key in its old position (reported by grumbler on + `__) + - fix for issue with non-ASCII anchor names (reported and fix + provided by Dandaleon Flux via email) + - fix for issue when parsing flow mapping value starting with colon (in pure Python only) + (reported by `FichteFoll `__) + 0.15.85 (2019-01-08): - - the types used by `SafeConstructor` for mappings and sequences can - now by set by assigning to `XXXConstructor.yaml_base_dict_type` - (and `..._list_type`), preventing the need to copy two methods - with 50+ lines that had `var = {}` hardcoded. (Implemented to + - the types used by ``SafeConstructor`` for mappings and sequences can + now by set by assigning to ``XXXConstructor.yaml_base_dict_type`` + (and ``..._list_type``), preventing the need to copy two methods + with 50+ lines that had ``var = {}`` hardcoded. (Implemented to help solve an feature request by `Anthony Sottile `__ in an easier way) 0.15.84 (2019-01-07): - - fix for `CommentedMap.copy()` not returning `CommentedMap`, let alone copying comments etc. + - fix for ``CommentedMap.copy()`` not returning ``CommentedMap``, let alone copying comments etc. (reported by `Anthony Sottile `__) 0.15.83 (2019-01-02): diff --git a/__init__.py b/__init__.py index 8a0ef9e..1cb3f30 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 85), - __version__='0.15.85', + version_info=(0, 15, 86), + __version__='0.15.86', author='Anthon van der Neut', author_email='a.van.der.neut@ruamel.eu', description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index 4c05b38..23fc356 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.850.15.85 + pypipypi0.15.860.15.86 diff --git a/_test/test_z_data.py b/_test/test_z_data.py index ca75ca6..99810aa 100644 --- a/_test/test_z_data.py +++ b/_test/test_z_data.py @@ -9,6 +9,7 @@ import warnings # NOQA from ruamel.std.pathlib import Path base_path = Path('data') # that is ruamel.yaml.data +PY2 = sys.version_info[0] == 2 class YAMLData(object): @@ -124,7 +125,10 @@ class TestYAMLData(object): buf = StringIO() yaml.dump(data, buf) expected = input.value if output is None else output.value - assert buf.getvalue() == expected + value = buf.getvalue() + if PY2: + value = value.decode('utf-8') + assert value == expected def load_assert(self, input, confirm, yaml_version=None): from ruamel.yaml.compat import Mapping diff --git a/constructor.py b/constructor.py index 53e0d27..3f11c56 100644 --- a/constructor.py +++ b/constructor.py @@ -599,6 +599,14 @@ class SafeConstructor(BaseConstructor): delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute) if values['tz_sign'] == '-': delta = -delta + # should do something else instead (or hook this up to the preceding if statement + # in reverse + # if delta is None: + # return datetime.datetime(year, month, day, hour, minute, second, fraction) + # return datetime.datetime(year, month, day, hour, minute, second, fraction, + # datetime.timezone.utc) + # the above is not good enough though, should provide tzinfo. In Python3 that is easily + # doable drop that kind of support for Python2 as it has not native tzinfo data = datetime.datetime(year, month, day, hour, minute, second, fraction) if delta: data -= delta diff --git a/representer.py b/representer.py index ced41a0..7b2f007 100644 --- a/representer.py +++ b/representer.py @@ -1002,6 +1002,7 @@ class RoundTripRepresenter(SafeRepresenter): except AttributeError: item_comments = {} merge_list = [m[1] for m in getattr(mapping, merge_attrib, [])] + merge_pos = getattr(mapping, merge_attrib, [[0]])[0][0] item_count = 0 if bool(merge_list): items = mapping.non_merged_items() @@ -1039,7 +1040,7 @@ class RoundTripRepresenter(SafeRepresenter): else: arg = self.represent_data(merge_list) arg.flow_style = True - value.insert(0, (ScalarNode(u'tag:yaml.org,2002:merge', '<<'), arg)) + value.insert(merge_pos, (ScalarNode(u'tag:yaml.org,2002:merge', '<<'), arg)) return node def represent_omap(self, tag, omap, flow_style=None): diff --git a/setup.py b/setup.py index e75711c..70aee86 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ if sys.version_info < (3, 4): class NameConstant: pass + if sys.version_info >= (3, 8): from ast import Str, Num, Bytes, NameConstant # NOQA diff --git a/timestamp.py b/timestamp.py index b87a348..374e4c0 100644 --- a/timestamp.py +++ b/timestamp.py @@ -5,6 +5,9 @@ from __future__ import print_function, absolute_import, division, unicode_litera import datetime import copy +# ToDo: at least on PY3 you could probably attach the tzinfo correctly to the object +# a more complete datetime might be used by safe loading as well + if False: # MYPY from typing import Any, Dict, Optional, List # NOQA -- cgit v1.2.1