diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | README.rst | 7 | ||||
-rw-r--r-- | __init__.py | 4 | ||||
-rw-r--r-- | _doc/_static/pypi.svg | 2 | ||||
-rw-r--r-- | anchor.py | 4 | ||||
-rw-r--r-- | main.py | 60 | ||||
-rw-r--r-- | setup.py | 5 |
7 files changed, 52 insertions, 33 deletions
@@ -1,3 +1,6 @@ +[0, 16, 5]: 2019-08-18 + - allow for ``YAML(typ=['unsafe', 'pytypes'])`` + [0, 16, 4]: 2019-08-16 - fix output of TAG directives with # (reported by `Thomas Smith <https://bitbucket.org/%7Bd4c57a72-f041-4843-8217-b4d48b6ece2f%7D/>`__) @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.16.4 -:updated: 2019-08-16 +:version: 0.16.5 +:updated: 2019-08-18 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/yaml :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,9 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.16.5 (2019-08-18): + - allow for ``YAML(typ=['unsafe', 'pytypes'])`` + 0.16.4 (2019-08-16): - fix output of TAG directives with # (reported by `Thomas Smith <https://bitbucket.org/%7Bd4c57a72-f041-4843-8217-b4d48b6ece2f%7D/>`__) diff --git a/__init__.py b/__init__.py index a04077d..74a042d 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 16, 4), - __version__='0.16.4', + version_info=(0, 16, 5), + __version__='0.16.5', author='Anthon van der Neut', author_email='a.van.der.neut@ruamel.eu', description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index 4b1b796..876b664 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.16.4</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.16.4</text></g> </svg> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.16.5</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.16.5</text></g> </svg> @@ -11,3 +11,7 @@ class Anchor(object): # type: () -> None self.value = None self.always_dump = False + + def __repr__(self): + ad = ", (always dump)" if self.always_dump else "" + return "Anchor({!r}{})".format(self.value, ad) @@ -78,7 +78,7 @@ class YAML(object): 'one was given ({!r})'.format(self.__class__.__name__, _kw) ) - self.typ = 'rt' if typ is None else typ + self.typ = ['rt'] if typ is None else (typ if isinstance(typ, list) else [typ]) self.pure = pure # self._input = input @@ -95,18 +95,11 @@ class YAML(object): self.Scanner = None # type: Any self.Serializer = None # type: Any self.default_flow_style = None # type: Any - if self.typ == 'rt': - self.default_flow_style = False - # no optimized rt-dumper yet - self.Emitter = ruamel.yaml.emitter.Emitter # type: Any - self.Serializer = ruamel.yaml.serializer.Serializer - self.Representer = ruamel.yaml.representer.RoundTripRepresenter # type: Any - self.Scanner = ruamel.yaml.scanner.RoundTripScanner - # no optimized rt-parser yet - self.Parser = ruamel.yaml.parser.RoundTripParser # type: Any - self.Composer = ruamel.yaml.composer.Composer # type: Any - self.Constructor = ruamel.yaml.constructor.RoundTripConstructor # type: Any - elif self.typ == 'safe': + typ_found = 1 + setup_rt = False + if 'rt' in self.typ: + setup_rt = True + elif 'safe' in self.typ: self.Emitter = ( ruamel.yaml.emitter.Emitter if pure or CEmitter is None else CEmitter ) @@ -114,13 +107,13 @@ class YAML(object): self.Parser = ruamel.yaml.parser.Parser if pure or CParser is None else CParser self.Composer = ruamel.yaml.composer.Composer self.Constructor = ruamel.yaml.constructor.SafeConstructor - elif self.typ == 'base': + elif 'base' in self.typ: self.Emitter = ruamel.yaml.emitter.Emitter self.Representer = ruamel.yaml.representer.BaseRepresenter self.Parser = ruamel.yaml.parser.Parser if pure or CParser is None else CParser self.Composer = ruamel.yaml.composer.Composer self.Constructor = ruamel.yaml.constructor.BaseConstructor - elif self.typ == 'unsafe': + elif 'unsafe' in self.typ: self.Emitter = ( ruamel.yaml.emitter.Emitter if pure or CEmitter is None else CEmitter ) @@ -129,14 +122,20 @@ class YAML(object): self.Composer = ruamel.yaml.composer.Composer self.Constructor = ruamel.yaml.constructor.Constructor else: - for module in self.plug_ins: - if getattr(module, 'typ', None) == self.typ: - module.init_typ(self) - break - else: - raise NotImplementedError( - 'typ "{}"not recognised (need to install plug-in?)'.format(self.typ) - ) + setup_rt = True + typ_found = 0 + if setup_rt: + self.default_flow_style = False + # no optimized rt-dumper yet + self.Emitter = ruamel.yaml.emitter.Emitter # type: Any + self.Serializer = ruamel.yaml.serializer.Serializer + self.Representer = ruamel.yaml.representer.RoundTripRepresenter # type: Any + self.Scanner = ruamel.yaml.scanner.RoundTripScanner + # no optimized rt-parser yet + self.Parser = ruamel.yaml.parser.RoundTripParser # type: Any + self.Composer = ruamel.yaml.composer.Composer # type: Any + self.Constructor = ruamel.yaml.constructor.RoundTripConstructor # type: Any + del setup_rt self.stream = None self.canonical = None self.old_indent = None @@ -165,6 +164,15 @@ class YAML(object): self.scalar_after_indicator = 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: + if getattr(module, 'typ', None) in self.typ: + typ_found += 1 + module.init_typ(self) + break + if typ_found == 0: + raise NotImplementedError( + 'typ "{}"not recognised (need to install plug-in?)'.format(self.typ) + ) @property def reader(self): @@ -535,7 +543,7 @@ class YAML(object): rslvr = ( ruamel.yaml.resolver.BaseResolver - if self.typ == 'base' + if 'base' in self.typ else ruamel.yaml.resolver.Resolver ) @@ -601,7 +609,7 @@ class YAML(object): # basic types def map(self, **kw): # type: (Any) -> Any - if self.typ == 'rt': + if 'rt' in self.typ: from ruamel.yaml.comments import CommentedMap return CommentedMap(**kw) @@ -610,7 +618,7 @@ class YAML(object): def seq(self, *args): # type: (Any) -> Any - if self.typ == 'rt': + if 'rt' in self.typ: from ruamel.yaml.comments import CommentedSeq return CommentedSeq(*args) @@ -23,8 +23,9 @@ from setuptools.command.sdist import sdist as _sdist # NOQA try: from setuptools.namespaces import Installer as NameSpaceInstaller # NOQA except ImportError: - print("You should use the latest setuptools. The namespaces.py file that this setup.py" - " uses was added in setuptools 28.7.0 (Oct 2016)") + 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__': |