From 253509a0afc997ab1fc027fc9344aea30dc7632b Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Fri, 16 Aug 2019 07:24:14 +0200 Subject: output of # in TAG directive fixes issue #307 *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))* --- CHANGES | 5 +++++ README.rst | 9 +++++++-- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/test_issues.py | 10 ++++++++++ emitter.py | 21 ++++++++++++--------- scanner.py | 2 +- 7 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 81dbe62..14c1c67 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +[0, 16, 4]: 2019-08-16 + - fix output of TAG directives with # (reported by `Thomas Smith + `__) + + [0, 16, 3]: 2019-08-15 - move setting of version based on YAML directive to scanner, allowing to check for file version during TAG directive scanning diff --git a/README.rst b/README.rst index 04f83b7..f467618 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.16.3 -:updated: 2019-08-15 +:version: 0.16.4 +:updated: 2019-08-16 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/yaml :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,11 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.16.4 (2019-08-16): + - fix output of TAG directives with # (reported by `Thomas Smith + `__) + + 0.16.3 (2019-08-15): - split construct_object - change stuff back to keep mypy happy diff --git a/__init__.py b/__init__.py index fa58ebc..a04077d 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, 16, 3), - __version__='0.16.3', + version_info=(0, 16, 4), + __version__='0.16.4', 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 7e4cfcd..4b1b796 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.16.30.16.3 + pypipypi0.16.40.16.4 diff --git a/_test/test_issues.py b/_test/test_issues.py index f2b5d74..673ba45 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -869,6 +869,16 @@ class TestIssues: """ d = na_round_trip(inp) # NOQA + def test_issue_307(self): + inp = """ + %YAML 1.2 + %TAG ! tag:example.com,2019/path# + --- + null + ... + """ + d = na_round_trip(inp) # NOQA + # @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError) # def test_issue_ xxx(self): # inp = """ diff --git a/emitter.py b/emitter.py index 02100dd..73fbe05 100644 --- a/emitter.py +++ b/emitter.py @@ -169,7 +169,7 @@ class Emitter(object): self.prefixed_colon = self.colon if prefix_colon is None else prefix_colon + self.colon # single entry mappings in flow sequence self.brace_single_entry_mapping_in_flow_sequence = ( - brace_single_entry_mapping_in_flow_sequence + brace_single_entry_mapping_in_flow_sequence ) # NOQA # Formatting details. @@ -410,8 +410,11 @@ class Emitter(object): and self.sequence_context ): self.sequence_context = False - if root and isinstance(self.event, ScalarEvent) \ - and not self.scalar_after_indicator: + if ( + root + and isinstance(self.event, ScalarEvent) + and not self.scalar_after_indicator + ): self.write_indent() self.process_tag() if isinstance(self.event, ScalarEvent): @@ -917,14 +920,14 @@ class Emitter(object): start = end = 0 if prefix[0] == u'!': end = 1 + ch_set = u"-;/?:@&=+$,_.~*'()[]" + if self.dumper: + version = getattr(self.dumper, 'version', (1, 2)) + if version is None or version >= (1, 2): + ch_set += u'#' while end < len(prefix): ch = prefix[end] - if ( - u'0' <= ch <= u'9' - or u'A' <= ch <= u'Z' - or u'a' <= ch <= u'z' - or ch in u"-;/?!:@&=+$,_.~*'()[]" - ): + if u'0' <= ch <= u'9' or u'A' <= ch <= u'Z' or u'a' <= ch <= u'z' or ch in ch_set: end += 1 else: if start < end: diff --git a/scanner.py b/scanner.py index 885bf22..df85ae0 100644 --- a/scanner.py +++ b/scanner.py @@ -1677,7 +1677,7 @@ class Scanner(object): or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' or ch in "-;/?:@&=+$,_.!~*'()[]%" - or ((self.scanner_processing_version > (1, 1)) and ch == "#") + or ((self.scanner_processing_version > (1, 1)) and ch == '#') ): if ch == '%': chunks.append(self.reader.prefix(length)) -- cgit v1.2.1