Projects
openEuler:Mainline
python-ruamel-yaml
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 10
View file
_service:tar_scm:python-ruamel-yaml.spec
Changed
@@ -1,11 +1,11 @@ %global _empty_manifest_terminate_build 0 Name: python-ruamel-yaml -Version: 0.17.21 +Version: 0.17.32 Release: 1 Summary: ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order License: MIT URL: https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree -Source0: https://files.pythonhosted.org/packages/46/a9/6ed24832095b692a8cecc323230ce2ec3480015fbfa4b79941bd41b23a3c/ruamel.yaml-0.17.21.tar.gz +Source0: https://files.pythonhosted.org/packages/63/dd/b4719a290e49015536bd0ab06ab13e3b468d8697bec6c2f668ac48b05661/ruamel.yaml-0.17.32.tar.gz BuildArch: noarch Patch0001: 0000-fix-big-endian-issues.patch %description @@ -80,6 +80,9 @@ %doc README.rst CHANGES %changelog +* Fri Jul 14 2023 chenzixuan <chenzixuan@kylinos.cn> - 0.17.32-1 +- Upgrade python3-ruamel-yaml to version 0.17.32 + * Sat Jun 04 2022 OpenStack_SIG <openstack@openeuler.org> - 0.17.21-1 - Upgrade python3-ruamel-yaml to version 0.17.21
View file
_service:tar_scm:0000-fix-big-endian-issues.patch
Changed
@@ -5,21 +5,24 @@ As the cpython code has an endianness bug https://sourceforge.net/p/ruamel-yaml/tickets/360/ Thanks to Rebecca N. Palmer for the tip about sys.byteorder! +--- + main.py | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) -Index: ruamel.yaml/main.py -=================================================================== ---- ruamel.yaml.orig/main.py 2021-10-14 00:10:27.265523204 +0200 -+++ ruamel.yaml/main.py 2021-10-14 00:11:02.469504291 +0200 -@@ -51,7 +51,7 @@ - - - class YAML: -- def __init__(self, *, typ=None, pure=False, output=None, plug_ins=None): # input=None, -+ def __init__(self, *, typ=None, pure=None, output=None, plug_ins=None): # input=None, - # type: (Any, OptionalText, Any, Any, Any) -> None - """ - typ: 'rt'/None -> RoundTripLoader/RoundTripDumper, (default) -@@ -64,6 +64,11 @@ +diff --git a/main.py b/main.py +index 9068282..49e70a4 100644 +--- a/main.py ++++ b/main.py +@@ -55,7 +55,7 @@ class YAML: + self: Any, + *, + typ: OptionalUnionListText, Text = None, +- pure: Any = False, ++ pure: Any = None, + output: Any = None, + plug_ins: Any = None, + ) -> None: # input=None, +@@ -70,6 +70,11 @@ class YAML: """ self.typ = 'rt' if typ is None else (typ if isinstance(typ, list) else typ) @@ -31,3 +34,6 @@ self.pure = pure # self._input = input +-- +2.39.1 +
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/.ruamel
Deleted
-(directory)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/.ruamel/__init__.py
Deleted
@@ -1,2 +0,0 @@ -import pkg_resources -pkg_resources.declare_namespace(__name__)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/ruamel.yaml.egg-info/namespace_packages.txt
Deleted
@@ -1,1 +0,0 @@ -ruamel
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/CHANGES -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/CHANGES
Changed
@@ -1,3 +1,93 @@ +0, 17, 32: 2023-06-17 + - fix issue with scanner getting stuck in infinite loop + +0, 17, 31: 2023-05-31 + - added tag.setter on `ScalarEvent` and on `Node`, that takes either + a `Tag` instance, or a str + (reported by `Sorin Sbarnea <https://sourceforge.net/u/ssbarnea/profile/>`__) + +0, 17, 30: 2023-05-30 + - fix issue 467, caused by Tag instances not being hashable (reported by + `Douglas Raillard + <https://bitbucket.org/%7Bcf052d92-a278-4339-9aa8-de41923bb556%7D/>`__) + +0, 17, 29: 2023-05-30 + - changed the internals of the tag property from a string to a class which allows + for preservation of the original handle and suffix. This should + result in better results using documents with %TAG directives, as well + as preserving URI escapes in tag suffixes. + +0, 17, 28: 2023-05-26 + - fix for issue 464: documents ending with document end marker without final newline + fail to load (reported by `Mariusz Rusiniak <https://sourceforge.net/u/r2dan/profile/>`__) + +0, 17, 27: 2023-05-25 + - fix issue with inline mappings as value for merge keys + (reported by Sirish on `StackOverflow <https://stackoverflow.com/q/76331049/1307905>`__) + - fix for 468, error inserting after accessing merge attribute on ``CommentedMap`` + (reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__) + - fix for issue 461 pop + insert on same `CommentedMap` key throwing error + (reported by `John Thorvald Wodder II <https://sourceforge.net/u/jwodder/profile/>`__) + +0, 17, 26: 2023-05-09 + - Fix for error on edge cage for issue 459 + +0, 17, 25: 2023-05-09 + - fix for regression while dumping wrapped strings with too many backslashes removed + (issue 459, reported by `Lele Gaifax <https://sourceforge.net/u/lele/profile/>`__) + +0, 17, 24: 2023-05-06 + - rewrite of ``CommentedMap.insert()``. If you have a merge key in + the YAML document for the mapping you insert to, the position value should + be the one as you look at the YAML input. + This fixes issue 453 where other + keys of a merged in mapping would show up after an insert (reported by + `Alex Miller <https://sourceforge.net/u/millerdevel/profile/>`__). It + also fixes a call to `.insert()` resulting into the merge key to move + to be the first key if it wasn't already and it is also now possible + to insert a key before a merge key (even if the fist key in the mapping). + - fix (in the pure Python implementation including default) for issue 447. + (reported by `Jack Cherng <https://sourceforge.net/u/jfcherng/profile/>`__, + also brought up by brent on + `StackOverflow <https://stackoverflow.com/q/40072485/1307905>`__) + +0, 17, 23: 2023-05-05 + - fix 458, error on plain scalars starting with word longer than width. + (reported by `Kyle Larose <https://sourceforge.net/u/klarose/profile/>`__) + - fix for ``.update()`` no longer correctly handling keyword arguments + (reported by John Lin on <StackOverflow + `<https://stackoverflow.com/q/76089100/1307905>`__) + - fix issue 454: high Unicode (emojis) in quoted strings always + escaped (reported by `Michal Čihař <https://sourceforge.net/u/nijel/profile/>`__ + based on a question on StackOverflow). + - fix issue with emitter conservatively inserting extra backslashes in wrapped + quoted strings (reported by thebenman on `StackOverflow + <https://stackoverflow.com/q/75631454/1307905>`__) + +0, 17, 22: 2023-05-02 + + - fix issue 449 where the second exclamation marks got URL encoded (reported + and fixing PR provided by `John Stark <https://sourceforge.net/u/jods/profile/>`__) + - fix issue with indent != 2 and literal scalars with empty first line + (reported by wrdis on `StackOverflow <https://stackoverflow.com/q/75584262/1307905>`__) + - updated __repr__ of CommentedMap, now that Python's dict is ordered -> no more + ordereddict(list-of-tuples) + - merge MR 4, handling OctalInt in YAML 1.1 + (provided by `Jacob Floyd <https://sourceforge.net/u/cognifloyd/profile/>`_) + - fix loading of `!!float 42` (reported by Eric on + `Stack overflow <https://stackoverflow.com/a/71555107/1307905>`_) + - line numbers are now set on `CommentedKeySeq` and `CommentedKeyMap` (which + are created if you have a sequence resp. mapping as the key in a mapping) + - plain scalars: put single words longer than width on a line of their own, instead + of after the previous line (issue 427, reported by `Antoine Cotten + <https://sourceforge.net/u/antoineco/profile/>`_). Caveat: this currently results in a + space ending the previous line. + - fix for folded scalar part of 421: comments after ">" on first line of folded + scalars are now preserved (as were those in the same position on literal scalars). + Issue reported by Jacob Floyd. + - added stacklevel to warnings + - typing changed from Py2 compatible comments to Py3, removed various Py2-isms + 0, 17, 21: 2022-02-12 - fix bug in calling `.compose()` method with `pathlib.Path` instance.
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/LICENSE -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/LICENSE
Changed
@@ -1,6 +1,6 @@ The MIT License (MIT) - Copyright (c) 2014-2022 Anthon van der Neut, Ruamel bvba + Copyright (c) 2014-2023 Anthon van der Neut, Ruamel bvba Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/PKG-INFO -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/PKG-INFO
Changed
@@ -1,13 +1,12 @@ Metadata-Version: 2.1 Name: ruamel.yaml -Version: 0.17.21 +Version: 0.17.32 Summary: ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order Home-page: https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree Author: Anthon van der Neut Author-email: a.van.der.neut@ruamel.eu License: MIT license Keywords: yaml 1.2 parser round-trip preserve quotes order config -Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License @@ -15,8 +14,7 @@ Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.10 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 @@ -36,32 +34,26 @@ ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.17.21 -:updated: 2022-02-12 +:version: 0.17.32 +:updated: 2023-06-17 :documentation: http://yaml.readthedocs.io :repository: https://sourceforge.net/projects/ruamel-yaml/ :pypi: https://pypi.org/project/ruamel.yaml/ -*The 0.16.13 release was the last that was tested to be working on Python 2.7. -The 0.17.21 is the last one tested to be working on Python 3.5, -that is also the last release supporting old PyYAML functions, you'll have to create a -`YAML()` instance and use its `.load()` and `.dump()` methods.* +*Starting with 0.17.22 only Python 3.7+ is supported. +The 0.17 series is also the last to support old PyYAML functions, replace it by +creating a `YAML()` instance and use its `.load()` and `.dump()` methods.* +New(er) functionality is usually only available via the new API. -*Please adjust your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* +The 0.17.21 was the last one tested to be working on Python 3.5 and 3.6 (the +latter was not tested, because +tox/virtualenv stopped supporting that EOL version). +The 0.16.13 release was the last that was tested to be working on Python 2.7. -Starting with version 0.15.0 the way YAML files are loaded and dumped -has been changing, see the API doc for details. Currently existing -functionality will throw a warning before being changed/removed. -**For production systems already using a pre 0.16 version, you should -pin the version being used with ``ruamel.yaml<=0.15``** if you cannot -fully test upgrading to a newer version. For new usage -pin to the minor version tested ( ``ruamel.yaml<=0.17``) or even to the -exact version used. +*Please adjust/pin your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* -New functionality is usually only available via the new API, so -make sure you use it and stop using the `ruamel.yaml.safe_load()`, -`ruamel.yaml.round_trip_load()` and `ruamel.yaml.load()` functions -(and their `....dump()` counterparts). +There are now two extra plug-in packages (`ruamel.yaml.bytes` and `ruamel.yaml.string`) +for those not wanting to do the streaming to a `io.BytesIO/StringIO` buffer themselves. If your package uses ``ruamel.yaml`` and is not listed on PyPI, drop me an email, preferably with some information on how you use the @@ -99,6 +91,96 @@ .. should insert NEXT: at the beginning of line for next key (with empty line) +0.17.32 (2023-06-17): + - fix issue with scanner getting stuck in infinite loop + +0.17.31 (2023-05-31): + - added tag.setter on `ScalarEvent` and on `Node`, that takes either + a `Tag` instance, or a str + (reported by `Sorin Sbarnea <https://sourceforge.net/u/ssbarnea/profile/>`__) + +0.17.30 (2023-05-30): + - fix issue 467, caused by Tag instances not being hashable (reported by + `Douglas Raillard + <https://bitbucket.org/%7Bcf052d92-a278-4339-9aa8-de41923bb556%7D/>`__) + +0.17.29 (2023-05-30): + - changed the internals of the tag property from a string to a class which allows + for preservation of the original handle and suffix. This should + result in better results using documents with %TAG directives, as well + as preserving URI escapes in tag suffixes. + +0.17.28 (2023-05-26): + - fix for issue 464: documents ending with document end marker without final newline + fail to load (reported by `Mariusz Rusiniak <https://sourceforge.net/u/r2dan/profile/>`__) + +0.17.27 (2023-05-25): + - fix issue with inline mappings as value for merge keys + (reported by Sirish on `StackOverflow <https://stackoverflow.com/q/76331049/1307905>`__) + - fix for 468, error inserting after accessing merge attribute on ``CommentedMap`` + (reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__) + - fix for issue 461 pop + insert on same `CommentedMap` key throwing error + (reported by `John Thorvald Wodder II <https://sourceforge.net/u/jwodder/profile/>`__) + +0.17.26 (2023-05-09): + - fix for error on edge cage for issue 459 + +0.17.25 (2023-05-09): + - fix for regression while dumping wrapped strings with too many backslashes removed + (issue 459, reported by `Lele Gaifax <https://sourceforge.net/u/lele/profile/>`__) + +0.17.24 (2023-05-06): + - rewrite of ``CommentedMap.insert()``. If you have a merge key in + the YAML document for the mapping you insert to, the position value should + be the one as you look at the YAML input. + This fixes issue 453 where other + keys of a merged in mapping would show up after an insert (reported by + `Alex Miller <https://sourceforge.net/u/millerdevel/profile/>`__). It + also fixes a call to `.insert()` resulting into the merge key to move + to be the first key if it wasn't already and it is also now possible + to insert a key before a merge key (even if the fist key in the mapping). + - fix (in the pure Python implementation including default) for issue 447. + (reported by `Jack Cherng <https://sourceforge.net/u/jfcherng/profile/>`__, + also brought up by brent on + `StackOverflow <https://stackoverflow.com/q/40072485/1307905>`__) + +0.17.23 (2023-05-05): + - fix 458, error on plain scalars starting with word longer than width. + (reported by `Kyle Larose <https://sourceforge.net/u/klarose/profile/>`__) + - fix for ``.update()`` no longer correctly handling keyword arguments + (reported by John Lin on <StackOverflow + `<https://stackoverflow.com/q/76089100/1307905>`__) + - fix issue 454: high Unicode (emojis) in quoted strings always + escaped (reported by `Michal Čihař <https://sourceforge.net/u/nijel/profile/>`__ + based on a question on StackOverflow). + - fix issue with emitter conservatively inserting extra backslashes in wrapped + quoted strings (reported by thebenman on `StackOverflow + <https://stackoverflow.com/q/75631454/1307905>`__) + +0.17.22 (2023-05-02): + + - fix issue 449 where the second exclamation marks got URL encoded (reported + and fixing PR provided by `John Stark <https://sourceforge.net/u/jods/profile/>`__) + - fix issue with indent != 2 and literal scalars with empty first line + (reported by wrdis on `StackOverflow <https://stackoverflow.com/q/75584262/1307905>`__) + - updated __repr__ of CommentedMap, now that Python's dict is ordered -> no more + ordereddict(list-of-tuples) + - merge MR 4, handling OctalInt in YAML 1.1 + (provided by `Jacob Floyd <https://sourceforge.net/u/cognifloyd/profile/>`_) + - fix loading of `!!float 42` (reported by Eric on + `Stack overflow <https://stackoverflow.com/a/71555107/1307905>`_) + - line numbers are now set on `CommentedKeySeq` and `CommentedKeyMap` (which + are created if you have a sequence resp. mapping as the key in a mapping) + - plain scalars: put single words longer than width on a line of their own, instead + of after the previous line (issue 427, reported by `Antoine Cotten + <https://sourceforge.net/u/antoineco/profile/>`_). Caveat: this currently results in a + space ending the previous line. + - fix for folded scalar part of 421: comments after ">" on first line of folded + scalars are now preserved (as were those in the same position on literal scalars). + Issue reported by Jacob Floyd. + - added stacklevel to warnings + - typing changed from Py2 compatible comments to Py3, removed various Py2-isms + 0.17.21 (2022-02-12): - fix bug in calling `.compose()` method with `pathlib.Path` instance. @@ -137,7 +219,7 @@ attrs with `@attr.s()` (both reported by `ssph <https://sourceforge.net/u/sph/>`__) 0.17.11 (2021-08-19): - - fix error baseclass for ``DuplicateKeyErorr`` (reported by `Łukasz Rogalski + - fix error baseclass for ``DuplicateKeyError`` (reported by `Łukasz Rogalski <https://sourceforge.net/u/lrogalski/>`__) - fix typo in reader error message, causing `KeyError` during reader error (reported by `MTU <https://sourceforge.net/u/mtu/>`__) @@ -288,5 +370,3 @@ For older changes see the file `CHANGES <https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/CHANGES>`_ - -
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/README.rst -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/README.rst
Changed
@@ -4,32 +4,26 @@ ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.17.21 -:updated: 2022-02-12 +:version: 0.17.32 +:updated: 2023-06-17 :documentation: http://yaml.readthedocs.io :repository: https://sourceforge.net/projects/ruamel-yaml/ :pypi: https://pypi.org/project/ruamel.yaml/ -*The 0.16.13 release was the last that was tested to be working on Python 2.7. -The 0.17.21 is the last one tested to be working on Python 3.5, -that is also the last release supporting old PyYAML functions, you'll have to create a -`YAML()` instance and use its `.load()` and `.dump()` methods.* +*Starting with 0.17.22 only Python 3.7+ is supported. +The 0.17 series is also the last to support old PyYAML functions, replace it by +creating a `YAML()` instance and use its `.load()` and `.dump()` methods.* +New(er) functionality is usually only available via the new API. -*Please adjust your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* +The 0.17.21 was the last one tested to be working on Python 3.5 and 3.6 (the +latter was not tested, because +tox/virtualenv stopped supporting that EOL version). +The 0.16.13 release was the last that was tested to be working on Python 2.7. -Starting with version 0.15.0 the way YAML files are loaded and dumped -has been changing, see the API doc for details. Currently existing -functionality will throw a warning before being changed/removed. -**For production systems already using a pre 0.16 version, you should -pin the version being used with ``ruamel.yaml<=0.15``** if you cannot -fully test upgrading to a newer version. For new usage -pin to the minor version tested ( ``ruamel.yaml<=0.17``) or even to the -exact version used. +*Please adjust/pin your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* -New functionality is usually only available via the new API, so -make sure you use it and stop using the `ruamel.yaml.safe_load()`, -`ruamel.yaml.round_trip_load()` and `ruamel.yaml.load()` functions -(and their `....dump()` counterparts). +There are now two extra plug-in packages (`ruamel.yaml.bytes` and `ruamel.yaml.string`) +for those not wanting to do the streaming to a `io.BytesIO/StringIO` buffer themselves. If your package uses ``ruamel.yaml`` and is not listed on PyPI, drop me an email, preferably with some information on how you use the @@ -67,6 +61,96 @@ .. should insert NEXT: at the beginning of line for next key (with empty line) +0.17.32 (2023-06-17): + - fix issue with scanner getting stuck in infinite loop + +0.17.31 (2023-05-31): + - added tag.setter on `ScalarEvent` and on `Node`, that takes either + a `Tag` instance, or a str + (reported by `Sorin Sbarnea <https://sourceforge.net/u/ssbarnea/profile/>`__) + +0.17.30 (2023-05-30): + - fix issue 467, caused by Tag instances not being hashable (reported by + `Douglas Raillard + <https://bitbucket.org/%7Bcf052d92-a278-4339-9aa8-de41923bb556%7D/>`__) + +0.17.29 (2023-05-30): + - changed the internals of the tag property from a string to a class which allows + for preservation of the original handle and suffix. This should + result in better results using documents with %TAG directives, as well + as preserving URI escapes in tag suffixes. + +0.17.28 (2023-05-26): + - fix for issue 464: documents ending with document end marker without final newline + fail to load (reported by `Mariusz Rusiniak <https://sourceforge.net/u/r2dan/profile/>`__) + +0.17.27 (2023-05-25): + - fix issue with inline mappings as value for merge keys + (reported by Sirish on `StackOverflow <https://stackoverflow.com/q/76331049/1307905>`__) + - fix for 468, error inserting after accessing merge attribute on ``CommentedMap`` + (reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__) + - fix for issue 461 pop + insert on same `CommentedMap` key throwing error + (reported by `John Thorvald Wodder II <https://sourceforge.net/u/jwodder/profile/>`__) + +0.17.26 (2023-05-09): + - fix for error on edge cage for issue 459 + +0.17.25 (2023-05-09): + - fix for regression while dumping wrapped strings with too many backslashes removed + (issue 459, reported by `Lele Gaifax <https://sourceforge.net/u/lele/profile/>`__) + +0.17.24 (2023-05-06): + - rewrite of ``CommentedMap.insert()``. If you have a merge key in + the YAML document for the mapping you insert to, the position value should + be the one as you look at the YAML input. + This fixes issue 453 where other + keys of a merged in mapping would show up after an insert (reported by + `Alex Miller <https://sourceforge.net/u/millerdevel/profile/>`__). It + also fixes a call to `.insert()` resulting into the merge key to move + to be the first key if it wasn't already and it is also now possible + to insert a key before a merge key (even if the fist key in the mapping). + - fix (in the pure Python implementation including default) for issue 447. + (reported by `Jack Cherng <https://sourceforge.net/u/jfcherng/profile/>`__, + also brought up by brent on + `StackOverflow <https://stackoverflow.com/q/40072485/1307905>`__) + +0.17.23 (2023-05-05): + - fix 458, error on plain scalars starting with word longer than width. + (reported by `Kyle Larose <https://sourceforge.net/u/klarose/profile/>`__) + - fix for ``.update()`` no longer correctly handling keyword arguments + (reported by John Lin on <StackOverflow + `<https://stackoverflow.com/q/76089100/1307905>`__) + - fix issue 454: high Unicode (emojis) in quoted strings always + escaped (reported by `Michal Čihař <https://sourceforge.net/u/nijel/profile/>`__ + based on a question on StackOverflow). + - fix issue with emitter conservatively inserting extra backslashes in wrapped + quoted strings (reported by thebenman on `StackOverflow + <https://stackoverflow.com/q/75631454/1307905>`__) + +0.17.22 (2023-05-02): + + - fix issue 449 where the second exclamation marks got URL encoded (reported + and fixing PR provided by `John Stark <https://sourceforge.net/u/jods/profile/>`__) + - fix issue with indent != 2 and literal scalars with empty first line + (reported by wrdis on `StackOverflow <https://stackoverflow.com/q/75584262/1307905>`__) + - updated __repr__ of CommentedMap, now that Python's dict is ordered -> no more + ordereddict(list-of-tuples) + - merge MR 4, handling OctalInt in YAML 1.1 + (provided by `Jacob Floyd <https://sourceforge.net/u/cognifloyd/profile/>`_) + - fix loading of `!!float 42` (reported by Eric on + `Stack overflow <https://stackoverflow.com/a/71555107/1307905>`_) + - line numbers are now set on `CommentedKeySeq` and `CommentedKeyMap` (which + are created if you have a sequence resp. mapping as the key in a mapping) + - plain scalars: put single words longer than width on a line of their own, instead + of after the previous line (issue 427, reported by `Antoine Cotten + <https://sourceforge.net/u/antoineco/profile/>`_). Caveat: this currently results in a + space ending the previous line. + - fix for folded scalar part of 421: comments after ">" on first line of folded + scalars are now preserved (as were those in the same position on literal scalars). + Issue reported by Jacob Floyd. + - added stacklevel to warnings + - typing changed from Py2 compatible comments to Py3, removed various Py2-isms + 0.17.21 (2022-02-12): - fix bug in calling `.compose()` method with `pathlib.Path` instance. @@ -105,7 +189,7 @@ attrs with `@attr.s()` (both reported by `ssph <https://sourceforge.net/u/sph/>`__) 0.17.11 (2021-08-19): - - fix error baseclass for ``DuplicateKeyErorr`` (reported by `Łukasz Rogalski + - fix error baseclass for ``DuplicateKeyError`` (reported by `Łukasz Rogalski <https://sourceforge.net/u/lrogalski/>`__) - fix typo in reader error message, causing `KeyError` during reader error (reported by `MTU <https://sourceforge.net/u/mtu/>`__)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/__init__.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/__init__.py
Changed
@@ -5,27 +5,26 @@ _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 17, 21), - __version__='0.17.21', - version_timestamp='2022-02-12 09:49:22', + version_info=(0, 17, 32), + __version__='0.17.32', + version_timestamp='2023-06-17 07:55:58', 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 entry_points=None, since=2014, extras_require={ - ':platform_python_implementation=="CPython" and python_version<"3.11"': 'ruamel.yaml.clib>=0.2.6', # NOQA + ':platform_python_implementation=="CPython" and python_version<"3.12"': 'ruamel.yaml.clib>=0.2.7', # NOQA 'jinja2': 'ruamel.yaml.jinja2>=0.2', 'docs': 'ryd', }, classifiers= 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: Implementation :: CPython', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Text Processing :: Markup', @@ -33,10 +32,10 @@ , keywords='yaml 1.2 parser round-trip preserve quotes order config', read_the_docs='yaml', - supported=(3, 5), # minimum + supported=(3, 7), # minimum tox=dict( - env='*f', # f for 3.5 - fl8excl='_test/lib', + env='*', + fl8excl='_test/lib,branch_default', ), # universal=True, python_requires='>=3',
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/anchor.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/anchor.py
Changed
@@ -1,6 +1,6 @@ # coding: utf-8 -if False: # MYPY - from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA + +from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA anchor_attrib = '_yaml_anchor' @@ -9,12 +9,10 @@ __slots__ = 'value', 'always_dump' attrib = anchor_attrib - def __init__(self): - # type: () -> None + def __init__(self) -> None: self.value = None self.always_dump = False - def __repr__(self): - # type: () -> Any + def __repr__(self) -> Any: ad = ', (always dump)' if self.always_dump else "" - return 'Anchor({!r}{})'.format(self.value, ad) + return f'Anchor({self.value!r}{ad})'
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/comments.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/comments.py
Changed
@@ -11,14 +11,14 @@ from ruamel.yaml.compat import ordereddict -from ruamel.yaml.compat import MutableSliceableSequence, _F, nprintf # NOQA +from ruamel.yaml.compat import MutableSliceableSequence, nprintf # NOQA from ruamel.yaml.scalarstring import ScalarString from ruamel.yaml.anchor import Anchor +from ruamel.yaml.tag import Tag from collections.abc import MutableSet, Sized, Set, Mapping -if False: # MYPY - from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA +from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA # fmt: off __all__ = 'CommentedSeq', 'CommentedKeySeq', @@ -46,18 +46,15 @@ class IDX: # temporary auto increment, so rearranging is easier - def __init__(self): - # type: () -> None + def __init__(self) -> None: self._idx = 0 - def __call__(self): - # type: () -> Any + def __call__(self) -> Any: x = self._idx self._idx += 1 return x - def __str__(self): - # type: () -> Any + def __str__(self) -> Any: return str(self._idx) @@ -83,7 +80,6 @@ format_attrib = '_yaml_format' line_col_attrib = '_yaml_line_col' merge_attrib = '_yaml_merge' -tag_attrib = '_yaml_tag' class Comment: @@ -92,27 +88,24 @@ __slots__ = 'comment', '_items', '_post', '_pre' attrib = comment_attrib - def __init__(self, old=True): - # type: (bool) -> None + def __init__(self, old: bool = True) -> None: self._pre = None if old else # type: ignore self.comment = None # post, pre # map key (mapping/omap/dict) or index (sequence/list) to a list of # dict: post_key, pre_key, post_value, pre_value # list: pre item, post item - self._items = {} # type: DictAny, Any + self._items: DictAny, Any = {} # self._start = # should not put these on first item - self._post = # type: ListAny # end of document comments + self._post: ListAny = # end of document comments - def __str__(self): - # type: () -> str + def __str__(self) -> str: if bool(self._post): end = ',\n end=' + str(self._post) else: end = "" - return 'Comment(comment={0},\n items={1}{2})'.format(self.comment, self._items, end) + return f'Comment(comment={self.comment},\n items={self._items}{end})' - def _old__repr__(self): - # type: () -> str + def _old__repr__(self) -> str: if bool(self._post): end = ',\n end=' + str(self._post) else: @@ -121,15 +114,12 @@ ln = max(len(str(k)) for k in self._items) + 1 except ValueError: ln = '' # type: ignore - it = ' '.join( - '{:{}} {}\n'.format(str(k) + ':', ln, v) for k, v in self._items.items() - ) + it = ' '.join(f'{str(k) + ":":{ln}} {v}\n' for k, v in self._items.items()) if it: it = '\n ' + it + ' ' - return 'Comment(\n start={},\n items={{{}}}{})'.format(self.comment, it, end) + return f'Comment(\n start={self.comment},\n items={{{it}}}{end})' - def __repr__(self): - # type: () -> str + def __repr__(self) -> str: if self._pre is None: return self._old__repr__() if bool(self._post): @@ -140,47 +130,38 @@ ln = max(len(str(k)) for k in self._items) + 1 except ValueError: ln = '' # type: ignore - it = ' '.join( - '{:{}} {}\n'.format(str(k) + ':', ln, v) for k, v in self._items.items() - ) + it = ' '.join(f'{str(k) + ":":{ln}} {v}\n' for k, v in self._items.items()) if it: it = '\n ' + it + ' ' - return 'Comment(\n pre={},\n items={{{}}}{})'.format(self.pre, it, end) + return f'Comment(\n pre={self.pre},\n items={{{it}}}{end})' @property - def items(self): - # type: () -> Any + def items(self) -> Any: return self._items @property - def end(self): - # type: () -> Any + def end(self) -> Any: return self._post @end.setter - def end(self, value): - # type: (Any) -> None + def end(self, value: Any) -> None: self._post = value @property - def pre(self): - # type: () -> Any + def pre(self) -> Any: return self._pre @pre.setter - def pre(self, value): - # type: (Any) -> None + def pre(self, value: Any) -> None: self._pre = value - def get(self, item, pos): - # type: (Any, Any) -> Any + def get(self, item: Any, pos: Any) -> Any: x = self._items.get(item) if x is None or len(x) < pos: return None return xpos # can be None - def set(self, item, pos, value): - # type: (Any, Any, Any) -> Any + def set(self, item: Any, pos: Any, value: Any) -> Any: x = self._items.get(item) if x is None: self._itemsitem = x = None * (pos + 1) @@ -190,8 +171,7 @@ assert xpos is None xpos = value - def __contains__(self, x): - # type: (Any) -> Any + def __contains__(self, x: Any) -> Any: # test if a substring is in any of the attached comments if self.comment: if self.comment0 and x in self.comment0.value: @@ -214,29 +194,24 @@ # to distinguish key from None -def NoComment(): - # type: () -> None - pass +class NotNone: + pass # NOQA class Format: __slots__ = ('_flow_style',) attrib = format_attrib - def __init__(self): - # type: () -> None - self._flow_style = None # type: Any + def __init__(self) -> None: + self._flow_style: Any = None - def set_flow_style(self): - # type: () -> None + def set_flow_style(self) -> None: self._flow_style = True - def set_block_style(self): - # type: () -> None + def set_block_style(self) -> None: self._flow_style = False - def flow_style(self, default=None):
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/compat.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/compat.py
Changed
@@ -11,11 +11,15 @@ # fmt: off -if False: # MYPY - from typing import Any, Dict, Optional, List, Union, BinaryIO, IO, Text, Tuple # NOQA - from typing import Optional # NOQA +from typing import Any, Dict, Optional, List, Union, BinaryIO, IO, Text, Tuple # NOQA +from typing import Optional # NOQA +try: + from typing import SupportsIndex as SupportsIndex # in order to reexport for mypy +except ImportError: + SupportsIndex = int # type: ignore # fmt: on + _DEFAULT_YAML_VERSION = (1, 2) try: @@ -29,8 +33,7 @@ class ordereddict(OrderedDict): # type: ignore if not hasattr(OrderedDict, 'insert'): - def insert(self, pos, key, value): - # type: (int, Any, Any) -> None + def insert(self, pos: int, key: Any, value: Any) -> None: if pos >= len(self): selfkey = value return @@ -47,34 +50,20 @@ PY2 = sys.version_info0 == 2 PY3 = sys.version_info0 == 3 - -# replace with f-strings when 3.5 support is dropped -# ft = '42' -# assert _F('abc {ft!r}', ft=ft) == 'abc %r' % ft -# 'abc %r' % ft -> _F('abc {ft!r}' -> f'abc {ft!r}' -def _F(s, *superfluous, **kw): - # type: (Any, Any, Any) -> Any - if superfluous: - raise TypeError - return s.format(**kw) - - StringIO = io.StringIO BytesIO = io.BytesIO -if False: # MYPY - # StreamType = UnionBinaryIO, IOstr, IOunicode, StringIO - # StreamType = UnionBinaryIO, IOstr, StringIO # type: ignore - StreamType = Any +# StreamType = UnionBinaryIO, IOstr, IOunicode, StringIO +# StreamType = UnionBinaryIO, IOstr, StringIO # type: ignore +StreamType = Any - StreamTextType = StreamType # UnionText, StreamType - VersionType = UnionListint, str, Tupleint, int +StreamTextType = StreamType # UnionText, StreamType +VersionType = UnionListint, str, Tupleint, int builtins_module = 'builtins' -def with_metaclass(meta, *bases): - # type: (Any, Any) -> Any +def with_metaclass(meta: Any, *bases: Any) -> Any: """Create a base class with a metaclass.""" return meta('NewBase', bases, {}) @@ -84,7 +73,7 @@ DBG_NODE = 4 -_debug = None # type: Optionalint +_debug: Optionalint = None if 'RUAMELDEBUG' in os.environ: _debugx = os.environ.get('RUAMELDEBUG') if _debugx is None: @@ -96,25 +85,21 @@ if bool(_debug): class ObjectCounter: - def __init__(self): - # type: () -> None - self.map = {} # type: DictAny, Any + def __init__(self) -> None: + self.map: DictAny, Any = {} - def __call__(self, k): - # type: (Any) -> None + def __call__(self, k: Any) -> None: self.mapk = self.map.get(k, 0) + 1 - def dump(self): - # type: () -> None + def dump(self) -> None: for k in sorted(self.map): - sys.stdout.write('{} -> {}'.format(k, self.mapk)) + sys.stdout.write(f'{k} -> {self.mapk}') object_counter = ObjectCounter() # used from yaml util when testing -def dbg(val=None): - # type: (Any) -> Any +def dbg(val: Any = None) -> Any: global _debug if _debug is None: # set to true or false @@ -129,14 +114,12 @@ class Nprint: - def __init__(self, file_name=None): - # type: (Any) -> None - self._max_print = None # type: Any - self._count = None # type: Any + def __init__(self, file_name: Any = None) -> None: + self._max_print: Any = None + self._count: Any = None self._file_name = file_name - def __call__(self, *args, **kw): - # type: (Any, Any) -> None + def __call__(self, *args: Any, **kw: Any) -> None: if not bool(_debug): return out = sys.stdout if self._file_name is None else open(self._file_name, 'a') @@ -157,13 +140,11 @@ if self._file_name: out.close() - def set_max_print(self, i): - # type: (int) -> None + def set_max_print(self, i: int) -> None: self._max_print = i self._count = None - def fp(self, mode='a'): - # type: (str) -> Any + def fp(self, mode: str = 'a') -> Any: out = sys.stdout if self._file_name is None else open(self._file_name, mode) return out @@ -174,8 +155,7 @@ # char checkers following production rules -def check_namespace_char(ch): - # type: (Any) -> bool +def check_namespace_char(ch: Any) -> bool: if '\x21' <= ch <= '\x7E': # ! to ~ return True if '\xA0' <= ch <= '\uD7FF': @@ -187,15 +167,13 @@ return False -def check_anchorname_char(ch): - # type: (Any) -> bool +def check_anchorname_char(ch: Any) -> bool: if ch in ',{}': return False return check_namespace_char(ch) -def version_tnf(t1, t2=None): - # type: (Any, Any) -> Any +def version_tnf(t1: Any, t2: Any = None) -> Any: """ return True if ruamel.yaml version_info < t1, None if t2 is specified and bigger else False """ @@ -211,14 +189,12 @@ class MutableSliceableSequence(collections.abc.MutableSequence): # type: ignore __slots__ = () - def __getitem__(self, index): - # type: (Any) -> Any + def __getitem__(self, index: Any) -> Any: if not isinstance(index, slice): return self.__getsingleitem__(index) return type(self)(selfi for i in range(*index.indices(len(self)))) # type: ignore - def __setitem__(self, index, value): - # type: (Any, Any) -> None + def __setitem__(self, index: Any, value: Any) -> None: if not isinstance(index, slice): return self.__setsingleitem__(index, value) assert iter(value) @@ -233,19 +209,16 @@ # need to test before changing, in case TypeError is caught if nr_assigned_items < len(value): raise TypeError( - 'too many elements in value {} < {}'.format(nr_assigned_items, len(value)) + f'too many elements in value {nr_assigned_items} < {len(value)}' ) elif nr_assigned_items > len(value): raise TypeError(
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/composer.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/composer.py
Changed
@@ -3,7 +3,7 @@ import warnings from ruamel.yaml.error import MarkedYAMLError, ReusedAnchorWarning -from ruamel.yaml.compat import _F, nprint, nprintf # NOQA +from ruamel.yaml.compat import nprint, nprintf # NOQA from ruamel.yaml.events import ( StreamStartEvent, @@ -17,8 +17,7 @@ ) from ruamel.yaml.nodes import MappingNode, ScalarNode, SequenceNode -if False: # MYPY - from typing import Any, Dict, Optional, List # NOQA +from typing import Any, Dict, Optional, List # NOQA __all__ = 'Composer', 'ComposerError' @@ -28,30 +27,27 @@ class Composer: - def __init__(self, loader=None): - # type: (Any) -> None + def __init__(self, loader: Any = None) -> None: self.loader = loader if self.loader is not None and getattr(self.loader, '_composer', None) is None: self.loader._composer = self - self.anchors = {} # type: DictAny, Any + self.anchors: DictAny, Any = {} + self.warn_double_anchors = True @property - def parser(self): - # type: () -> Any + def parser(self) -> Any: if hasattr(self.loader, 'typ'): self.loader.parser return self.loader._parser @property - def resolver(self): - # type: () -> Any + def resolver(self) -> Any: # assert self.loader._resolver is not None if hasattr(self.loader, 'typ'): self.loader.resolver return self.loader._resolver - def check_node(self): - # type: () -> Any + def check_node(self) -> Any: # Drop the STREAM-START event. if self.parser.check_event(StreamStartEvent): self.parser.get_event() @@ -59,19 +55,17 @@ # If there are more documents available? return not self.parser.check_event(StreamEndEvent) - def get_node(self): - # type: () -> Any + def get_node(self) -> Any: # Get the root node of the next document. if not self.parser.check_event(StreamEndEvent): return self.compose_document() - def get_single_node(self): - # type: () -> Any + def get_single_node(self) -> Any: # Drop the STREAM-START event. self.parser.get_event() # Compose a document if the stream is not empty. - document = None # type: Any + document: Any = None if not self.parser.check_event(StreamEndEvent): document = self.compose_document() @@ -90,8 +84,7 @@ return document - def compose_document(self): - # type: (Any) -> Any + def compose_document(self: Any) -> Any: # Drop the DOCUMENT-START event. self.parser.get_event() @@ -104,36 +97,28 @@ self.anchors = {} return node - def return_alias(self, a): - # type: (Any) -> Any + def return_alias(self, a: Any) -> Any: return a - def compose_node(self, parent, index): - # type: (Any, Any) -> Any + def compose_node(self, parent: Any, index: Any) -> Any: if self.parser.check_event(AliasEvent): event = self.parser.get_event() alias = event.anchor if alias not in self.anchors: raise ComposerError( - None, - None, - _F('found undefined alias {alias!r}', alias=alias), - event.start_mark, + None, None, f'found undefined alias {alias!r}', event.start_mark, ) return self.return_alias(self.anchorsalias) event = self.parser.peek_event() anchor = event.anchor if anchor is not None: # have an anchor - if anchor in self.anchors: - # raise ComposerError( - # "found duplicate anchor %r; first occurrence" - # % (anchor), self.anchorsanchor.start_mark, - # "second occurrence", event.start_mark) + if self.warn_double_anchors and anchor in self.anchors: ws = ( - '\nfound duplicate anchor {!r}\nfirst occurrence {}\nsecond occurrence ' - '{}'.format((anchor), self.anchorsanchor.start_mark, event.start_mark) + f'\nfound duplicate anchor {anchor!r}\n' + f'first occurrence {self.anchorsanchor.start_mark}\n' + f'second occurrence {event.start_mark}' ) - warnings.warn(ws, ReusedAnchorWarning) + warnings.warn(ws, ReusedAnchorWarning, stacklevel=2) self.resolver.descend_resolver(parent, index) if self.parser.check_event(ScalarEvent): node = self.compose_scalar_node(anchor) @@ -144,12 +129,13 @@ self.resolver.ascend_resolver() return node - def compose_scalar_node(self, anchor): - # type: (Any) -> Any + def compose_scalar_node(self, anchor: Any) -> Any: event = self.parser.get_event() - tag = event.tag - if tag is None or tag == '!': + tag = event.ctag + if tag is None or str(tag) == '!': tag = self.resolver.resolve(ScalarNode, event.value, event.implicit) + assert not isinstance(tag, str) + # e.g tag.yaml.org,2002:str node = ScalarNode( tag, event.value, @@ -163,12 +149,12 @@ self.anchorsanchor = node return node - def compose_sequence_node(self, anchor): - # type: (Any) -> Any + def compose_sequence_node(self, anchor: Any) -> Any: start_event = self.parser.get_event() - tag = start_event.tag - if tag is None or tag == '!': + tag = start_event.ctag + if tag is None or str(tag) == '!': tag = self.resolver.resolve(SequenceNode, None, start_event.implicit) + assert not isinstance(tag, str) node = SequenceNode( tag, , @@ -187,21 +173,21 @@ end_event = self.parser.get_event() if node.flow_style is True and end_event.comment is not None: if node.comment is not None: + x = node.flow_style nprint( - 'Warning: unexpected end_event commment in sequence ' - 'node {}'.format(node.flow_style) + f'Warning: unexpected end_event commment in sequence node {x}' ) node.comment = end_event.comment node.end_mark = end_event.end_mark self.check_end_doc_comment(end_event, node) return node - def compose_mapping_node(self, anchor): - # type: (Any) -> Any + def compose_mapping_node(self, anchor: Any) -> Any: start_event = self.parser.get_event() - tag = start_event.tag - if tag is None or tag == '!': + tag = start_event.ctag + if tag is None or str(tag) == '!': tag = self.resolver.resolve(MappingNode, None, start_event.implicit) + assert not isinstance(tag, str) node = MappingNode( tag, , @@ -230,8 +216,7 @@ self.check_end_doc_comment(end_event, node) return node
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/configobjwalker.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/configobjwalker.py
Changed
@@ -4,11 +4,12 @@ from ruamel.yaml.util import configobj_walker as new_configobj_walker -if False: # MYPY - from typing import Any # NOQA +from typing import Any -def configobj_walker(cfg): - # type: (Any) -> Any - warnings.warn('configobj_walker has moved to ruamel.yaml.util, please update your code') +def configobj_walker(cfg: Any) -> Any: + warnings.warn( + 'configobj_walker has moved to ruamel.yaml.util, please update your code', + stacklevel=2 + ) return new_configobj_walker(cfg)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/constructor.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/constructor.py
Changed
@@ -13,7 +13,7 @@ MantissaNoDotYAML1_1Warning) from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.nodes import (SequenceNode, MappingNode, ScalarNode) -from ruamel.yaml.compat import (_F, builtins_module, # NOQA +from ruamel.yaml.compat import (builtins_module, # NOQA nprint, nprintf, version_tnf) from ruamel.yaml.compat import ordereddict @@ -33,8 +33,7 @@ from ruamel.yaml.timestamp import TimeStamp from ruamel.yaml.util import timestamp_regexp, create_timestamp -if False: # MYPY - from typing import Any, Dict, List, Set, Generator, Union, Optional # NOQA +from typing import Any, Dict, List, Set, Iterator, Union, Optional # NOQA __all__ = 'BaseConstructor', 'SafeConstructor', 'Constructor', @@ -59,70 +58,62 @@ yaml_constructors = {} # type: DictAny, Any yaml_multi_constructors = {} # type: DictAny, Any - def __init__(self, preserve_quotes=None, loader=None): - # type: (Optionalbool, Any) -> None + def __init__(self, preserve_quotes: Optionalbool = None, loader: Any = None) -> None: self.loader = loader if self.loader is not None and getattr(self.loader, '_constructor', None) is None: self.loader._constructor = self self.loader = loader self.yaml_base_dict_type = dict self.yaml_base_list_type = list - self.constructed_objects = {} # type: DictAny, Any - self.recursive_objects = {} # type: DictAny, Any - self.state_generators = # type: ListAny + self.constructed_objects: DictAny, Any = {} + self.recursive_objects: DictAny, Any = {} + self.state_generators: ListAny = self.deep_construct = False self._preserve_quotes = preserve_quotes self.allow_duplicate_keys = version_tnf((0, 15, 1), (0, 16)) @property - def composer(self): - # type: () -> Any + def composer(self) -> Any: if hasattr(self.loader, 'typ'): return self.loader.composer try: return self.loader._composer except AttributeError: - sys.stdout.write('slt {}\n'.format(type(self))) - sys.stdout.write('slc {}\n'.format(self.loader._composer)) - sys.stdout.write('{}\n'.format(dir(self))) + sys.stdout.write(f'slt {type(self)}\n') + sys.stdout.write(f'slc {self.loader._composer}\n') + sys.stdout.write(f'{dir(self)}\n') raise @property - def resolver(self): - # type: () -> Any + def resolver(self) -> Any: if hasattr(self.loader, 'typ'): return self.loader.resolver return self.loader._resolver @property - def scanner(self): - # type: () -> Any + def scanner(self) -> Any: # needed to get to the expanded comments if hasattr(self.loader, 'typ'): return self.loader.scanner return self.loader._scanner - def check_data(self): - # type: () -> Any + def check_data(self) -> Any: # If there are more documents available? return self.composer.check_node() - def get_data(self): - # type: () -> Any + def get_data(self) -> Any: # Construct and return the next document. if self.composer.check_node(): return self.construct_document(self.composer.get_node()) - def get_single_data(self): - # type: () -> Any + def get_single_data(self) -> Any: # Ensure that the stream contains a single document and construct it. node = self.composer.get_single_node() if node is not None: return self.construct_document(node) return None - def construct_document(self, node): - # type: (Any) -> Any + def construct_document(self, node: Any) -> Any: data = self.construct_object(node) while bool(self.state_generators): state_generators = self.state_generators @@ -135,8 +126,7 @@ self.deep_construct = False return data - def construct_object(self, node, deep=False): - # type: (Any, bool) -> Any + def construct_object(self, node: Any, deep: bool = False) -> Any: """deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction """ @@ -159,9 +149,8 @@ self.deep_construct = old_deep return data - def construct_non_recursive_object(self, node, tag=None): - # type: (Any, Optionalstr) -> Any - constructor = None # type: Any + def construct_non_recursive_object(self, node: Any, tag: Optionalstr = None) -> Any: + constructor: Any = None tag_suffix = None if tag is None: tag = node.tag @@ -199,19 +188,14 @@ self.state_generators.append(generator) return data - def construct_scalar(self, node): - # type: (Any) -> Any + def construct_scalar(self, node: Any) -> Any: if not isinstance(node, ScalarNode): raise ConstructorError( - None, - None, - _F('expected a scalar node, but found {node_id!s}', node_id=node.id), - node.start_mark, + None, None, f'expected a scalar node, but found {node.id!s}', node.start_mark, ) return node.value - def construct_sequence(self, node, deep=False): - # type: (Any, bool) -> Any + def construct_sequence(self, node: Any, deep: bool = False) -> Any: """deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction """ @@ -219,22 +203,18 @@ raise ConstructorError( None, None, - _F('expected a sequence node, but found {node_id!s}', node_id=node.id), + f'expected a sequence node, but found {node.id!s}', node.start_mark, ) return self.construct_object(child, deep=deep) for child in node.value - def construct_mapping(self, node, deep=False): - # type: (Any, bool) -> Any + def construct_mapping(self, node: Any, deep: bool = False) -> Any: """deep is True when creating an object/mapping recursively, in that case want the underlying elements available during construction """ if not isinstance(node, MappingNode): raise ConstructorError( - None, - None, - _F('expected a mapping node, but found {node_id!s}', node_id=node.id), - node.start_mark, + None, None, f'expected a mapping node, but found {node.id!s}', node.start_mark, ) total_mapping = self.yaml_base_dict_type() if getattr(node, 'merge', None) is not None: @@ -242,7 +222,7 @@ else: todo = (node.value, True) for values, check in todo: - mapping = self.yaml_base_dict_type() # type: DictAny, Any + mapping: DictAny, Any = self.yaml_base_dict_type() for key_node, value_node in values: # keys can be list -> deep key = self.construct_object(key_node, deep=True) @@ -267,8 +247,9 @@ total_mapping.update(mapping) return total_mapping - def check_mapping_key(self, node, key_node, mapping, key, value): - # type: (Any, Any, Any, Any, Any) -> bool + def check_mapping_key( + self, node: Any, key_node: Any, mapping: Any, key: Any, value: Any + ) -> bool: """return True if key is unique""" if key in mapping: if not self.allow_duplicate_keys: @@ -276,8 +257,8 @@ args = 'while constructing a mapping', node.start_mark,
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/cyaml.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/cyaml.py
Changed
@@ -6,9 +6,9 @@ from ruamel.yaml.representer import Representer, SafeRepresenter, BaseRepresenter from ruamel.yaml.resolver import Resolver, BaseResolver -if False: # MYPY - from typing import Any, Union, Optional # NOQA - from ruamel.yaml.compat import StreamTextType, StreamType, VersionType # NOQA + +from typing import Any, Union, Optional # NOQA +from ruamel.yaml.compat import StreamTextType, StreamType, VersionType # NOQA __all__ = 'CBaseLoader', 'CSafeLoader', 'CLoader', 'CBaseDumper', 'CSafeDumper', 'CDumper' @@ -18,8 +18,12 @@ class CBaseLoader(CParser, BaseConstructor, BaseResolver): # type: ignore - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: CParser.__init__(self, stream) self._parser = self._composer = self BaseConstructor.__init__(self, loader=self) @@ -30,8 +34,12 @@ class CSafeLoader(CParser, SafeConstructor, Resolver): # type: ignore - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: CParser.__init__(self, stream) self._parser = self._composer = self SafeConstructor.__init__(self, loader=self) @@ -42,8 +50,12 @@ class CLoader(CParser, Constructor, Resolver): # type: ignore - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: CParser.__init__(self, stream) self._parser = self._composer = self Constructor.__init__(self, loader=self) @@ -55,25 +67,25 @@ class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver): # type: ignore def __init__( - self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + self: StreamType, + stream: Any, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA CEmitter.__init__( self, stream, @@ -100,25 +112,25 @@ class CSafeDumper(CEmitter, SafeRepresenter, Resolver): # type: ignore def __init__( - self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + self: StreamType, + stream: Any, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA self._emitter = self._serializer = self._representer = self CEmitter.__init__( self, @@ -143,25 +155,25 @@ class CDumper(CEmitter, Representer, Resolver): # type: ignore def __init__( - self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + self: StreamType, + stream: Any, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA CEmitter.__init__( self, stream,
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/dumper.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/dumper.py
Changed
@@ -10,34 +10,33 @@ ) from ruamel.yaml.resolver import Resolver, BaseResolver, VersionedResolver -if False: # MYPY - from typing import Any, Dict, List, Union, Optional # NOQA - from ruamel.yaml.compat import StreamType, VersionType # NOQA +from typing import Any, Dict, List, Union, Optional # NOQA +from ruamel.yaml.compat import StreamType, VersionType # NOQA __all__ = 'BaseDumper', 'SafeDumper', 'Dumper', 'RoundTripDumper' class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): def __init__( - self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (Any, StreamType, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + self: Any, + stream: StreamType, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA Emitter.__init__( self, stream, @@ -70,24 +69,24 @@ class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver): def __init__( self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + stream: StreamType, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA Emitter.__init__( self, stream, @@ -120,24 +119,24 @@ class Dumper(Emitter, Serializer, Representer, Resolver): def __init__( self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Any, Optionalbool, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + stream: StreamType, + default_style: Any = None, + default_flow_style: Any = None, + canonical: Optionalbool = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA Emitter.__init__( self, stream, @@ -170,24 +169,24 @@ class RoundTripDumper(Emitter, Serializer, RoundTripRepresenter, VersionedResolver): def __init__( self, - stream, - default_style=None, - default_flow_style=None, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - ): - # type: (StreamType, Any, Optionalbool, Optionalint, Optionalint, Optionalint, Optionalbool, Any, Any, Optionalbool, Optionalbool, Any, Any, Any, Any, Any) -> None # NOQA + stream: StreamType, + default_style: Any = None, + default_flow_style: Optionalbool = None, + canonical: Optionalint = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: Any = None, + tags: Any = None, + block_seq_indent: Any = None, + top_level_colon_align: Any = None, + prefix_colon: Any = None, + ) -> None: + # NOQA Emitter.__init__( self, stream,
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/emitter.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/emitter.py
Changed
@@ -12,13 +12,13 @@ from ruamel.yaml.events import * # NOQA # fmt: off -from ruamel.yaml.compat import _F, nprint, dbg, DBG_EVENT, \ +from ruamel.yaml.compat import nprint, dbg, DBG_EVENT, \ check_anchorname_char, nprintf # NOQA # fmt: on -if False: # MYPY - from typing import Any, Dict, List, Union, Text, Tuple, Optional # NOQA - from ruamel.yaml.compat import StreamType # NOQA + +from typing import Any, Dict, List, Union, Text, Tuple, Optional # NOQA +from ruamel.yaml.compat import StreamType # NOQA __all__ = 'Emitter', 'EmitterError' @@ -30,16 +30,15 @@ class ScalarAnalysis: def __init__( self, - scalar, - empty, - multiline, - allow_flow_plain, - allow_block_plain, - allow_single_quoted, - allow_double_quoted, - allow_block, - ): - # type: (Any, Any, Any, bool, bool, bool, bool, bool) -> None + scalar: Any, + empty: Any, + multiline: Any, + allow_flow_plain: bool, + allow_block_plain: bool, + allow_single_quoted: bool, + allow_double_quoted: bool, + allow_block: bool, + ) -> None: self.scalar = scalar self.empty = empty self.multiline = multiline @@ -52,20 +51,16 @@ class Indents: # replacement for the list based stack of None/int - def __init__(self): - # type: () -> None - self.values = # type: ListTupleAny, bool + def __init__(self) -> None: + self.values: ListTupleAny, bool = - def append(self, val, seq): - # type: (Any, Any) -> None + def append(self, val: Any, seq: Any) -> None: self.values.append((val, seq)) - def pop(self): - # type: () -> Any + def pop(self) -> Any: return self.values.pop()0 - def last_seq(self): - # type: () -> bool + def last_seq(self) -> bool: # return the seq(uence) value for the element added before the last one # in increase_indent() try: @@ -73,8 +68,9 @@ except IndexError: return False - def seq_flow_align(self, seq_indent, column, pre_comment=False): - # type: (int, int, Optionalbool) -> int + def seq_flow_align( + self, seq_indent: int, column: int, pre_comment: Optionalbool = False + ) -> int: # extra spaces because of dash # nprint('seq_flow_align', self.values, pre_comment) if len(self.values) < 2 or not self.values-11: @@ -87,8 +83,7 @@ # -1 for the dash return base + seq_indent - column - 1 # type: ignore - def __len__(self): - # type: () -> int + def __len__(self) -> int: return len(self.values) @@ -97,6 +92,7 @@ DEFAULT_TAG_PREFIXES = { '!': '!', 'tag:yaml.org,2002:': '!!', + '!!': '!!', } # fmt: on @@ -104,44 +100,44 @@ def __init__( self, - stream, - canonical=None, - indent=None, - width=None, - allow_unicode=None, - line_break=None, - block_seq_indent=None, - top_level_colon_align=None, - prefix_colon=None, - brace_single_entry_mapping_in_flow_sequence=None, - dumper=None, - ): - # type: (StreamType, Any, Optionalint, Optionalint, Optionalbool, Any, Optionalint, Optionalbool, Any, Optionalbool, Any) -> None # NOQA + stream: StreamType, + canonical: Any = None, + indent: Optionalint = None, + width: Optionalint = None, + allow_unicode: Optionalbool = None, + line_break: Any = None, + block_seq_indent: Optionalint = None, + top_level_colon_align: Optionalbool = None, + prefix_colon: Any = None, + brace_single_entry_mapping_in_flow_sequence: Optionalbool = None, + dumper: Any = None, + ) -> None: + # NOQA self.dumper = dumper if self.dumper is not None and getattr(self.dumper, '_emitter', None) is None: self.dumper._emitter = self self.stream = stream # Encoding can be overriden by STREAM-START. - self.encoding = None # type: OptionalText + self.encoding: OptionalText = None self.allow_space_break = None # Emitter is a state machine with a stack of states to handle nested # structures. - self.states = # type: ListAny - self.state = self.expect_stream_start # type: Any + self.states: ListAny = + self.state: Any = self.expect_stream_start # Current event and the event queue. - self.events = # type: ListAny - self.event = None # type: Any + self.events: ListAny = + self.event: Any = None # The current indentation level and the stack of previous indents. self.indents = Indents() - self.indent = None # type: Optionalint + self.indent: Optionalint = None # flow_context is an expanding/shrinking list consisting of '{' and '' # for each unclosed flow context. If empty list that means block context - self.flow_context = # type: ListText + self.flow_context: ListText = # Contexts. self.root_context = False @@ -161,7 +157,7 @@ self.compact_seq_seq = True # dash after dash self.compact_seq_map = True # key after dash # self.compact_ms = False # dash after key, only when excplicit key with ? - self.no_newline = None # type: Optionalbool # set if directly after `- ` + self.no_newline: Optionalbool = None # set if directly after `- ` # Whether the document requires an explicit document end indicator self.open_ended = False @@ -191,36 +187,34 @@ self.best_width = 80 if width and width > self.best_sequence_indent * 2: self.best_width = width - self.best_line_break = '\n' # type: Any + self.best_line_break: Any = '\n' if line_break in '\r', '\n', '\r\n': self.best_line_break = line_break # Tag prefixes. - self.tag_prefixes = None # type: Any + self.tag_prefixes: Any = None # Prepared anchor and tag. - self.prepared_anchor = None # type: Any - self.prepared_tag = None # type: Any + self.prepared_anchor: Any = None + self.prepared_tag: Any = None # Scalar analysis and style. - self.analysis = None # type: Any - self.style = None # type: Any + self.analysis: Any = None + self.style: Any = None self.scalar_after_indicator = True # write a scalar on the same line as `---`
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/error.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/error.py
Changed
@@ -3,10 +3,7 @@ import warnings import textwrap -from ruamel.yaml.compat import _F - -if False: # MYPY - from typing import Any, Dict, Optional, List, Text # NOQA +from typing import Any, Dict, Optional, List, Text # NOQA __all__ = @@ -25,33 +22,24 @@ class StreamMark: __slots__ = 'name', 'index', 'line', 'column' - def __init__(self, name, index, line, column): - # type: (Any, int, int, int) -> None + def __init__(self, name: Any, index: int, line: int, column: int) -> None: self.name = name self.index = index self.line = line self.column = column - def __str__(self): - # type: () -> Any - where = _F( - ' in "{sname!s}", line {sline1:d}, column {scolumn1:d}', - sname=self.name, - sline1=self.line + 1, - scolumn1=self.column + 1, - ) + def __str__(self) -> Any: + where = f' in "{self.name!s}", line {self.line + 1:d}, column {self.column + 1:d}' return where - def __eq__(self, other): - # type: (Any) -> bool + def __eq__(self, other: Any) -> bool: if self.line != other.line or self.column != other.column: return False if self.name != other.name or self.index != other.index: return False return True - def __ne__(self, other): - # type: (Any) -> bool + def __ne__(self, other: Any) -> bool: return not self.__eq__(other) @@ -62,14 +50,14 @@ class StringMark(StreamMark): __slots__ = 'name', 'index', 'line', 'column', 'buffer', 'pointer' - def __init__(self, name, index, line, column, buffer, pointer): - # type: (Any, int, int, int, Any, Any) -> None + def __init__( + self, name: Any, index: int, line: int, column: int, buffer: Any, pointer: Any + ) -> None: StreamMark.__init__(self, name, index, line, column) self.buffer = buffer self.pointer = pointer - def get_snippet(self, indent=4, max_length=75): - # type: (int, int) -> Any + def get_snippet(self, indent: int = 4, max_length: int = 75) -> Any: if self.buffer is None: # always False return None head = "" @@ -90,7 +78,7 @@ break snippet = self.bufferstart:end caret = '^' - caret = '^ (line: {})'.format(self.line + 1) + caret = f'^ (line: {self.line + 1})' return ( ' ' * indent + head @@ -101,28 +89,16 @@ + caret ) - def __str__(self): - # type: () -> Any + def __str__(self) -> Any: snippet = self.get_snippet() - where = _F( - ' in "{sname!s}", line {sline1:d}, column {scolumn1:d}', - sname=self.name, - sline1=self.line + 1, - scolumn1=self.column + 1, - ) + where = f' in "{self.name!s}", line {self.line + 1:d}, column {self.column + 1:d}' if snippet is not None: where += ':\n' + snippet return where - def __repr__(self): - # type: () -> Any + def __repr__(self) -> Any: snippet = self.get_snippet() - where = _F( - ' in "{sname!s}", line {sline1:d}, column {scolumn1:d}', - sname=self.name, - sline1=self.line + 1, - scolumn1=self.column + 1, - ) + where = f' in "{self.name!s}", line {self.line + 1:d}, column {self.column + 1:d}' if snippet is not None: where += ':\n' + snippet return where @@ -131,8 +107,7 @@ class CommentMark: __slots__ = ('column',) - def __init__(self, column): - # type: (Any) -> None + def __init__(self, column: Any) -> None: self.column = column @@ -143,14 +118,13 @@ class MarkedYAMLError(YAMLError): def __init__( self, - context=None, - context_mark=None, - problem=None, - problem_mark=None, - note=None, - warn=None, - ): - # type: (Any, Any, Any, Any, Any, Any) -> None + context: Any = None, + context_mark: Any = None, + problem: Any = None, + problem_mark: Any = None, + note: Any = None, + warn: Any = None, + ) -> None: self.context = context self.context_mark = context_mark self.problem = problem @@ -158,9 +132,8 @@ self.note = note # warn is ignored - def __str__(self): - # type: () -> Any - lines = # type: Liststr + def __str__(self) -> Any: + lines: Liststr = if self.context is not None: lines.append(self.context) if self.context_mark is not None and ( @@ -192,14 +165,13 @@ class MarkedYAMLWarning(YAMLWarning): def __init__( self, - context=None, - context_mark=None, - problem=None, - problem_mark=None, - note=None, - warn=None, - ): - # type: (Any, Any, Any, Any, Any, Any) -> None + context: Any = None, + context_mark: Any = None, + problem: Any = None, + problem_mark: Any = None, + note: Any = None, + warn: Any = None, + ) -> None: self.context = context self.context_mark = context_mark self.problem = problem @@ -207,9 +179,8 @@ self.note = note self.warn = warn - def __str__(self): - # type: () -> Any - lines = # type: Liststr + def __str__(self) -> Any: + lines: Liststr = if self.context is not None: lines.append(self.context) if self.context_mark is not None and ( @@ -254,30 +225,26 @@ class MantissaNoDotYAML1_1Warning(YAMLWarning): - def __init__(self, node, flt_str): - # type: (Any, Any) -> None + def __init__(self, node: Any, flt_str: Any) -> None: self.node = node self.flt = flt_str
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/events.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/events.py
Changed
@@ -1,25 +1,24 @@ # coding: utf-8 -from ruamel.yaml.compat import _F - # Abstract classes. -if False: # MYPY - from typing import Any, Dict, Optional, List # NOQA +from typing import Any, Dict, Optional, List # NOQA +from ruamel.yaml.tag import Tag SHOW_LINES = False -def CommentCheck(): - # type: () -> None +def CommentCheck() -> None: pass class Event: __slots__ = 'start_mark', 'end_mark', 'comment' + crepr = 'Unspecified Event' - def __init__(self, start_mark=None, end_mark=None, comment=CommentCheck): - # type: (Any, Any, Any) -> None + def __init__( + self, start_mark: Any = None, end_mark: Any = None, comment: Any = CommentCheck + ) -> None: self.start_mark = start_mark self.end_mark = end_mark # assert comment is not CommentCheck @@ -27,29 +26,24 @@ comment = None self.comment = comment - def __repr__(self): - # type: () -> Any + def __repr__(self) -> Any: if True: arguments = if hasattr(self, 'value'): # if you use repr(getattr(self, 'value')) then flake8 complains about # abuse of getattr with a constant. When you change to self.value # then mypy throws an error - arguments.append(repr(self.value)) # type: ignore + arguments.append(repr(self.value)) for key in 'anchor', 'tag', 'implicit', 'flow_style', 'style': v = getattr(self, key, None) if v is not None: - arguments.append(_F('{key!s}={v!r}', key=key, v=v)) + arguments.append(f'{key!s}={v!r}') if self.comment not in None, CommentCheck: - arguments.append('comment={!r}'.format(self.comment)) + arguments.append(f'comment={self.comment!r}') if SHOW_LINES: arguments.append( - '({}:{}/{}:{})'.format( - self.start_mark.line, - self.start_mark.column, - self.end_mark.line, - self.end_mark.column, - ) + f'({self.start_mark.line}:{self.start_mark.column}/' + f'{self.end_mark.line}:{self.end_mark.column})' ) arguments = ', '.join(arguments) # type: ignore else: @@ -58,48 +52,49 @@ for key in 'anchor', 'tag', 'implicit', 'value', 'flow_style', 'style' if hasattr(self, key) - arguments = ', '.join( - _F('{k!s}={attr!r}', k=key, attr=getattr(self, key)) for key in attributes - ) + arguments = ', '.join(f'{key!s}={getattr(self, key)!r}' for key in attributes) if self.comment not in None, CommentCheck: - arguments += ', comment={!r}'.format(self.comment) - return _F( - '{self_class_name!s}({arguments!s})', - self_class_name=self.__class__.__name__, - arguments=arguments, - ) + arguments += f', comment={self.comment!r}' + return f'{self.__class__.__name__!s}({arguments!s})' + + def compact_repr(self) -> str: + return f'{self.crepr}' class NodeEvent(Event): __slots__ = ('anchor',) - def __init__(self, anchor, start_mark=None, end_mark=None, comment=None): - # type: (Any, Any, Any, Any) -> None + def __init__( + self, anchor: Any, start_mark: Any = None, end_mark: Any = None, comment: Any = None + ) -> None: Event.__init__(self, start_mark, end_mark, comment) self.anchor = anchor class CollectionStartEvent(NodeEvent): - __slots__ = 'tag', 'implicit', 'flow_style', 'nr_items' + __slots__ = 'ctag', 'implicit', 'flow_style', 'nr_items' def __init__( self, - anchor, - tag, - implicit, - start_mark=None, - end_mark=None, - flow_style=None, - comment=None, - nr_items=None, - ): - # type: (Any, Any, Any, Any, Any, Any, Any, Optionalint) -> None + anchor: Any, + tag: Any, + implicit: Any, + start_mark: Any = None, + end_mark: Any = None, + flow_style: Any = None, + comment: Any = None, + nr_items: Optionalint = None, + ) -> None: NodeEvent.__init__(self, anchor, start_mark, end_mark, comment) - self.tag = tag + self.ctag = tag self.implicit = implicit self.flow_style = flow_style self.nr_items = nr_items + @property + def tag(self) -> Optionalstr: + return None if self.ctag is None else str(self.ctag) + class CollectionEndEvent(Event): __slots__ = () @@ -110,87 +105,160 @@ class StreamStartEvent(Event): __slots__ = ('encoding',) + crepr = '+STR' - def __init__(self, start_mark=None, end_mark=None, encoding=None, comment=None): - # type: (Any, Any, Any, Any) -> None + def __init__( + self, + start_mark: Any = None, + end_mark: Any = None, + encoding: Any = None, + comment: Any = None, + ) -> None: Event.__init__(self, start_mark, end_mark, comment) self.encoding = encoding class StreamEndEvent(Event): __slots__ = () + crepr = '-STR' class DocumentStartEvent(Event): __slots__ = 'explicit', 'version', 'tags' + crepr = '+DOC' def __init__( self, - start_mark=None, - end_mark=None, - explicit=None, - version=None, - tags=None, - comment=None, - ): - # type: (Any, Any, Any, Any, Any, Any) -> None + start_mark: Any = None, + end_mark: Any = None, + explicit: Any = None, + version: Any = None, + tags: Any = None, + comment: Any = None, + ) -> None: Event.__init__(self, start_mark, end_mark, comment) self.explicit = explicit self.version = version self.tags = tags + def compact_repr(self) -> str: + start = ' ---' if self.explicit else '' + return f'{self.crepr}{start}' + class DocumentEndEvent(Event): __slots__ = ('explicit',) + crepr = '-DOC'
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/loader.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/loader.py
Changed
@@ -12,16 +12,19 @@ ) from ruamel.yaml.resolver import VersionedResolver -if False: # MYPY - from typing import Any, Dict, List, Union, Optional # NOQA - from ruamel.yaml.compat import StreamTextType, VersionType # NOQA +from typing import Any, Dict, List, Union, Optional # NOQA +from ruamel.yaml.compat import StreamTextType, VersionType # NOQA __all__ = 'BaseLoader', 'SafeLoader', 'Loader', 'RoundTripLoader' class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, VersionedResolver): - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: self.comment_handling = None Reader.__init__(self, stream, loader=self) Scanner.__init__(self, loader=self) @@ -32,8 +35,12 @@ class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, VersionedResolver): - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: self.comment_handling = None Reader.__init__(self, stream, loader=self) Scanner.__init__(self, loader=self) @@ -44,8 +51,12 @@ class Loader(Reader, Scanner, Parser, Composer, Constructor, VersionedResolver): - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: self.comment_handling = None Reader.__init__(self, stream, loader=self) Scanner.__init__(self, loader=self) @@ -63,8 +74,12 @@ RoundTripConstructor, VersionedResolver, ): - def __init__(self, stream, version=None, preserve_quotes=None): - # type: (StreamTextType, OptionalVersionType, Optionalbool) -> None + def __init__( + self, + stream: StreamTextType, + version: OptionalVersionType = None, + preserve_quotes: Optionalbool = None, + ) -> None: # self.reader = Reader.__init__(self, stream) self.comment_handling = None # issue 385 Reader.__init__(self, stream, loader=self)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/main.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/main.py
Changed
@@ -30,13 +30,13 @@ Constructor, RoundTripConstructor, ) -from ruamel.yaml.loader import Loader as UnsafeLoader +from ruamel.yaml.loader import Loader as UnsafeLoader # NOQA from ruamel.yaml.comments import CommentedMap, CommentedSeq, C_PRE -if False: # MYPY - from typing import List, Set, Dict, Union, Any, Callable, Optional, Text # NOQA - from ruamel.yaml.compat import StreamType, StreamTextType, VersionType # NOQA - from pathlib import Path +from typing import List, Set, Dict, Union, Any, Callable, Optional, Text, Type # NOQA +from types import TracebackType +from ruamel.yaml.compat import StreamType, StreamTextType, VersionType # NOQA +from pathlib import Path # NOQA try: from _ruamel_yaml import CParser, CEmitter # type: ignore @@ -51,8 +51,14 @@ class YAML: - def __init__(self, *, typ=None, pure=False, output=None, plug_ins=None): # input=None, - # type: (Any, OptionalText, Any, Any, Any) -> None + def __init__( + self: Any, + *, + typ: OptionalUnionListText, Text = None, + pure: Any = False, + output: Any = None, + plug_ins: Any = None, + ) -> None: # input=None, """ typ: 'rt'/None -> RoundTripLoader/RoundTripDumper, (default) 'safe' -> SafeLoader/SafeDumper, @@ -68,20 +74,20 @@ # self._input = input self._output = output - self._context_manager = None # type: Any + self._context_manager: Any = None - self.plug_ins = # type: ListAny + self.plug_ins: ListAny = for pu in ( if plug_ins is None else plug_ins) + self.official_plug_ins(): file_name = pu.replace(os.sep, '.') self.plug_ins.append(import_module(file_name)) - self.Resolver = ruamel.yaml.resolver.VersionedResolver # type: Any + self.Resolver: Any = ruamel.yaml.resolver.VersionedResolver self.allow_unicode = True - self.Reader = None # type: Any - self.Representer = None # type: Any - self.Constructor = None # type: Any - self.Scanner = None # type: Any - self.Serializer = None # type: Any - self.default_flow_style = None # type: Any + self.Reader: Any = None + self.Representer: Any = None + self.Constructor: Any = None + self.Scanner: Any = None + self.Serializer: Any = None + self.default_flow_style: Any = None self.comment_handling = None typ_found = 1 setup_rt = False @@ -112,7 +118,7 @@ elif 'rtsc' in self.typ: self.default_flow_style = False # no optimized rt-dumper yet - self.Emitter = ruamel.yaml.emitter.Emitter + self.Emitter = ruamel.yaml.emitter.RoundTripEmitter self.Serializer = ruamel.yaml.serializer.Serializer self.Representer = ruamel.yaml.representer.RoundTripRepresenter self.Scanner = ruamel.yaml.scanner.RoundTripScannerSC @@ -127,7 +133,7 @@ if setup_rt: self.default_flow_style = False # no optimized rt-dumper yet - self.Emitter = ruamel.yaml.emitter.Emitter + self.Emitter = ruamel.yaml.emitter.RoundTripEmitter self.Serializer = ruamel.yaml.serializer.Serializer self.Representer = ruamel.yaml.representer.RoundTripRepresenter self.Scanner = ruamel.yaml.scanner.RoundTripScanner @@ -139,29 +145,29 @@ self.stream = None self.canonical = None self.old_indent = None - self.width = None + self.width: Unionint, None = None self.line_break = None - self.map_indent = None - self.sequence_indent = None - self.sequence_dash_offset = 0 + self.map_indent: Unionint, None = None + self.sequence_indent: Unionint, None = None + self.sequence_dash_offset: int = 0 self.compact_seq_seq = None self.compact_seq_map = None self.sort_base_mapping_type_on_output = None # default: sort self.top_level_colon_align = None self.prefix_colon = None - self.version = None - self.preserve_quotes = None + self._version: OptionalAny = None + self.preserve_quotes: Optionalbool = None self.allow_duplicate_keys = False # duplicate keys in map, set self.encoding = 'utf-8' - self.explicit_start = None - self.explicit_end = None + self.explicit_start: Unionbool, None = None + self.explicit_end: Unionbool, None = None self.tags = None self.default_style = None self.top_level_block_style_scalar_no_indent_error_1_1 = False # directives end indicator with single scalar document - self.scalar_after_indicator = None + self.scalar_after_indicator: Optionalbool = None # a, b: 1, c: {d: 2} vs. a, {b: 1}, {c: {d: 2}} self.brace_single_entry_mapping_in_flow_sequence = False for module in self.plug_ins: @@ -171,12 +177,11 @@ break if typ_found == 0: raise NotImplementedError( - 'typ "{}"not recognised (need to install plug-in?)'.format(self.typ) + f'typ "{self.typ}" not recognised (need to install plug-in?)' ) @property - def reader(self): - # type: () -> Any + def reader(self) -> Any: try: return self._reader # type: ignore except AttributeError: @@ -184,8 +189,7 @@ return self._reader @property - def scanner(self): - # type: () -> Any + def scanner(self) -> Any: try: return self._scanner # type: ignore except AttributeError: @@ -193,8 +197,7 @@ return self._scanner @property - def parser(self): - # type: () -> Any + def parser(self) -> Any: attr = '_' + sys._getframe().f_code.co_name if not hasattr(self, attr): if self.Parser is not CParser: @@ -215,16 +218,14 @@ return getattr(self, attr) @property - def composer(self): - # type: () -> Any + def composer(self) -> Any: attr = '_' + sys._getframe().f_code.co_name if not hasattr(self, attr): setattr(self, attr, self.Composer(loader=self)) return getattr(self, attr) @property - def constructor(self): - # type: () -> Any + def constructor(self) -> Any: attr = '_' + sys._getframe().f_code.co_name if not hasattr(self, attr): cnst = self.Constructor(preserve_quotes=self.preserve_quotes, loader=self) @@ -233,16 +234,14 @@ return getattr(self, attr) @property - def resolver(self): - # type: () -> Any + def resolver(self) -> Any: attr = '_' + sys._getframe().f_code.co_name if not hasattr(self, attr): setattr(self, attr, self.Resolver(version=self.version, loader=self)) return getattr(self, attr) @property - def emitter(self): - # type: () -> Any + def emitter(self) -> Any: attr = '_' + sys._getframe().f_code.co_name if not hasattr(self, attr): if self.Emitter is not CEmitter: @@ -277,8 +276,7 @@ return getattr(self, attr) @property
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/nodes.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/nodes.py
Changed
@@ -2,26 +2,41 @@ import sys -from ruamel.yaml.compat import _F - -if False: # MYPY - from typing import Dict, Any, Text # NOQA +from typing import Dict, Any, Text, Optional # NOQA +from ruamel.yaml.tag import Tag class Node: - __slots__ = 'tag', 'value', 'start_mark', 'end_mark', 'comment', 'anchor' + __slots__ = 'ctag', 'value', 'start_mark', 'end_mark', 'comment', 'anchor' - def __init__(self, tag, value, start_mark, end_mark, comment=None, anchor=None): - # type: (Any, Any, Any, Any, Any, Any) -> None - self.tag = tag + def __init__( + self, + tag: Any, + value: Any, + start_mark: Any, + end_mark: Any, + comment: Any = None, + anchor: Any = None, + ) -> None: + # you can still get a string from the serializer + self.ctag = tag if isinstance(tag, Tag) else Tag(suffix=tag) self.value = value self.start_mark = start_mark self.end_mark = end_mark self.comment = comment self.anchor = anchor - def __repr__(self): - # type: () -> Any + @property + def tag(self) -> Optionalstr: + return None if self.ctag is None else str(self.ctag) + + @tag.setter + def tag(self, val: Any) -> None: + if isinstance(val, str): + val = Tag(suffix=val) + self.ctag = val + + def __repr__(self) -> Any: value = self.value # if isinstance(value, list): # if len(value) == 0: @@ -36,29 +51,19 @@ # else: # value = repr(value) value = repr(value) - return _F( - '{class_name!s}(tag={self_tag!r}, value={value!s})', - class_name=self.__class__.__name__, - self_tag=self.tag, - value=value, - ) + return f'{self.__class__.__name__!s}(tag={self.tag!r}, value={value!s})' - def dump(self, indent=0): - # type: (int) -> None + def dump(self, indent: int = 0) -> None: + xx = self.__class__.__name__ + xi = ' ' * indent if isinstance(self.value, str): - sys.stdout.write( - '{}{}(tag={!r}, value={!r})\n'.format( - ' ' * indent, self.__class__.__name__, self.tag, self.value - ) - ) + sys.stdout.write(f'{xi}{xx}(tag={self.tag!r}, value={self.value!r})\n') if self.comment: - sys.stdout.write(' {}comment: {})\n'.format(' ' * indent, self.comment)) + sys.stdout.write(f' {xi}comment: {self.comment})\n') return - sys.stdout.write( - '{}{}(tag={!r})\n'.format(' ' * indent, self.__class__.__name__, self.tag) - ) + sys.stdout.write(f'{xi}{xx}(tag={self.tag!r})\n') if self.comment: - sys.stdout.write(' {}comment: {})\n'.format(' ' * indent, self.comment)) + sys.stdout.write(f' {xi}comment: {self.comment})\n') for v in self.value: if isinstance(v, tuple): for v1 in v: @@ -66,7 +71,7 @@ elif isinstance(v, Node): v.dump(indent + 1) else: - sys.stdout.write('Node value type? {}\n'.format(type(v))) + sys.stdout.write(f'Node value type? {type(v)}\n') class ScalarNode(Node): @@ -83,9 +88,15 @@ id = 'scalar' def __init__( - self, tag, value, start_mark=None, end_mark=None, style=None, comment=None, anchor=None - ): - # type: (Any, Any, Any, Any, Any, Any, Any) -> None + self, + tag: Any, + value: Any, + start_mark: Any = None, + end_mark: Any = None, + style: Any = None, + comment: Any = None, + anchor: Any = None, + ) -> None: Node.__init__(self, tag, value, start_mark, end_mark, comment=comment, anchor=anchor) self.style = style @@ -95,15 +106,14 @@ def __init__( self, - tag, - value, - start_mark=None, - end_mark=None, - flow_style=None, - comment=None, - anchor=None, - ): - # type: (Any, Any, Any, Any, Any, Any, Any) -> None + tag: Any, + value: Any, + start_mark: Any = None, + end_mark: Any = None, + flow_style: Any = None, + comment: Any = None, + anchor: Any = None, + ) -> None: Node.__init__(self, tag, value, start_mark, end_mark, comment=comment) self.flow_style = flow_style self.anchor = anchor @@ -120,15 +130,14 @@ def __init__( self, - tag, - value, - start_mark=None, - end_mark=None, - flow_style=None, - comment=None, - anchor=None, - ): - # type: (Any, Any, Any, Any, Any, Any, Any) -> None + tag: Any, + value: Any, + start_mark: Any = None, + end_mark: Any = None, + flow_style: Any = None, + comment: Any = None, + anchor: Any = None, + ) -> None: CollectionNode.__init__( self, tag, value, start_mark, end_mark, flow_style, comment, anchor )
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/parser.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/parser.py
Changed
@@ -80,16 +80,15 @@ from ruamel.yaml.scanner import Scanner, RoundTripScanner, ScannerError # NOQA from ruamel.yaml.scanner import BlankLineComment from ruamel.yaml.comments import C_PRE, C_POST, C_SPLIT_ON_FIRST_BLANK -from ruamel.yaml.compat import _F, nprint, nprintf # NOQA +from ruamel.yaml.compat import nprint, nprintf # NOQA +from ruamel.yaml.tag import Tag -if False: # MYPY - from typing import Any, Dict, Optional, List, Optional # NOQA +from typing import Any, Dict, Optional, List, Optional # NOQA __all__ = 'Parser', 'RoundTripParser', 'ParserError' -def xprintf(*args, **kw): - # type: (Any, Any) -> Any +def xprintf(*args: Any, **kw: Any) -> Any: return nprintf(*args, **kw) pass @@ -104,42 +103,36 @@ DEFAULT_TAGS = {'!': '!', '!!': 'tag:yaml.org,2002:'} - def __init__(self, loader): - # type: (Any) -> None + def __init__(self, loader: Any) -> None: self.loader = loader if self.loader is not None and getattr(self.loader, '_parser', None) is None: self.loader._parser = self self.reset_parser() - def reset_parser(self): - # type: () -> None + def reset_parser(self) -> None: # Reset the state attributes (to clear self-references) self.current_event = self.last_event = None - self.tag_handles = {} # type: DictAny, Any - self.states = # type: ListAny - self.marks = # type: ListAny - self.state = self.parse_stream_start # type: Any + self.tag_handles: DictAny, Any = {} + self.states: ListAny = + self.marks: ListAny = + self.state: Any = self.parse_stream_start - def dispose(self): - # type: () -> None + def dispose(self) -> None: self.reset_parser() @property - def scanner(self): - # type: () -> Any + def scanner(self) -> Any: if hasattr(self.loader, 'typ'): return self.loader.scanner return self.loader._scanner @property - def resolver(self): - # type: () -> Any + def resolver(self) -> Any: if hasattr(self.loader, 'typ'): return self.loader.resolver return self.loader._resolver - def check_event(self, *choices): - # type: (Any) -> bool + def check_event(self, *choices: Any) -> bool: # Check the type of the next event. if self.current_event is None: if self.state: @@ -152,16 +145,14 @@ return True return False - def peek_event(self): - # type: () -> Any + def peek_event(self) -> Any: # Get the next event. if self.current_event is None: if self.state: self.current_event = self.state() return self.current_event - def get_event(self): - # type: () -> Any + def get_event(self) -> Any: # Get the next event and proceed further. if self.current_event is None: if self.state: @@ -178,8 +169,7 @@ # implicit_document ::= block_node DOCUMENT-END* # explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* - def parse_stream_start(self): - # type: () -> Any + def parse_stream_start(self) -> Any: # Parse the stream start. token = self.scanner.get_token() self.move_token_comment(token) @@ -190,10 +180,10 @@ return event - def parse_implicit_document_start(self): - # type: () -> Any + def parse_implicit_document_start(self) -> Any: # Parse an implicit document. if not self.scanner.check_token(DirectiveToken, DocumentStartToken, StreamEndToken): + # don't need copy, as an implicit tag doesn't add tag_handles self.tag_handles = self.DEFAULT_TAGS token = self.scanner.peek_token() start_mark = end_mark = token.start_mark @@ -208,8 +198,7 @@ else: return self.parse_document_start() - def parse_document_start(self): - # type: () -> Any + def parse_document_start(self) -> Any: # Parse any extra document end indicators. while self.scanner.check_token(DocumentEndToken): self.scanner.get_token() @@ -220,10 +209,8 @@ raise ParserError( None, None, - _F( - "expected '<document start>', but found {pt!r}", - pt=self.scanner.peek_token().id, - ), + "expected '<document start>', " + f'but found {self.scanner.peek_token().id,!r}', self.scanner.peek_token().start_mark, ) token = self.scanner.get_token() @@ -232,10 +219,14 @@ # if self.loader is not None and \ # end_mark.line != self.scanner.peek_token().start_mark.line: # self.loader.scalar_after_indicator = False - event = DocumentStartEvent( - start_mark, end_mark, explicit=True, version=version, tags=tags, - comment=token.comment - ) # type: Any + event: Any = DocumentStartEvent( + start_mark, + end_mark, + explicit=True, + version=version, + tags=tags, + comment=token.comment, + ) self.states.append(self.parse_document_end) self.state = self.parse_document_content else: @@ -247,14 +238,25 @@ self.state = None return event - def parse_document_end(self): - # type: () -> Any + def parse_document_end(self) -> Any: # Parse the document end. token = self.scanner.peek_token() start_mark = end_mark = token.start_mark explicit = False if self.scanner.check_token(DocumentEndToken): token = self.scanner.get_token() + # if token.end_mark.line != self.peek_event().start_mark.line: + pt = self.scanner.peek_token() + if not isinstance(pt, StreamEndToken) and ( + token.end_mark.line == pt.start_mark.line + ): + raise ParserError( + None, + None, + 'found non-comment content after document end marker, ' + f'{self.scanner.peek_token().id,!r}', + self.scanner.peek_token().start_mark, + ) end_mark = token.end_mark explicit = True event = DocumentEndEvent(start_mark, end_mark, explicit=explicit) @@ -263,12 +265,15 @@ if self.resolver.processing_version == (1, 1): self.state = self.parse_document_start else: - self.state = self.parse_implicit_document_start + if explicit: + # found a document end marker, can be followed by implicit document + self.state = self.parse_implicit_document_start + else: + self.state = self.parse_document_start return event - def parse_document_content(self):
View file
_service:tar_scm:ruamel.yaml-0.17.32.tar.gz/pyproject.toml
Added
@@ -0,0 +1,4 @@ +build-system +requires = "setuptools", "wheel" +# test +build-backend = "setuptools.build_meta"
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/reader.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/reader.py
Changed
@@ -22,46 +22,35 @@ import codecs from ruamel.yaml.error import YAMLError, FileMark, StringMark, YAMLStreamError -from ruamel.yaml.compat import _F # NOQA from ruamel.yaml.util import RegExp -if False: # MYPY - from typing import Any, Dict, Optional, List, Union, Text, Tuple, Optional # NOQA -# from ruamel.yaml.compat import StreamTextType # NOQA +from typing import Any, Dict, Optional, List, Union, Text, Tuple, Optional # NOQA +# from ruamel.yaml.compat import StreamTextType # NOQA __all__ = 'Reader', 'ReaderError' class ReaderError(YAMLError): - def __init__(self, name, position, character, encoding, reason): - # type: (Any, Any, Any, Any, Any) -> None + def __init__( + self, name: Any, position: Any, character: Any, encoding: Any, reason: Any + ) -> None: self.name = name self.character = character self.position = position self.encoding = encoding self.reason = reason - def __str__(self): - # type: () -> Any + def __str__(self) -> Any: if isinstance(self.character, bytes): - return _F( - "'{self_encoding!s}' codec can't decode byte #x{ord_self_character:02x}: " - '{self_reason!s}\n' - ' in "{self_name!s}", position {self_position:d}', - self_encoding=self.encoding, - ord_self_character=ord(self.character), - self_reason=self.reason, - self_name=self.name, - self_position=self.position, + return ( + f"'{self.encoding!s}' codec can't decode byte #x{ord(self.character):02x}: " + f'{self.reason!s}\n' + f' in "{self.name!s}", position {self.position:d}' ) else: - return _F( - 'unacceptable character #x{self_character:04x}: {self_reason!s}\n' - ' in "{self_name!s}", position {self_position:d}', - self_character=self.character, - self_reason=self.reason, - self_name=self.name, - self_position=self.position, + return ( + f'unacceptable character #x{self.character:04x}: {self.reason!s}\n' + f' in "{self.name!s}", position {self.position:d}' ) @@ -79,39 +68,35 @@ # Yeah, it's ugly and slow. - def __init__(self, stream, loader=None): - # type: (Any, Any) -> None + def __init__(self, stream: Any, loader: Any = None) -> None: self.loader = loader if self.loader is not None and getattr(self.loader, '_reader', None) is None: self.loader._reader = self self.reset_reader() - self.stream = stream # type: Any # as .read is called + self.stream: Any = stream # as .read is called - def reset_reader(self): - # type: () -> None - self.name = None # type: Any + def reset_reader(self) -> None: + self.name: Any = None self.stream_pointer = 0 self.eof = True self.buffer = "" self.pointer = 0 - self.raw_buffer = None # type: Any + self.raw_buffer: Any = None self.raw_decode = None - self.encoding = None # type: OptionalText + self.encoding: OptionalText = None self.index = 0 self.line = 0 self.column = 0 @property - def stream(self): - # type: () -> Any + def stream(self) -> Any: try: return self._stream except AttributeError: - raise YAMLStreamError('input stream needs to specified') + raise YAMLStreamError('input stream needs to be specified') @stream.setter - def stream(self, val): - # type: (Any) -> None + def stream(self, val: Any) -> None: if val is None: return self._stream = None @@ -132,22 +117,19 @@ self.raw_buffer = None self.determine_encoding() - def peek(self, index=0): - # type: (int) -> Text + def peek(self, index: int = 0) -> Text: try: return self.bufferself.pointer + index except IndexError: self.update(index + 1) return self.bufferself.pointer + index - def prefix(self, length=1): - # type: (int) -> Any + def prefix(self, length: int = 1) -> Any: if self.pointer + length >= len(self.buffer): self.update(length) return self.bufferself.pointer : self.pointer + length - def forward_1_1(self, length=1): - # type: (int) -> None + def forward_1_1(self, length: int = 1) -> None: if self.pointer + length + 1 >= len(self.buffer): self.update(length + 1) while length != 0: @@ -163,8 +145,7 @@ self.column += 1 length -= 1 - def forward(self, length=1): - # type: (int) -> None + def forward(self, length: int = 1) -> None: if self.pointer + length + 1 >= len(self.buffer): self.update(length + 1) while length != 0: @@ -178,8 +159,7 @@ self.column += 1 length -= 1 - def get_mark(self): - # type: () -> Any + def get_mark(self) -> Any: if self.stream is None: return StringMark( self.name, self.index, self.line, self.column, self.buffer, self.pointer @@ -187,8 +167,7 @@ else: return FileMark(self.name, self.index, self.line, self.column) - def determine_encoding(self): - # type: () -> None + def determine_encoding(self) -> None: while not self.eof and (self.raw_buffer is None or len(self.raw_buffer) < 2): self.update_raw() if isinstance(self.raw_buffer, bytes): @@ -210,8 +189,7 @@ _printable_ascii = ('\x09\x0A\x0D' + "".join(map(chr, range(0x20, 0x7F)))).encode('ascii') @classmethod - def _get_non_printable_ascii(cls, data): # type: ignore - # type: (Text, bytes) -> OptionalTupleint, Text + def _get_non_printable_ascii(cls: Text, data: bytes) -> OptionalTupleint, Text: # type: ignore # NOQA ascii_bytes = data.encode('ascii') # type: ignore non_printables = ascii_bytes.translate(None, cls._printable_ascii) # type: ignore if not non_printables: @@ -220,23 +198,20 @@ return ascii_bytes.index(non_printable), non_printable.decode('ascii') @classmethod - def _get_non_printable_regex(cls, data): - # type: (Text) -> OptionalTupleint, Text + def _get_non_printable_regex(cls, data: Text) -> OptionalTupleint, Text: match = cls.NON_PRINTABLE.search(data) if not bool(match): return None return match.start(), match.group() @classmethod - def _get_non_printable(cls, data): - # type: (Text) -> OptionalTupleint, Text + def _get_non_printable(cls, data: Text) -> OptionalTupleint, Text: try: return cls._get_non_printable_ascii(data) # type: ignore except UnicodeEncodeError: return cls._get_non_printable_regex(data) - def check_printable(self, data): - # type: (Any) -> None + def check_printable(self, data: Any) -> None: non_printable_match = self._get_non_printable(data)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/representer.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/representer.py
Changed
@@ -3,7 +3,7 @@ from ruamel.yaml.error import * # NOQA from ruamel.yaml.nodes import * # NOQA from ruamel.yaml.compat import ordereddict -from ruamel.yaml.compat import _F, nprint, nprintf # NOQA +from ruamel.yaml.compat import nprint, nprintf # NOQA from ruamel.yaml.scalarstring import ( LiteralScalarString, FoldedScalarString, @@ -35,8 +35,7 @@ import copyreg import base64 -if False: # MYPY - from typing import Dict, List, Any, Union, Text, Optional # NOQA +from typing import Dict, List, Any, Union, Text, Optional # NOQA # fmt: off __all__ = 'BaseRepresenter', 'SafeRepresenter', 'Representer', @@ -50,24 +49,27 @@ class BaseRepresenter: - yaml_representers = {} # type: DictAny, Any - yaml_multi_representers = {} # type: DictAny, Any + yaml_representers: DictAny, Any = {} + yaml_multi_representers: DictAny, Any = {} - def __init__(self, default_style=None, default_flow_style=None, dumper=None): - # type: (Any, Any, Any, Any) -> None + def __init__( + self: Any, + default_style: Any = None, + default_flow_style: Any = None, + dumper: Any = None, + ) -> None: self.dumper = dumper if self.dumper is not None: self.dumper._representer = self self.default_style = default_style self.default_flow_style = default_flow_style - self.represented_objects = {} # type: DictAny, Any - self.object_keeper = # type: ListAny - self.alias_key = None # type: Optionalint + self.represented_objects: DictAny, Any = {} + self.object_keeper: ListAny = + self.alias_key: Optionalint = None self.sort_base_mapping_type_on_output = True @property - def serializer(self): - # type: () -> Any + def serializer(self) -> Any: try: if hasattr(self.dumper, 'typ'): return self.dumper.serializer @@ -75,16 +77,14 @@ except AttributeError: return self # cyaml - def represent(self, data): - # type: (Any) -> None + def represent(self, data: Any) -> None: node = self.represent_data(data) self.serializer.serialize(node) self.represented_objects = {} self.object_keeper = self.alias_key = None - def represent_data(self, data): - # type: (Any) -> Any + def represent_data(self, data: Any) -> Any: if self.ignore_aliases(data): self.alias_key = None else: @@ -117,8 +117,7 @@ # self.represented_objectsalias_key = node return node - def represent_key(self, data): - # type: (Any) -> Any + def represent_key(self, data: Any) -> Any: """ David Fraser: Extract a method to represent keys in mappings, so that a subclass can choose not to quote them (for example) @@ -128,21 +127,20 @@ return self.represent_data(data) @classmethod - def add_representer(cls, data_type, representer): - # type: (Any, Any) -> None + def add_representer(cls, data_type: Any, representer: Any) -> None: if 'yaml_representers' not in cls.__dict__: cls.yaml_representers = cls.yaml_representers.copy() cls.yaml_representersdata_type = representer @classmethod - def add_multi_representer(cls, data_type, representer): - # type: (Any, Any) -> None + def add_multi_representer(cls, data_type: Any, representer: Any) -> None: if 'yaml_multi_representers' not in cls.__dict__: cls.yaml_multi_representers = cls.yaml_multi_representers.copy() cls.yaml_multi_representersdata_type = representer - def represent_scalar(self, tag, value, style=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def represent_scalar( + self, tag: Any, value: Any, style: Any = None, anchor: Any = None + ) -> ScalarNode: if style is None: style = self.default_style comment = None @@ -150,14 +148,19 @@ comment = getattr(value, 'comment', None) if comment: comment = None, comment + if isinstance(tag, str): + tag = Tag(suffix=tag) node = ScalarNode(tag, value, style=style, comment=comment, anchor=anchor) if self.alias_key is not None: self.represented_objectsself.alias_key = node return node - def represent_sequence(self, tag, sequence, flow_style=None): - # type: (Any, Any, Any) -> Any - value = # type: ListAny + def represent_sequence( + self, tag: Any, sequence: Any, flow_style: Any = None + ) -> SequenceNode: + value: ListAny = + if isinstance(tag, str): + tag = Tag(suffix=tag) node = SequenceNode(tag, value, flow_style=flow_style) if self.alias_key is not None: self.represented_objectsself.alias_key = node @@ -174,9 +177,10 @@ node.flow_style = best_style return node - def represent_omap(self, tag, omap, flow_style=None): - # type: (Any, Any, Any) -> Any - value = # type: ListAny + def represent_omap(self, tag: Any, omap: Any, flow_style: Any = None) -> SequenceNode: + value: ListAny = + if isinstance(tag, str): + tag = Tag(suffix=tag) node = SequenceNode(tag, value, flow_style=flow_style) if self.alias_key is not None: self.represented_objectsself.alias_key = node @@ -195,9 +199,10 @@ node.flow_style = best_style return node - def represent_mapping(self, tag, mapping, flow_style=None): - # type: (Any, Any, Any) -> Any - value = # type: ListAny + def represent_mapping(self, tag: Any, mapping: Any, flow_style: Any = None) -> MappingNode: + value: ListAny = + if isinstance(tag, str): + tag = Tag(suffix=tag) node = MappingNode(tag, value, flow_style=flow_style) if self.alias_key is not None: self.represented_objectsself.alias_key = node @@ -224,14 +229,12 @@ node.flow_style = best_style return node - def ignore_aliases(self, data): - # type: (Any) -> bool + def ignore_aliases(self, data: Any) -> bool: return False class SafeRepresenter(BaseRepresenter): - def ignore_aliases(self, data): - # type: (Any) -> bool + def ignore_aliases(self, data: Any) -> bool: # https://docs.python.org/3/reference/expressions.html#parenthesized-forms : # "i.e. two occurrences of the empty tuple may or may not yield the same object" # so "data is ()" should not be used @@ -241,16 +244,13 @@ return True return False - def represent_none(self, data): - # type: (Any) -> Any + def represent_none(self, data: Any) -> ScalarNode: return self.represent_scalar('tag:yaml.org,2002:null', 'null') - def represent_str(self, data): - # type: (Any) -> Any + def represent_str(self, data: Any) -> Any: return self.represent_scalar('tag:yaml.org,2002:str', data) - def represent_binary(self, data): - # type: (Any) -> Any + def represent_binary(self, data: Any) -> ScalarNode: if hasattr(base64, 'encodebytes'): data = base64.encodebytes(data).decode('ascii') else:
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/resolver.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/resolver.py
Changed
@@ -2,11 +2,11 @@ import re -if False: # MYPY - from typing import Any, Dict, List, Union, Text, Optional # NOQA - from ruamel.yaml.compat import VersionType # NOQA +from typing import Any, Dict, List, Union, Text, Optional # NOQA +from ruamel.yaml.compat import VersionType # NOQA -from ruamel.yaml.compat import _DEFAULT_YAML_VERSION, _F # NOQA +from ruamel.yaml.tag import Tag +from ruamel.yaml.compat import _DEFAULT_YAML_VERSION # NOQA from ruamel.yaml.error import * # NOQA from ruamel.yaml.nodes import MappingNode, ScalarNode, SequenceNode # NOQA from ruamel.yaml.util import RegExp # NOQA @@ -103,25 +103,23 @@ class BaseResolver: - DEFAULT_SCALAR_TAG = 'tag:yaml.org,2002:str' - DEFAULT_SEQUENCE_TAG = 'tag:yaml.org,2002:seq' - DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map' + DEFAULT_SCALAR_TAG = Tag(suffix='tag:yaml.org,2002:str') + DEFAULT_SEQUENCE_TAG = Tag(suffix='tag:yaml.org,2002:seq') + DEFAULT_MAPPING_TAG = Tag(suffix='tag:yaml.org,2002:map') - yaml_implicit_resolvers = {} # type: DictAny, Any - yaml_path_resolvers = {} # type: DictAny, Any + yaml_implicit_resolvers: DictAny, Any = {} + yaml_path_resolvers: DictAny, Any = {} - def __init__(self, loadumper=None): - # type: (Any, Any) -> None + def __init__(self: Any, loadumper: Any = None) -> None: self.loadumper = loadumper if self.loadumper is not None and getattr(self.loadumper, '_resolver', None) is None: self.loadumper._resolver = self.loadumper - self._loader_version = None # type: Any - self.resolver_exact_paths = # type: ListAny - self.resolver_prefix_paths = # type: ListAny + self._loader_version: Any = None + self.resolver_exact_paths: ListAny = + self.resolver_prefix_paths: ListAny = @property - def parser(self): - # type: () -> Any + def parser(self) -> Any: if self.loadumper is not None: if hasattr(self.loadumper, 'typ'): return self.loadumper.parser @@ -129,8 +127,7 @@ return None @classmethod - def add_implicit_resolver_base(cls, tag, regexp, first): - # type: (Any, Any, Any) -> None + def add_implicit_resolver_base(cls, tag: Any, regexp: Any, first: Any) -> None: if 'yaml_implicit_resolvers' not in cls.__dict__: # deepcopy doesn't work here cls.yaml_implicit_resolvers = dict( @@ -142,8 +139,7 @@ cls.yaml_implicit_resolvers.setdefault(ch, ).append((tag, regexp)) @classmethod - def add_implicit_resolver(cls, tag, regexp, first): - # type: (Any, Any, Any) -> None + def add_implicit_resolver(cls, tag: Any, regexp: Any, first: Any) -> None: if 'yaml_implicit_resolvers' not in cls.__dict__: # deepcopy doesn't work here cls.yaml_implicit_resolvers = dict( @@ -159,8 +155,7 @@ # def add_implicit_resolver(cls, tag, regexp, first): @classmethod - def add_path_resolver(cls, tag, path, kind=None): - # type: (Any, Any, Any) -> None + def add_path_resolver(cls, tag: Any, path: Any, kind: Any = None) -> None: # Note: `add_path_resolver` is experimental. The API could be changed. # `new_path` is a pattern that is matched against the path from the # root to the node that is being considered. `node_path` elements are @@ -175,7 +170,7 @@ # against a sequence value with the index equal to `index_check`. if 'yaml_path_resolvers' not in cls.__dict__: cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy() - new_path = # type: ListAny + new_path: ListAny = for element in path: if isinstance(element, (list, tuple)): if len(element) == 2: @@ -184,9 +179,7 @@ node_check = element0 index_check = True else: - raise ResolverError( - _F('Invalid path element: {element!s}', element=element) - ) + raise ResolverError(f'Invalid path element: {element!s}') else: node_check = None index_check = element @@ -201,13 +194,9 @@ and not isinstance(node_check, str) and node_check is not None ): - raise ResolverError( - _F('Invalid node checker: {node_check!s}', node_check=node_check) - ) + raise ResolverError(f'Invalid node checker: {node_check!s}') if not isinstance(index_check, (str, int)) and index_check is not None: - raise ResolverError( - _F('Invalid index checker: {index_check!s}', index_check=index_check) - ) + raise ResolverError(f'Invalid index checker: {index_check!s}') new_path.append((node_check, index_check)) if kind is str: kind = ScalarNode @@ -216,11 +205,10 @@ elif kind is dict: kind = MappingNode elif kind not in ScalarNode, SequenceNode, MappingNode and kind is not None: - raise ResolverError(_F('Invalid node kind: {kind!s}', kind=kind)) + raise ResolverError(f'Invalid node kind: {kind!s}') cls.yaml_path_resolverstuple(new_path), kind = tag - def descend_resolver(self, current_node, current_index): - # type: (Any, Any) -> None + def descend_resolver(self, current_node: Any, current_index: Any) -> None: if not self.yaml_path_resolvers: return exact_paths = {} @@ -242,15 +230,15 @@ self.resolver_exact_paths.append(exact_paths) self.resolver_prefix_paths.append(prefix_paths) - def ascend_resolver(self): - # type: () -> None + def ascend_resolver(self) -> None: if not self.yaml_path_resolvers: return self.resolver_exact_paths.pop() self.resolver_prefix_paths.pop() - def check_resolver_prefix(self, depth, path, kind, current_node, current_index): - # type: (int, Any, Any, Any, Any) -> bool + def check_resolver_prefix( + self, depth: int, path: Any, kind: Any, current_node: Any, current_index: Any + ) -> bool: node_check, index_check = pathdepth - 1 if isinstance(node_check, str): if current_node.tag != node_check: @@ -272,8 +260,7 @@ return False return True - def resolve(self, kind, value, implicit): - # type: (Any, Any, Any) -> Any + def resolve(self, kind: Any, value: Any, implicit: Any) -> Any: if kind is ScalarNode and implicit0: if value == "": resolvers = self.yaml_implicit_resolvers.get("", ) @@ -282,14 +269,14 @@ resolvers += self.yaml_implicit_resolvers.get(None, ) for tag, regexp in resolvers: if regexp.match(value): - return tag + return Tag(suffix=tag) implicit = implicit1 if bool(self.yaml_path_resolvers): exact_paths = self.resolver_exact_paths-1 if kind in exact_paths: - return exact_pathskind + return Tag(suffix=exact_pathskind) if None in exact_paths: - return exact_pathsNone + return Tag(suffix=exact_pathsNone) if kind is ScalarNode: return self.DEFAULT_SCALAR_TAG elif kind is SequenceNode: @@ -298,8 +285,7 @@ return self.DEFAULT_MAPPING_TAG @property - def processing_version(self): - # type: () -> Any + def processing_version(self) -> Any: return None @@ -320,24 +306,25 @@ and Yes/No/On/Off booleans. """ - def __init__(self, version=None, loader=None, loadumper=None): - # type: (OptionalVersionType, Any, Any) -> None + def __init__( + self, version: OptionalVersionType = None, loader: Any = None, loadumper: Any = None + ) -> None: if loader is None and loadumper is not None:
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/ruamel.yaml.egg-info/PKG-INFO -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/ruamel.yaml.egg-info/PKG-INFO
Changed
@@ -1,13 +1,12 @@ Metadata-Version: 2.1 Name: ruamel.yaml -Version: 0.17.21 +Version: 0.17.32 Summary: ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order Home-page: https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree Author: Anthon van der Neut Author-email: a.van.der.neut@ruamel.eu License: MIT license Keywords: yaml 1.2 parser round-trip preserve quotes order config -Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License @@ -15,8 +14,7 @@ Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.10 -Classifier: Programming Language :: Python :: 3.5 -Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 @@ -36,32 +34,26 @@ ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.17.21 -:updated: 2022-02-12 +:version: 0.17.32 +:updated: 2023-06-17 :documentation: http://yaml.readthedocs.io :repository: https://sourceforge.net/projects/ruamel-yaml/ :pypi: https://pypi.org/project/ruamel.yaml/ -*The 0.16.13 release was the last that was tested to be working on Python 2.7. -The 0.17.21 is the last one tested to be working on Python 3.5, -that is also the last release supporting old PyYAML functions, you'll have to create a -`YAML()` instance and use its `.load()` and `.dump()` methods.* +*Starting with 0.17.22 only Python 3.7+ is supported. +The 0.17 series is also the last to support old PyYAML functions, replace it by +creating a `YAML()` instance and use its `.load()` and `.dump()` methods.* +New(er) functionality is usually only available via the new API. -*Please adjust your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* +The 0.17.21 was the last one tested to be working on Python 3.5 and 3.6 (the +latter was not tested, because +tox/virtualenv stopped supporting that EOL version). +The 0.16.13 release was the last that was tested to be working on Python 2.7. -Starting with version 0.15.0 the way YAML files are loaded and dumped -has been changing, see the API doc for details. Currently existing -functionality will throw a warning before being changed/removed. -**For production systems already using a pre 0.16 version, you should -pin the version being used with ``ruamel.yaml<=0.15``** if you cannot -fully test upgrading to a newer version. For new usage -pin to the minor version tested ( ``ruamel.yaml<=0.17``) or even to the -exact version used. +*Please adjust/pin your dependencies accordingly if necessary. (`ruamel.yaml<0.18`)* -New functionality is usually only available via the new API, so -make sure you use it and stop using the `ruamel.yaml.safe_load()`, -`ruamel.yaml.round_trip_load()` and `ruamel.yaml.load()` functions -(and their `....dump()` counterparts). +There are now two extra plug-in packages (`ruamel.yaml.bytes` and `ruamel.yaml.string`) +for those not wanting to do the streaming to a `io.BytesIO/StringIO` buffer themselves. If your package uses ``ruamel.yaml`` and is not listed on PyPI, drop me an email, preferably with some information on how you use the @@ -99,6 +91,96 @@ .. should insert NEXT: at the beginning of line for next key (with empty line) +0.17.32 (2023-06-17): + - fix issue with scanner getting stuck in infinite loop + +0.17.31 (2023-05-31): + - added tag.setter on `ScalarEvent` and on `Node`, that takes either + a `Tag` instance, or a str + (reported by `Sorin Sbarnea <https://sourceforge.net/u/ssbarnea/profile/>`__) + +0.17.30 (2023-05-30): + - fix issue 467, caused by Tag instances not being hashable (reported by + `Douglas Raillard + <https://bitbucket.org/%7Bcf052d92-a278-4339-9aa8-de41923bb556%7D/>`__) + +0.17.29 (2023-05-30): + - changed the internals of the tag property from a string to a class which allows + for preservation of the original handle and suffix. This should + result in better results using documents with %TAG directives, as well + as preserving URI escapes in tag suffixes. + +0.17.28 (2023-05-26): + - fix for issue 464: documents ending with document end marker without final newline + fail to load (reported by `Mariusz Rusiniak <https://sourceforge.net/u/r2dan/profile/>`__) + +0.17.27 (2023-05-25): + - fix issue with inline mappings as value for merge keys + (reported by Sirish on `StackOverflow <https://stackoverflow.com/q/76331049/1307905>`__) + - fix for 468, error inserting after accessing merge attribute on ``CommentedMap`` + (reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__) + - fix for issue 461 pop + insert on same `CommentedMap` key throwing error + (reported by `John Thorvald Wodder II <https://sourceforge.net/u/jwodder/profile/>`__) + +0.17.26 (2023-05-09): + - fix for error on edge cage for issue 459 + +0.17.25 (2023-05-09): + - fix for regression while dumping wrapped strings with too many backslashes removed + (issue 459, reported by `Lele Gaifax <https://sourceforge.net/u/lele/profile/>`__) + +0.17.24 (2023-05-06): + - rewrite of ``CommentedMap.insert()``. If you have a merge key in + the YAML document for the mapping you insert to, the position value should + be the one as you look at the YAML input. + This fixes issue 453 where other + keys of a merged in mapping would show up after an insert (reported by + `Alex Miller <https://sourceforge.net/u/millerdevel/profile/>`__). It + also fixes a call to `.insert()` resulting into the merge key to move + to be the first key if it wasn't already and it is also now possible + to insert a key before a merge key (even if the fist key in the mapping). + - fix (in the pure Python implementation including default) for issue 447. + (reported by `Jack Cherng <https://sourceforge.net/u/jfcherng/profile/>`__, + also brought up by brent on + `StackOverflow <https://stackoverflow.com/q/40072485/1307905>`__) + +0.17.23 (2023-05-05): + - fix 458, error on plain scalars starting with word longer than width. + (reported by `Kyle Larose <https://sourceforge.net/u/klarose/profile/>`__) + - fix for ``.update()`` no longer correctly handling keyword arguments + (reported by John Lin on <StackOverflow + `<https://stackoverflow.com/q/76089100/1307905>`__) + - fix issue 454: high Unicode (emojis) in quoted strings always + escaped (reported by `Michal Čihař <https://sourceforge.net/u/nijel/profile/>`__ + based on a question on StackOverflow). + - fix issue with emitter conservatively inserting extra backslashes in wrapped + quoted strings (reported by thebenman on `StackOverflow + <https://stackoverflow.com/q/75631454/1307905>`__) + +0.17.22 (2023-05-02): + + - fix issue 449 where the second exclamation marks got URL encoded (reported + and fixing PR provided by `John Stark <https://sourceforge.net/u/jods/profile/>`__) + - fix issue with indent != 2 and literal scalars with empty first line + (reported by wrdis on `StackOverflow <https://stackoverflow.com/q/75584262/1307905>`__) + - updated __repr__ of CommentedMap, now that Python's dict is ordered -> no more + ordereddict(list-of-tuples) + - merge MR 4, handling OctalInt in YAML 1.1 + (provided by `Jacob Floyd <https://sourceforge.net/u/cognifloyd/profile/>`_) + - fix loading of `!!float 42` (reported by Eric on + `Stack overflow <https://stackoverflow.com/a/71555107/1307905>`_) + - line numbers are now set on `CommentedKeySeq` and `CommentedKeyMap` (which + are created if you have a sequence resp. mapping as the key in a mapping) + - plain scalars: put single words longer than width on a line of their own, instead + of after the previous line (issue 427, reported by `Antoine Cotten + <https://sourceforge.net/u/antoineco/profile/>`_). Caveat: this currently results in a + space ending the previous line. + - fix for folded scalar part of 421: comments after ">" on first line of folded + scalars are now preserved (as were those in the same position on literal scalars). + Issue reported by Jacob Floyd. + - added stacklevel to warnings + - typing changed from Py2 compatible comments to Py3, removed various Py2-isms + 0.17.21 (2022-02-12): - fix bug in calling `.compose()` method with `pathlib.Path` instance. @@ -137,7 +219,7 @@ attrs with `@attr.s()` (both reported by `ssph <https://sourceforge.net/u/sph/>`__) 0.17.11 (2021-08-19): - - fix error baseclass for ``DuplicateKeyErorr`` (reported by `Łukasz Rogalski + - fix error baseclass for ``DuplicateKeyError`` (reported by `Łukasz Rogalski <https://sourceforge.net/u/lrogalski/>`__) - fix typo in reader error message, causing `KeyError` during reader error (reported by `MTU <https://sourceforge.net/u/mtu/>`__) @@ -288,5 +370,3 @@ For older changes see the file `CHANGES <https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/CHANGES>`_ - -
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/ruamel.yaml.egg-info/SOURCES.txt -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/ruamel.yaml.egg-info/SOURCES.txt
Changed
@@ -2,6 +2,7 @@ LICENSE MANIFEST.in README.rst +pyproject.toml setup.py ./LICENSE ./__init__.py @@ -30,13 +31,13 @@ ./scalarstring.py ./scanner.py ./serializer.py +./tag.py ./timestamp.py ./tokens.py ./util.py -.ruamel/__init__.py ruamel.yaml.egg-info/PKG-INFO ruamel.yaml.egg-info/SOURCES.txt ruamel.yaml.egg-info/dependency_links.txt -ruamel.yaml.egg-info/namespace_packages.txt +ruamel.yaml.egg-info/not-zip-safe ruamel.yaml.egg-info/requires.txt ruamel.yaml.egg-info/top_level.txt \ No newline at end of file
View file
_service:tar_scm:ruamel.yaml-0.17.32.tar.gz/ruamel.yaml.egg-info/not-zip-safe
Added
@@ -0,0 +1,1 @@ +
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/ruamel.yaml.egg-info/requires.txt -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/ruamel.yaml.egg-info/requires.txt
Changed
@@ -1,6 +1,6 @@ -:platform_python_implementation=="CPython" and python_version<"3.11" -ruamel.yaml.clib>=0.2.6 +:platform_python_implementation=="CPython" and python_version<"3.12" +ruamel.yaml.clib>=0.2.7 docs ryd
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/scalarbool.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/scalarbool.py
Changed
@@ -11,15 +11,13 @@ from ruamel.yaml.anchor import Anchor -if False: # MYPY - from typing import Text, Any, Dict, List # NOQA +from typing import Text, Any, Dict, List # NOQA __all__ = 'ScalarBoolean' class ScalarBoolean(int): - def __new__(cls, *args, **kw): - # type: (Any, Any, Any) -> Any + def __new__(cls: Any, *args: Any, **kw: Any) -> Any: anchor = kw.pop('anchor', None) b = int.__new__(cls, *args, **kw) if anchor is not None: @@ -27,21 +25,18 @@ return b @property - def anchor(self): - # type: () -> Any + def anchor(self) -> Any: if not hasattr(self, Anchor.attrib): setattr(self, Anchor.attrib, Anchor()) return getattr(self, Anchor.attrib) - def yaml_anchor(self, any=False): - # type: (bool) -> Any + def yaml_anchor(self, any: bool = False) -> Any: if not hasattr(self, Anchor.attrib): return None if any or self.anchor.always_dump: return self.anchor return None - def yaml_set_anchor(self, value, always_dump=False): - # type: (Any, bool) -> None + def yaml_set_anchor(self, value: Any, always_dump: bool = False) -> None: self.anchor.value = value self.anchor.always_dump = always_dump
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/scalarfloat.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/scalarfloat.py
Changed
@@ -3,15 +3,13 @@ import sys from ruamel.yaml.anchor import Anchor -if False: # MYPY - from typing import Text, Any, Dict, List # NOQA +from typing import Text, Any, Dict, List # NOQA __all__ = 'ScalarFloat', 'ExponentialFloat', 'ExponentialCapsFloat' class ScalarFloat(float): - def __new__(cls, *args, **kw): - # type: (Any, Any, Any) -> Any + def __new__(cls: Any, *args: Any, **kw: Any) -> Any: width = kw.pop('width', None) prec = kw.pop('prec', None) m_sign = kw.pop('m_sign', None) @@ -34,24 +32,21 @@ v.yaml_set_anchor(anchor, always_dump=True) return v - def __iadd__(self, a): # type: ignore - # type: (Any) -> Any + def __iadd__(self, a: Any) -> Any: # type: ignore return float(self) + a x = type(self)(self + a) x._width = self._width x._underscore = self._underscore: if self._underscore is not None else None # NOQA return x - def __ifloordiv__(self, a): # type: ignore - # type: (Any) -> Any + def __ifloordiv__(self, a: Any) -> Any: # type: ignore return float(self) // a x = type(self)(self // a) x._width = self._width x._underscore = self._underscore: if self._underscore is not None else None # NOQA return x - def __imul__(self, a): # type: ignore - # type: (Any) -> Any + def __imul__(self, a: Any) -> Any: # type: ignore return float(self) * a x = type(self)(self * a) x._width = self._width @@ -59,16 +54,14 @@ x._prec = self._prec # check for others return x - def __ipow__(self, a): # type: ignore - # type: (Any) -> Any + def __ipow__(self, a: Any) -> Any: # type: ignore return float(self) ** a x = type(self)(self ** a) x._width = self._width x._underscore = self._underscore: if self._underscore is not None else None # NOQA return x - def __isub__(self, a): # type: ignore - # type: (Any) -> Any + def __isub__(self, a: Any) -> Any: # type: ignore return float(self) - a x = type(self)(self - a) x._width = self._width @@ -76,49 +69,35 @@ return x @property - def anchor(self): - # type: () -> Any + def anchor(self) -> Any: if not hasattr(self, Anchor.attrib): setattr(self, Anchor.attrib, Anchor()) return getattr(self, Anchor.attrib) - def yaml_anchor(self, any=False): - # type: (bool) -> Any + def yaml_anchor(self, any: bool = False) -> Any: if not hasattr(self, Anchor.attrib): return None if any or self.anchor.always_dump: return self.anchor return None - def yaml_set_anchor(self, value, always_dump=False): - # type: (Any, bool) -> None + def yaml_set_anchor(self, value: Any, always_dump: bool = False) -> None: self.anchor.value = value self.anchor.always_dump = always_dump - def dump(self, out=sys.stdout): - # type: (Any) -> Any + def dump(self, out: Any = sys.stdout) -> None: out.write( - 'ScalarFloat({}| w:{}, p:{}, s:{}, lz:{}, _:{}|{}, w:{}, s:{})\n'.format( - self, - self._width, # type: ignore - self._prec, # type: ignore - self._m_sign, # type: ignore - self._m_lead0, # type: ignore - self._underscore, # type: ignore - self._exp, # type: ignore - self._e_width, # type: ignore - self._e_sign, # type: ignore - ) + f'ScalarFloat({self}| w:{self._width}, p:{self._prec}, ' # type: ignore + f's:{self._m_sign}, lz:{self._m_lead0}, _:{self._underscore}|{self._exp}' + f', w:{self._e_width}, s:{self._e_sign})\n' ) class ExponentialFloat(ScalarFloat): - def __new__(cls, value, width=None, underscore=None): - # type: (Any, Any, Any) -> Any + def __new__(cls, value: Any, width: Any = None, underscore: Any = None) -> Any: return ScalarFloat.__new__(cls, value, width=width, underscore=underscore) class ExponentialCapsFloat(ScalarFloat): - def __new__(cls, value, width=None, underscore=None): - # type: (Any, Any, Any) -> Any + def __new__(cls, value: Any, width: Any = None, underscore: Any = None) -> Any: return ScalarFloat.__new__(cls, value, width=width, underscore=underscore)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/scalarint.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/scalarint.py
Changed
@@ -2,15 +2,13 @@ from ruamel.yaml.anchor import Anchor -if False: # MYPY - from typing import Text, Any, Dict, List # NOQA +from typing import Text, Any, Dict, List # NOQA __all__ = 'ScalarInt', 'BinaryInt', 'OctalInt', 'HexInt', 'HexCapsInt', 'DecimalInt' class ScalarInt(int): - def __new__(cls, *args, **kw): - # type: (Any, Any, Any) -> Any + def __new__(cls: Any, *args: Any, **kw: Any) -> Any: width = kw.pop('width', None) underscore = kw.pop('underscore', None) anchor = kw.pop('anchor', None) @@ -21,8 +19,7 @@ v.yaml_set_anchor(anchor, always_dump=True) return v - def __iadd__(self, a): # type: ignore - # type: (Any) -> Any + def __iadd__(self, a: Any) -> Any: # type: ignore x = type(self)(self + a) x._width = self._width # type: ignore x._underscore = ( # type: ignore @@ -30,8 +27,7 @@ ) # NOQA return x - def __ifloordiv__(self, a): # type: ignore - # type: (Any) -> Any + def __ifloordiv__(self, a: Any) -> Any: # type: ignore x = type(self)(self // a) x._width = self._width # type: ignore x._underscore = ( # type: ignore @@ -39,8 +35,7 @@ ) # NOQA return x - def __imul__(self, a): # type: ignore - # type: (Any) -> Any + def __imul__(self, a: Any) -> Any: # type: ignore x = type(self)(self * a) x._width = self._width # type: ignore x._underscore = ( # type: ignore @@ -48,8 +43,7 @@ ) # NOQA return x - def __ipow__(self, a): # type: ignore - # type: (Any) -> Any + def __ipow__(self, a: Any) -> Any: # type: ignore x = type(self)(self ** a) x._width = self._width # type: ignore x._underscore = ( # type: ignore @@ -57,8 +51,7 @@ ) # NOQA return x - def __isub__(self, a): # type: ignore - # type: (Any) -> Any + def __isub__(self, a: Any) -> Any: # type: ignore x = type(self)(self - a) x._width = self._width # type: ignore x._underscore = ( # type: ignore @@ -67,35 +60,34 @@ return x @property - def anchor(self): - # type: () -> Any + def anchor(self) -> Any: if not hasattr(self, Anchor.attrib): setattr(self, Anchor.attrib, Anchor()) return getattr(self, Anchor.attrib) - def yaml_anchor(self, any=False): - # type: (bool) -> Any + def yaml_anchor(self, any: bool = False) -> Any: if not hasattr(self, Anchor.attrib): return None if any or self.anchor.always_dump: return self.anchor return None - def yaml_set_anchor(self, value, always_dump=False): - # type: (Any, bool) -> None + def yaml_set_anchor(self, value: Any, always_dump: bool = False) -> None: self.anchor.value = value self.anchor.always_dump = always_dump class BinaryInt(ScalarInt): - def __new__(cls, value, width=None, underscore=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def __new__( + cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None + ) -> Any: return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor) class OctalInt(ScalarInt): - def __new__(cls, value, width=None, underscore=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def __new__( + cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None + ) -> Any: return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor) @@ -106,22 +98,25 @@ class HexInt(ScalarInt): """uses lower case (a-f)""" - def __new__(cls, value, width=None, underscore=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def __new__( + cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None + ) -> Any: return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor) class HexCapsInt(ScalarInt): """uses upper case (A-F)""" - def __new__(cls, value, width=None, underscore=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def __new__( + cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None + ) -> Any: return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor) class DecimalInt(ScalarInt): """needed if anchor""" - def __new__(cls, value, width=None, underscore=None, anchor=None): - # type: (Any, Any, Any, Any) -> Any + def __new__( + cls, value: Any, width: Any = None, underscore: Any = None, anchor: Any = None + ) -> Any: return ScalarInt.__new__(cls, value, width=width, underscore=underscore, anchor=anchor)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/scalarstring.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/scalarstring.py
Changed
@@ -2,8 +2,8 @@ from ruamel.yaml.anchor import Anchor -if False: # MYPY - from typing import Text, Any, Dict, List # NOQA +from typing import Text, Any, Dict, List # NOQA +from ruamel.yaml.compat import SupportsIndex __all__ = 'ScalarString', @@ -21,35 +21,30 @@ class ScalarString(str): __slots__ = Anchor.attrib - def __new__(cls, *args, **kw): - # type: (Any, Any) -> Any + def __new__(cls, *args: Any, **kw: Any) -> Any: anchor = kw.pop('anchor', None) ret_val = str.__new__(cls, *args, **kw) if anchor is not None: ret_val.yaml_set_anchor(anchor, always_dump=True) return ret_val - def replace(self, old, new, maxreplace=-1): - # type: (Any, Any, int) -> Any + def replace(self, old: Any, new: Any, maxreplace: SupportsIndex = -1) -> Any: return type(self)((str.replace(self, old, new, maxreplace))) @property - def anchor(self): - # type: () -> Any + def anchor(self) -> Any: if not hasattr(self, Anchor.attrib): setattr(self, Anchor.attrib, Anchor()) return getattr(self, Anchor.attrib) - def yaml_anchor(self, any=False): - # type: (bool) -> Any + def yaml_anchor(self, any: bool = False) -> Any: if not hasattr(self, Anchor.attrib): return None if any or self.anchor.always_dump: return self.anchor return None - def yaml_set_anchor(self, value, always_dump=False): - # type: (Any, bool) -> None + def yaml_set_anchor(self, value: Any, always_dump: bool = False) -> None: self.anchor.value = value self.anchor.always_dump = always_dump @@ -59,8 +54,7 @@ style = '|' - def __new__(cls, value, anchor=None): - # type: (Text, Any) -> Any + def __new__(cls, value: Text, anchor: Any = None) -> Any: return ScalarString.__new__(cls, value, anchor=anchor) @@ -72,8 +66,7 @@ style = '>' - def __new__(cls, value, anchor=None): - # type: (Text, Any) -> Any + def __new__(cls, value: Text, anchor: Any = None) -> Any: return ScalarString.__new__(cls, value, anchor=anchor) @@ -82,8 +75,7 @@ style = "'" - def __new__(cls, value, anchor=None): - # type: (Text, Any) -> Any + def __new__(cls, value: Text, anchor: Any = None) -> Any: return ScalarString.__new__(cls, value, anchor=anchor) @@ -92,8 +84,7 @@ style = '"' - def __new__(cls, value, anchor=None): - # type: (Text, Any) -> Any + def __new__(cls, value: Text, anchor: Any = None) -> Any: return ScalarString.__new__(cls, value, anchor=anchor) @@ -102,18 +93,15 @@ style = '' - def __new__(cls, value, anchor=None): - # type: (Text, Any) -> Any + def __new__(cls, value: Text, anchor: Any = None) -> Any: return ScalarString.__new__(cls, value, anchor=anchor) -def preserve_literal(s): - # type: (Text) -> Text +def preserve_literal(s: Text) -> Text: return LiteralScalarString(s.replace('\r\n', '\n').replace('\r', '\n')) -def walk_tree(base, map=None): - # type: (Any, Any) -> None +def walk_tree(base: Any, map: Any = None) -> None: """ the routine here walks over a simple yaml tree (recursing in dict values and list items) and converts strings that @@ -133,7 +121,7 @@ if isinstance(base, MutableMapping): for k in base: - v = basek # type: Text + v: Text = basek if isinstance(v, str): for ch in map: if ch in v:
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/scanner.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/scanner.py
Changed
@@ -31,11 +31,10 @@ import inspect from ruamel.yaml.error import MarkedYAMLError, CommentMark # NOQA from ruamel.yaml.tokens import * # NOQA -from ruamel.yaml.compat import _F, check_anchorname_char, nprint, nprintf # NOQA +from ruamel.yaml.compat import check_anchorname_char, nprint, nprintf # NOQA -if False: # MYPY - from typing import Any, Dict, Optional, List, Union, Text # NOQA - from ruamel.yaml.compat import VersionType # NOQA +from typing import Any, Dict, Optional, List, Union, Text # NOQA +from ruamel.yaml.compat import VersionType # NOQA __all__ = 'Scanner', 'RoundTripScanner', 'ScannerError' @@ -45,8 +44,7 @@ _SPACE_TAB = ' \t' -def xprintf(*args, **kw): - # type: (Any, Any) -> Any +def xprintf(*args: Any, **kw: Any) -> Any: return nprintf(*args, **kw) pass @@ -58,8 +56,9 @@ class SimpleKey: # See below simple keys treatment. - def __init__(self, token_number, required, index, line, column, mark): - # type: (Any, Any, int, int, int, Any) -> None + def __init__( + self, token_number: Any, required: Any, index: int, line: int, column: int, mark: Any + ) -> None: self.token_number = token_number self.required = required self.index = index @@ -69,8 +68,7 @@ class Scanner: - def __init__(self, loader=None): - # type: (Any) -> None + def __init__(self, loader: Any = None) -> None: """Initialize the scanner.""" # It is assumed that Scanner and Reader will have a common descendant. # Reader do the dirty work of checking for BOM and converting the @@ -86,24 +84,22 @@ self.loader._scanner = self self.reset_scanner() self.first_time = False - self.yaml_version = None # type: Any + self.yaml_version: Any = None @property - def flow_level(self): - # type: () -> int + def flow_level(self) -> int: return len(self.flow_context) - def reset_scanner(self): - # type: () -> None + def reset_scanner(self) -> None: # Had we reached the end of the stream? self.done = False # flow_context is an expanding/shrinking list consisting of '{' and '' # for each unclosed flow context. If empty list that means block context - self.flow_context = # type: ListText + self.flow_context: ListText = # List of processed tokens that are not yet emitted. - self.tokens = # type: ListAny + self.tokens: ListAny = # Add the STREAM-START token. self.fetch_stream_start() @@ -115,7 +111,7 @@ self.indent = -1 # Past indentation levels. - self.indents = # type: Listint + self.indents: Listint = # Variables related to simple keys treatment. @@ -145,11 +141,10 @@ # (token_number, required, index, line, column, mark) # A simple key may start with ALIAS, ANCHOR, TAG, SCALAR(flow), # '', or '{' tokens. - self.possible_simple_keys = {} # type: DictAny, Any + self.possible_simple_keys: DictAny, Any = {} @property - def reader(self): - # type: () -> Any + def reader(self) -> Any: try: return self._scanner_reader # type: ignore except AttributeError: @@ -160,16 +155,14 @@ return self._scanner_reader @property - def scanner_processing_version(self): # prefix until un-composited - # type: () -> Any + def scanner_processing_version(self) -> Any: # prefix until un-composited if hasattr(self.loader, 'typ'): return self.loader.resolver.processing_version return self.loader.processing_version # Public methods. - def check_token(self, *choices): - # type: (Any) -> bool + def check_token(self, *choices: Any) -> bool: # Check if the next token is one of the given types. while self.need_more_tokens(): self.fetch_more_tokens() @@ -181,16 +174,14 @@ return True return False - def peek_token(self): - # type: () -> Any + def peek_token(self) -> Any: # Return the next token, but do not delete if from the queue. while self.need_more_tokens(): self.fetch_more_tokens() if len(self.tokens) > 0: return self.tokens0 - def get_token(self): - # type: () -> Any + def get_token(self) -> Any: # Return the next token. while self.need_more_tokens(): self.fetch_more_tokens() @@ -200,8 +191,7 @@ # Private methods. - def need_more_tokens(self): - # type: () -> bool + def need_more_tokens(self) -> bool: if self.done: return False if len(self.tokens) == 0: @@ -213,12 +203,10 @@ return True return False - def fetch_comment(self, comment): - # type: (Any) -> None + def fetch_comment(self, comment: Any) -> None: raise NotImplementedError - def fetch_more_tokens(self): - # type: () -> Any + def fetch_more_tokens(self) -> Any: # Eat whitespaces and comments until we reach the next token. comment = self.scan_to_next_token() if comment is not None: # never happens for base scanner @@ -323,14 +311,13 @@ raise ScannerError( 'while scanning for the next token', None, - _F('found character {ch!r} that cannot start any token', ch=ch), + f'found character {ch!r} that cannot start any token', self.reader.get_mark(), ) # Simple keys treatment. - def next_possible_simple_key(self): - # type: () -> Any + def next_possible_simple_key(self) -> Any: # Return the number of the nearest possible simple key. Actually we # don't need to loop through the whole dictionary. We may replace it # with the following code: @@ -345,8 +332,7 @@ min_token_number = key.token_number return min_token_number - def stale_possible_simple_keys(self): - # type: () -> None + def stale_possible_simple_keys(self) -> None: # Remove entries that are no longer possible simple keys. According to # the YAML specification, simple keys # - should be limited to a single line, @@ -365,8 +351,7 @@ ) del self.possible_simple_keyslevel - def save_possible_simple_key(self): - # type: () -> None + def save_possible_simple_key(self) -> None: # The next token may start a simple key. We check if it's possible # and save its position. This function is called for # ALIAS, ANCHOR, TAG, SCALAR(flow), '', and '{'.
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/serializer.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/serializer.py
Changed
@@ -18,9 +18,8 @@ ) from ruamel.yaml.nodes import MappingNode, ScalarNode, SequenceNode -if False: # MYPY - from typing import Any, Dict, Union, Text, Optional # NOQA - from ruamel.yaml.compat import VersionType # NOQA +from typing import Any, Dict, Union, Text, Optional # NOQA +from ruamel.yaml.compat import VersionType # NOQA __all__ = 'Serializer', 'SerializerError' @@ -32,19 +31,19 @@ class Serializer: # 'id' and 3+ numbers, but not 000 - ANCHOR_TEMPLATE = 'id%03d' + ANCHOR_TEMPLATE = 'id{:03d}' ANCHOR_RE = RegExp('id(?!000$)\\d{3,}') def __init__( self, - encoding=None, - explicit_start=None, - explicit_end=None, - version=None, - tags=None, - dumper=None, - ): - # type: (Any, Optionalbool, Optionalbool, OptionalVersionType, Any, Any) -> None # NOQA + encoding: Any = None, + explicit_start: Optionalbool = None, + explicit_end: Optionalbool = None, + version: OptionalVersionType = None, + tags: Any = None, + dumper: Any = None, + ) -> None: + # NOQA self.dumper = dumper if self.dumper is not None: self.dumper._serializer = self @@ -56,28 +55,25 @@ else: self.use_version = version # type: ignore self.use_tags = tags - self.serialized_nodes = {} # type: DictAny, Any - self.anchors = {} # type: DictAny, Any + self.serialized_nodes: DictAny, Any = {} + self.anchors: DictAny, Any = {} self.last_anchor_id = 0 - self.closed = None # type: Optionalbool + self.closed: Optionalbool = None self._templated_id = None @property - def emitter(self): - # type: () -> Any + def emitter(self) -> Any: if hasattr(self.dumper, 'typ'): return self.dumper.emitter return self.dumper._emitter @property - def resolver(self): - # type: () -> Any + def resolver(self) -> Any: if hasattr(self.dumper, 'typ'): self.dumper.resolver return self.dumper._resolver - def open(self): - # type: () -> None + def open(self) -> None: if self.closed is None: self.emitter.emit(StreamStartEvent(encoding=self.use_encoding)) self.closed = False @@ -86,8 +82,7 @@ else: raise SerializerError('serializer is already opened') - def close(self): - # type: () -> None + def close(self) -> None: if self.closed is None: raise SerializerError('serializer is not opened') elif not self.closed: @@ -97,8 +92,7 @@ # def __del__(self): # self.close() - def serialize(self, node): - # type: (Any) -> None + def serialize(self, node: Any) -> None: if dbg(DBG_NODE): nprint('Serializing nodes') node.dump() @@ -118,8 +112,7 @@ self.anchors = {} self.last_anchor_id = 0 - def anchor_node(self, node): - # type: (Any) -> None + def anchor_node(self, node: Any) -> None: if node in self.anchors: if self.anchorsnode is None: self.anchorsnode = self.generate_anchor(node) @@ -139,19 +132,17 @@ self.anchor_node(key) self.anchor_node(value) - def generate_anchor(self, node): - # type: (Any) -> Any + def generate_anchor(self, node: Any) -> Any: try: anchor = node.anchor.value except: # NOQA anchor = None if anchor is None: self.last_anchor_id += 1 - return self.ANCHOR_TEMPLATE % self.last_anchor_id + return self.ANCHOR_TEMPLATE.format(self.last_anchor_id) return anchor - def serialize_node(self, node, parent, index): - # type: (Any, Any, Any) -> None + def serialize_node(self, node: Any, parent: Any, index: Any) -> None: alias = self.anchorsnode if node in self.serialized_nodes: node_style = getattr(node, 'style', None) @@ -167,14 +158,14 @@ detected_tag = self.resolver.resolve(ScalarNode, node.value, (True, False)) default_tag = self.resolver.resolve(ScalarNode, node.value, (False, True)) implicit = ( - (node.tag == detected_tag), - (node.tag == default_tag), - node.tag.startswith('tag:yaml.org,2002:'), + (node.ctag == detected_tag), + (node.ctag == default_tag), + node.tag.startswith('tag:yaml.org,2002:'), # type: ignore ) self.emitter.emit( ScalarEvent( alias, - node.tag, + node.ctag, implicit, node.value, style=node.style, @@ -182,7 +173,7 @@ ) ) elif isinstance(node, SequenceNode): - implicit = node.tag == self.resolver.resolve(SequenceNode, node.value, True) + implicit = node.ctag == self.resolver.resolve(SequenceNode, node.value, True) comment = node.comment end_comment = None seq_comment = None @@ -197,7 +188,7 @@ self.emitter.emit( SequenceStartEvent( alias, - node.tag, + node.ctag, implicit, flow_style=node.flow_style, comment=node.comment, @@ -209,7 +200,7 @@ index += 1 self.emitter.emit(SequenceEndEvent(comment=seq_comment, end_comment)) elif isinstance(node, MappingNode): - implicit = node.tag == self.resolver.resolve(MappingNode, node.value, True) + implicit = node.ctag == self.resolver.resolve(MappingNode, node.value, True) comment = node.comment end_comment = None map_comment = None @@ -222,7 +213,7 @@ self.emitter.emit( MappingStartEvent( alias, - node.tag, + node.ctag, implicit, flow_style=node.flow_style, comment=node.comment, @@ -236,6 +227,5 @@ self.resolver.ascend_resolver() -def templated_id(s): - # type: (Text) -> Any +def templated_id(s: Text) -> Any: return Serializer.ANCHOR_RE.match(s)
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/setup.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/setup.py
Changed
@@ -1,15 +1,13 @@ # # header # coding: utf-8 -# dd: 20200903 - -from __future__ import print_function, absolute_import, division, unicode_literals +# dd: 20230418 # # __init__.py parser import sys import os import datetime -import traceback +from textwrap import dedent sys.path = path for path in sys.path if path not in os.getcwd(), "" import platform # NOQA @@ -20,13 +18,13 @@ from setuptools.command import install_lib # NOQA from setuptools.command.sdist import sdist as _sdist # NOQA -try: - from setuptools.namespaces import Installer as NameSpaceInstaller # NOQA -except ImportError: - msg = ('You should use the latest setuptools. The namespaces.py file that this setup.py' - ' uses was added in setuptools 28.7.0 (Oct 2016)') - print(msg) - sys.exit() +# try: +# from setuptools.namespaces import Installer as NameSpaceInstaller # NOQA +# except ImportError: +# msg = ('You should use the latest setuptools. The namespaces.py file that this setup.py' +# ' uses was added in setuptools 28.7.0 (Oct 2016)') +# print(msg) +# sys.exit() if __name__ != '__main__': raise NotImplementedError('should never include setup.py') @@ -278,8 +276,7 @@ class MySdist(_sdist): def initialize_options(self): _sdist.initialize_options(self) - # see pep 527, new uploads should be tar.gz or .zip - # fmt = getattr(self, 'tarfmt', None) + # failed expiriment, see pep 527, new uploads should be tar.gz or .zip # because of unicode_literals # self.formats = fmt if fmt else b'bztar' if sys.version_info < (3, ) else 'bztar' dist_base = os.environ.get('PYDISTBASE') @@ -317,8 +314,8 @@ self._split = None self.depth = self.full_package_name.count('.') self.nested = self._pkg_data.get('nested', False) - if self.nested: - NameSpaceInstaller.install_namespaces = lambda x: None + # if self.nested: + # NameSpaceInstaller.install_namespaces = lambda x: None self.command = None self.python_version() self._pkg = None, None # required and pre-installable packages @@ -387,9 +384,6 @@ return self._split @property - def namespace_packages(self): - return self.split: self.depth - def namespace_directories(self, depth=None): """return list of directories where the namespace should be created / can be found @@ -410,23 +404,11 @@ } if 'extra_packages' in self._pkg_data: return d - if len(self.split) > 1: # only if package namespace - dself.split0 = self.namespace_directories(1)0 + # if len(self.split) > 1: # only if package namespace + # dself.split0 = self.namespace_directories(1)0 + # print('d', d, os.getcwd()) return d - def create_dirs(self): - """create the directories necessary for namespace packaging""" - directories = self.namespace_directories(self.depth) - if not directories: - return - if not os.path.exists(directories0): - for d in directories: - os.mkdir(d) - with open(os.path.join(d, '__init__.py'), 'w') as fp: - fp.write( - 'import pkg_resources\n' 'pkg_resources.declare_namespace(__name__)\n' - ) - def python_version(self): supported = self._pkg_data.get('supported') if supported is None: @@ -718,7 +700,8 @@ @property def packages(self): - s = self.split + # s = self.split + s = self._pkg_data'full_package_name' # fixed this in package_data, the keys there must be non-unicode for py27 # if sys.version_info < (3, 0): # s = x.encode('utf-8') for x in self.split @@ -754,7 +737,7 @@ except ValueError: pass self._ext_modules = - no_test_compile = False + no_test_compile = True if '--restructuredtext' in sys.argv: no_test_compile = True elif 'sdist' in sys.argv: @@ -768,77 +751,7 @@ ) self._ext_modules.append(ext) return self._ext_modules - - print('sys.argv', sys.argv) - import tempfile - import shutil - from textwrap import dedent - - import distutils.sysconfig - import distutils.ccompiler - from distutils.errors import CompileError, LinkError - - for target in self._pkg_data.get('ext_modules', ): # list of dicts - ext = Extension( - self.pn(target'name'), - sources=self.pn(x) for x in target'src', - libraries=self.pn(x) for x in target.get('lib'), - ) - # debug('test1 in target', 'test' in target, target) - if 'test' not in target: # no test, just hope it works - self._ext_modules.append(ext) - continue - if sys.version_info:2 == (3, 4) and platform.system() == 'Windows': - # this is giving problems on appveyor, so skip - if 'FORCE_C_BUILD_TEST' not in os.environ: - self._ext_modules.append(ext) - continue - # write a temporary .c file to compile - c_code = dedent(target'test') - try: - tmp_dir = tempfile.mkdtemp(prefix='tmp_ruamel_') - bin_file_name = 'test' + self.pn(target'name') - file_name = os.path.join(tmp_dir, bin_file_name + '.c') - print('test compiling', file_name, '->', bin_file_name, end=' ') - with open(file_name, 'w') as fp: # write source - fp.write(c_code) - # and try to compile it - compiler = distutils.ccompiler.new_compiler() - assert isinstance(compiler, distutils.ccompiler.CCompiler) - # do any platform specific initialisations - distutils.sysconfig.customize_compiler(compiler) - # make sure you can reach header files because compile does change dir - compiler.add_include_dir(os.getcwd()) - if sys.version_info < (3,): - tmp_dir = tmp_dir.encode('utf-8') - # used to be a different directory, not necessary - compile_out_dir = tmp_dir - try: - compiler.link_executable( - compiler.compile(file_name, output_dir=compile_out_dir), - bin_file_name, - output_dir=tmp_dir, - libraries=ext.libraries, - ) - except CompileError: - debug('compile error:', file_name) - print('compile error:', file_name) - raise - except LinkError: - debug('link error', file_name) - print('link error', file_name) - raise - print('OK') - self._ext_modules.append(ext) - except Exception as e: # NOQA - debug('Exception:', e) - print('Exception:', e) - sys.exit(1) - if sys.version_info:2 == (3, 4) and platform.system() == 'Windows': - traceback.print_exc() - finally: - shutil.rmtree(tmp_dir) - return self._ext_modules + # this used to use distutils @property def test_suite(self): @@ -854,10 +767,6 @@ if os.path.exists(file_name): # add it if not in there? return False with open(file_name, 'w') as fp: - if os.path.exists('LICENSE'):
View file
_service:tar_scm:ruamel.yaml-0.17.32.tar.gz/tag.py
Added
@@ -0,0 +1,124 @@ +# coding: utf-8 + +""" +In round-trip mode the original tag needs to be preserved, but the tag +transformed based on the directives needs to be available as well. + +A Tag that is created during loading has a handle and a suffix. +Not all objects loaded currently have a Tag, that .tag attribute can be None +A Tag that is created for dumping only (on an object loaded without a tag) has a suffix +only. +""" + +from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA + +tag_attrib = '_yaml_tag' + + +class Tag: + """store original tag information for roundtripping""" + + attrib = tag_attrib + + def __init__(self, handle: Any = None, suffix: Any = None, handles: Any = None) -> None: + self.handle = handle + self.suffix = suffix + self.handles = handles + self._transform_type: Optionalbool = None + + def __repr__(self) -> str: + return f'{self.__class__.__name__}({self.trval!r})' + + def __str__(self) -> str: + return f'{self.trval}' + + def __hash__(self) -> int: + try: + return self._hash_id # type: ignore + except AttributeError: + self._hash_id = res = hash((self.handle, self.suffix)) + return res + + def __eq__(self, other: Any) -> bool: + # other should not be a string, but the serializer sometimes provides these + if isinstance(other, str): + return self.trval == other + return bool(self.trval == other.trval) + + def startswith(self, x: str) -> bool: + if self.trval is not None: + return self.trval.startswith(x) + return False + + @property + def trval(self) -> Optionalstr: + try: + return self._trval + except AttributeError: + pass + if self.handle is None: + self._trval: Optionalstr = self.uri_decoded_suffix + return self._trval + assert self._transform_type is not None + if not self._transform_type: + # the non-round-trip case + self._trval = self.handlesself.handle + self.uri_decoded_suffix + return self._trval + # round-trip case + if self.handle == '!!' and self.suffix in ( + 'null', + 'bool', + 'int', + 'float', + 'binary', + 'timestamp', + 'omap', + 'pairs', + 'set', + 'str', + 'seq', + 'map', + ): + self._trval = self.handlesself.handle + self.uri_decoded_suffix + else: + # self._trval = self.handle + self.suffix + self._trval = self.handlesself.handle + self.uri_decoded_suffix + return self._trval + + value = trval + + @property + def uri_decoded_suffix(self) -> Optionalstr: + try: + return self._uri_decoded_suffix + except AttributeError: + pass + if self.suffix is None: + self._uri_decoded_suffix: Optionalstr = None + return None + res = '' + # don't have to check for scanner errors here + idx = 0 + while idx < len(self.suffix): + ch = self.suffixidx + idx += 1 + if ch != '%': + res += ch + else: + res += chr(int(self.suffixidx : idx + 2, 16)) + idx += 2 + self._uri_decoded_suffix = res + return res + + def select_transform(self, val: bool) -> None: + """ + val: False -> non-round-trip + True -> round-trip + """ + assert self._transform_type is None + self._transform_type = val + + def check_handle(self) -> bool: + if self.handle is None: + return False + return self.handle not in self.handles
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/timestamp.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/timestamp.py
Changed
@@ -5,39 +5,36 @@ # 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 +# +# add type information (iso8601, spaced) -if False: # MYPY - from typing import Any, Dict, Optional, List # NOQA +from typing import Any, Dict, Optional, List # NOQA class TimeStamp(datetime.datetime): - def __init__(self, *args, **kw): - # type: (Any, Any) -> None - self._yaml = dict(t=False, tz=None, delta=0) # type: DictAny, Any + def __init__(self, *args: Any, **kw: Any) -> None: + self._yaml: DictAny, Any = dict(t=False, tz=None, delta=0) - def __new__(cls, *args, **kw): # datetime is immutable - # type: (Any, Any) -> Any + def __new__(cls, *args: Any, **kw: Any) -> Any: # datetime is immutable return datetime.datetime.__new__(cls, *args, **kw) - def __deepcopy__(self, memo): - # type: (Any) -> Any + def __deepcopy__(self, memo: Any) -> Any: ts = TimeStamp(self.year, self.month, self.day, self.hour, self.minute, self.second) ts._yaml = copy.deepcopy(self._yaml) return ts def replace( self, - year=None, - month=None, - day=None, - hour=None, - minute=None, - second=None, - microsecond=None, - tzinfo=True, - fold=None, - ): - # type: (Any, Any, Any, Any, Any, Any, Any, Any, Any) -> Any + year: Any = None, + month: Any = None, + day: Any = None, + hour: Any = None, + minute: Any = None, + second: Any = None, + microsecond: Any = None, + tzinfo: Any = True, + fold: Any = None, + ) -> Any: if year is None: year = self.year if month is None:
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/tokens.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/tokens.py
Changed
@@ -1,10 +1,9 @@ # coding: utf-8 -from ruamel.yaml.compat import _F, nprintf # NOQA +from ruamel.yaml.compat import nprintf # NOQA -if False: # MYPY - from typing import Text, Any, Dict, Optional, List # NOQA - from .error import StreamMark # NOQA +from typing import Text, Any, Dict, Optional, List # NOQA +from .error import StreamMark # NOQA SHOW_LINES = True @@ -12,23 +11,19 @@ class Token: __slots__ = 'start_mark', 'end_mark', '_comment' - def __init__(self, start_mark, end_mark): - # type: (StreamMark, StreamMark) -> None + def __init__(self, start_mark: StreamMark, end_mark: StreamMark) -> None: self.start_mark = start_mark self.end_mark = end_mark - def __repr__(self): - # type: () -> Any + def __repr__(self) -> Any: # attributes = key for key in self.__slots__ if not key.endswith('_mark') and # hasattr('self', key) attributes = key for key in self.__slots__ if not key.endswith('_mark') attributes.sort() # arguments = ', '.join( - # _F('{key!s}={gattr!r})', key=key, gattr=getattr(self, key)) for key in attributes + # f'{key!s}={getattr(self, key)!r})' for key in attributes # ) - arguments = - _F('{key!s}={gattr!r}', key=key, gattr=getattr(self, key)) for key in attributes - + arguments = f'{key!s}={getattr(self, key)!r}' for key in attributes if SHOW_LINES: try: arguments.append('line: ' + str(self.start_mark.line)) @@ -38,16 +33,14 @@ arguments.append('comment: ' + str(self._comment)) except: # NOQA pass - return '{}({})'.format(self.__class__.__name__, ', '.join(arguments)) + return f'{self.__class__.__name__}({", ".join(arguments)})' @property - def column(self): - # type: () -> int + def column(self) -> int: return self.start_mark.column @column.setter - def column(self, pos): - # type: (Any) -> None + def column(self, pos: Any) -> None: self.start_mark.column = pos # old style ( <= 0.17) is a TWO element list with first being the EOL @@ -61,8 +54,7 @@ # new style routines add one comment at a time # going to be deprecated in favour of add_comment_eol/post - def add_post_comment(self, comment): - # type: (Any) -> None + def add_post_comment(self, comment: Any) -> None: if not hasattr(self, '_comment'): self._comment = None, None else: @@ -73,8 +65,7 @@ self._comment0 = comment # going to be deprecated in favour of add_comment_pre - def add_pre_comments(self, comments): - # type: (Any) -> None + def add_pre_comments(self, comments: Any) -> None: if not hasattr(self, '_comment'): self._comment = None, None else: @@ -84,8 +75,7 @@ return # new style - def add_comment_pre(self, comment): - # type: (Any) -> None + def add_comment_pre(self, comment: Any) -> None: if not hasattr(self, '_comment'): self._comment = , None, None # type: ignore else: @@ -94,8 +84,7 @@ self._comment0 = # type: ignore self._comment0.append(comment) # type: ignore - def add_comment_eol(self, comment, comment_type): - # type: (Any, Any) -> None + def add_comment_eol(self, comment: Any, comment_type: Any) -> None: if not hasattr(self, '_comment'): self._comment = None, None, None else: @@ -107,8 +96,7 @@ # nprintf('commy', self.comment, comment_type) self._comment1comment_type = comment # type: ignore - def add_comment_post(self, comment): - # type: (Any) -> None + def add_comment_post(self, comment: Any) -> None: if not hasattr(self, '_comment'): self._comment = None, None, # type: ignore else: @@ -117,17 +105,14 @@ self._comment2 = # type: ignore self._comment2.append(comment) # type: ignore - # def get_comment(self): - # # type: () -> Any + # def get_comment(self) -> Any: # return getattr(self, '_comment', None) @property - def comment(self): - # type: () -> Any + def comment(self) -> Any: return getattr(self, '_comment', None) - def move_old_comment(self, target, empty=False): - # type: (Any, bool) -> Any + def move_old_comment(self, target: Any, empty: bool = False) -> Any: """move a comment from this token to target (normally next token) used to combine e.g. comments before a BlockEntryToken to the ScalarToken that follows it @@ -149,15 +134,14 @@ # nprint('mco2:', self, target, target.comment, empty) return self if c0 and tc0 or c1 and tc1: - raise NotImplementedError(_F('overlap in comment {c!r} {tc!r}', c=c, tc=tc)) + raise NotImplementedError(f'overlap in comment {c!r} {tc!r}') if c0: tc0 = c0 if c1: tc1 = c1 return self - def split_old_comment(self): - # type: () -> Any + def split_old_comment(self) -> Any: """ split the post part of a comment, and return it as comment to be added. Delete second part if None, None abc: # this goes to sequence @@ -172,8 +156,7 @@ delattr(self, '_comment') return ret_val - def move_new_comment(self, target, empty=False): - # type: (Any, bool) -> Any + def move_new_comment(self, target: Any, empty: bool = False) -> Any: """move a comment from this token to target (normally next token) used to combine e.g. comments before a BlockEntryToken to the ScalarToken that follows it @@ -197,7 +180,7 @@ # if self and target have both pre, eol or post comments, something seems wrong for idx in range(3): if cidx is not None and tcidx is not None: - raise NotImplementedError(_F('overlap in comment {c!r} {tc!r}', c=c, tc=tc)) + raise NotImplementedError(f'overlap in comment {c!r} {tc!r}') # move the comment parts for idx in range(3): if cidx: @@ -213,8 +196,7 @@ __slots__ = 'name', 'value' id = '<directive>' - def __init__(self, name, value, start_mark, end_mark): - # type: (Any, Any, Any, Any) -> None + def __init__(self, name: Any, value: Any, start_mark: Any, end_mark: Any) -> None: Token.__init__(self, start_mark, end_mark) self.name = name self.value = value @@ -234,8 +216,9 @@ __slots__ = ('encoding',) id = '<stream start>' - def __init__(self, start_mark=None, end_mark=None, encoding=None): - # type: (Any, Any, Any) -> None + def __init__( + self, start_mark: Any = None, end_mark: Any = None, encoding: Any = None + ) -> None: Token.__init__(self, start_mark, end_mark) self.encoding = encoding @@ -284,9 +267,8 @@ __slots__ = () id = '?' - # def x__repr__(self): - # return 'KeyToken({})'.format( - # self.start_mark.bufferself.start_mark.index:.split(None, 1)0) +# def x__repr__(self):
View file
_service:tar_scm:ruamel.yaml-0.17.21.tar.gz/util.py -> _service:tar_scm:ruamel.yaml-0.17.32.tar.gz/util.py
Changed
@@ -9,9 +9,8 @@ import re -if False: # MYPY - from typing import Any, Dict, Optional, List, Text # NOQA - from .compat import StreamTextType # NOQA +from typing import Any, Dict, Optional, List, Text, Callable, Union # NOQA +from .compat import StreamTextType # NOQA class LazyEval: @@ -25,25 +24,21 @@ return value (or, prior to evaluation, func and arguments), in its closure. """ - def __init__(self, func, *args, **kwargs): - # type: (Any, Any, Any) -> None - def lazy_self(): - # type: () -> Any + def __init__(self, func: Callable..., Any, *args: Any, **kwargs: Any) -> None: + def lazy_self() -> Any: return_value = func(*args, **kwargs) object.__setattr__(self, 'lazy_self', lambda: return_value) return return_value object.__setattr__(self, 'lazy_self', lazy_self) - def __getattribute__(self, name): - # type: (Any) -> Any + def __getattribute__(self, name: str) -> Any: lazy_self = object.__getattribute__(self, 'lazy_self') if name == 'lazy_self': return lazy_self return getattr(lazy_self(), name) - def __setattr__(self, name, value): - # type: (Any, Any) -> None + def __setattr__(self, name: str, value: Any) -> None: setattr(self.lazy_self(), name, value) @@ -65,9 +60,19 @@ def create_timestamp( - year, month, day, t, hour, minute, second, fraction, tz, tz_sign, tz_hour, tz_minute -): - # type: (Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any) -> Any + year: Any, + month: Any, + day: Any, + t: Any, + hour: Any, + minute: Any, + second: Any, + fraction: Any, + tz: Any, + tz_sign: Any, + tz_hour: Any, + tz_minute: Any, +) -> Uniondatetime.datetime, datetime.date: # create a timestamp from match against timestamp_regexp MAX_FRAC = 999999 year = int(year) @@ -122,8 +127,7 @@ # if you use this in your code, I suggest adding a test in your test suite # that check this routines output against a known piece of your YAML # before upgrades to this code break your round-tripped YAML -def load_yaml_guess_indent(stream, **kw): - # type: (StreamTextType, Any) -> Any +def load_yaml_guess_indent(stream: StreamTextType, **kw: Any) -> Any: """guess the indent and block sequence indent of yaml stream/string returns round_trip_loaded stream, indent level, block sequence indent @@ -134,15 +138,14 @@ from .main import YAML # load a YAML document, guess the indentation, if you use TABs you are on your own - def leading_spaces(line): - # type: (Any) -> int + def leading_spaces(line: Any) -> int: idx = 0 while idx < len(line) and lineidx == ' ': idx += 1 return idx if isinstance(stream, str): - yaml_str = stream # type: Any + yaml_str: Any = stream elif isinstance(stream, bytes): # most likely, but the Reader checks BOM for this yaml_str = stream.decode('utf-8') @@ -183,11 +186,10 @@ if indent is None and map_indent is not None: indent = map_indent yaml = YAML() - return yaml.load(yaml_str, **kw), indent, block_seq_indent # type: ignore + return yaml.load(yaml_str, **kw), indent, block_seq_indent -def configobj_walker(cfg): - # type: (Any) -> Any +def configobj_walker(cfg: Any) -> Any: """ walks over a ConfigObj (INI file with comments) generating corresponding YAML output (including comments @@ -206,8 +208,7 @@ yield c -def _walk_section(s, level=0): - # type: (Any, int) -> Any +def _walk_section(s: Any, level: int = 0) -> Any: from configobj import Section assert isinstance(s, Section) @@ -221,7 +222,7 @@ x = '|\n' + i + x.strip().replace('\n', '\n' + i) elif ':' in x: x = "'" + x.replace("'", "''") + "'" - line = '{0}{1}: {2}'.format(indent, name, x) + line = f'{indent}{name}: {x}' c = s.inline_commentsname if c: line += ' ' + c @@ -229,7 +230,7 @@ for name in s.sections: for c in s.commentsname: yield indent + c.strip() - line = '{0}{1}:'.format(indent, name) + line = f'{indent}{name}:' c = s.inline_commentsname if c: line += ' ' + c
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2