Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:jayvdb:py-new
python-oyaml
oyaml-1.0.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File oyaml-1.0.obscpio of Package python-oyaml
07070100000000000081A40000000000000000000000015F3B5A9B0000025C000000000000000000000000000000000000001600000000oyaml-1.0/.travis.ymllanguage: python sudo: false python: - "2.7" - "3.5" - "3.6" - "3.7" - "3.8" - "nightly" - "pypy" - "pypy3" env: - PYYAML_VERSION="3.13" # - PYYAML_VERSION="4.1" # this was pulled from the index (!) ..wtf, Ingy? - PYYAML_VERSION="4.2b4" - PYYAML_VERSION="5.3" matrix: fast_finish: true allow_failures: - python: "nightly" install: - pip install pyyaml~=$PYYAML_VERSION - pip install --editable . - pip install pytest-cov coveralls script: - pip freeze - pytest --cov=oyaml after_success: - coverage combine - coveralls notifications: email: false 07070100000001000081A40000000000000000000000015F3B5A9B0000042A000000000000000000000000000000000000001200000000oyaml-1.0/LICENSEMIT License Copyright (c) 2018 wim glenn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 07070100000002000081A40000000000000000000000015F3B5A9B00000010000000000000000000000000000000000000001600000000oyaml-1.0/MANIFEST.ininclude LICENSE 07070100000003000081A40000000000000000000000015F3B5A9B00000388000000000000000000000000000000000000001500000000oyaml-1.0/README.rst|travis|_ |coveralls|_ |pypi|_ |womm|_ .. |travis| image:: https://img.shields.io/travis/wimglenn/oyaml.svg?branch=master .. _travis: https://travis-ci.org/wimglenn/oyaml .. |coveralls| image:: https://img.shields.io/coveralls/wimglenn/oyaml.svg .. _coveralls: https://coveralls.io/github/wimglenn/oyaml?branch=master .. |pypi| image:: https://img.shields.io/pypi/v/oyaml.svg .. _pypi: https://pypi.org/project/oyaml .. |womm| image:: https://cdn.rawgit.com/nikku/works-on-my-machine/v0.2.0/badge.svg .. _womm: https://github.com/nikku/works-on-my-machine oyaml ===== oyaml is a drop-in replacement for `PyYAML <http://pyyaml.org/wiki/PyYAML>`_ which preserves dict ordering. Both Python 2 and Python 3 are supported. Just ``pip install oyaml``, and import as shown below: .. code-block:: python import oyaml as yaml You'll no longer be annoyed by screwed-up mappings when dumping/loading. 07070100000004000081A40000000000000000000000015F3B5A9B00000618000000000000000000000000000000000000001300000000oyaml-1.0/oyaml.pyimport platform import sys from collections import OrderedDict import yaml as pyyaml _items = "viewitems" if sys.version_info < (3,) else "items" _std_dict_is_order_preserving = sys.version_info >= (3, 7) or ( sys.version_info >= (3, 6) and platform.python_implementation() == "CPython" ) def map_representer(dumper, data): return dumper.represent_dict(getattr(data, _items)()) def map_constructor(loader, node): loader.flatten_mapping(node) pairs = loader.construct_pairs(node) try: return OrderedDict(pairs) except TypeError: loader.construct_mapping(node) # trigger any contextual error raise _loaders = [getattr(pyyaml.loader, x) for x in pyyaml.loader.__all__] _dumpers = [getattr(pyyaml.dumper, x) for x in pyyaml.dumper.__all__] try: _cyaml = pyyaml.cyaml.__all__ except AttributeError: pass else: _loaders += [getattr(pyyaml.cyaml, x) for x in _cyaml if x.endswith("Loader")] _dumpers += [getattr(pyyaml.cyaml, x) for x in _cyaml if x.endswith("Dumper")] Dumper = None for Dumper in _dumpers: pyyaml.add_representer(dict, map_representer, Dumper=Dumper) pyyaml.add_representer(OrderedDict, map_representer, Dumper=Dumper) Loader = None if not _std_dict_is_order_preserving: for Loader in _loaders: pyyaml.add_constructor("tag:yaml.org,2002:map", map_constructor, Loader=Loader) # Merge PyYAML namespace into ours. # This allows users a drop-in replacement: # import oyaml as yaml del map_constructor, map_representer, Loader, Dumper from yaml import * 07070100000005000081A40000000000000000000000015F3B5A9B0000003F000000000000000000000000000000000000001400000000oyaml-1.0/setup.cfg[bdist_wheel] universal = 1 [metadata] license_file = LICENSE 07070100000006000081A40000000000000000000000015F3B5A9B00000192000000000000000000000000000000000000001300000000oyaml-1.0/setup.pyfrom setuptools import setup setup( name="oyaml", version="1.0", description="Ordered YAML: drop-in replacement for PyYAML which preserves dict ordering", long_description=open("README.rst").read(), author="Wim Glenn", author_email="hey@wimglenn.com", url="https://github.com/wimglenn/oyaml", license="MIT", py_modules=["oyaml"], install_requires=["pyyaml"], ) 07070100000007000081A40000000000000000000000015F3B5A9B0000170F000000000000000000000000000000000000001800000000oyaml-1.0/test_oyaml.pyfrom collections import OrderedDict from types import GeneratorType import pytest from yaml.constructor import ConstructorError from yaml.representer import RepresenterError import oyaml as yaml from oyaml import _std_dict_is_order_preserving data = OrderedDict([("x", 1), ("z", 3), ("y", 2)]) def test_dump(): assert yaml.dump(data, default_flow_style=None) == "{x: 1, z: 3, y: 2}\n" def test_safe_dump(): assert yaml.safe_dump(data, default_flow_style=None) == "{x: 1, z: 3, y: 2}\n" def test_dump_all(): assert ( yaml.dump_all(documents=[data, {}], default_flow_style=None) == "{x: 1, z: 3, y: 2}\n--- {}\n" ) def test_dump_and_safe_dump_match(): mydict = {"x": 1, "z": 2, "y": 3} # don't know if mydict is ordered in the implementation or not (but don't care) assert yaml.dump(mydict) == yaml.safe_dump(mydict) def test_safe_dump_all(): assert ( yaml.safe_dump_all(documents=[data, {}], default_flow_style=None) == "{x: 1, z: 3, y: 2}\n--- {}\n" ) def test_load(): loaded = yaml.load("{x: 1, z: 3, y: 2}") assert loaded == {"x": 1, "z": 3, "y": 2} def test_safe_load(): loaded = yaml.safe_load("{x: 1, z: 3, y: 2}") assert loaded == {"x": 1, "z": 3, "y": 2} def test_load_all(): gen = yaml.load_all("{x: 1, z: 3, y: 2}\n--- {}\n") assert isinstance(gen, GeneratorType) ordered_data, empty_dict = gen assert empty_dict == {} assert ordered_data == data @pytest.mark.skipif(_std_dict_is_order_preserving, reason="requires old dict impl") def test_loads_to_ordered_dict(): loaded = yaml.load("{x: 1, z: 3, y: 2}") assert isinstance(loaded, OrderedDict) @pytest.mark.skipif(not _std_dict_is_order_preserving, reason="requires new dict impl") def test_loads_to_std_dict(): loaded = yaml.load("{x: 1, z: 3, y: 2}") assert not isinstance(loaded, OrderedDict) assert isinstance(loaded, dict) @pytest.mark.skipif(_std_dict_is_order_preserving, reason="requires old dict impl") def test_safe_loads_to_ordered_dict(): loaded = yaml.safe_load("{x: 1, z: 3, y: 2}") assert isinstance(loaded, OrderedDict) @pytest.mark.skipif(not _std_dict_is_order_preserving, reason="requires new dict impl") def test_safe_loads_to_std_dict(): loaded = yaml.safe_load("{x: 1, z: 3, y: 2}") assert not isinstance(loaded, OrderedDict) assert isinstance(loaded, dict) class MyOrderedDict(OrderedDict): pass def test_subclass_dump(): data = MyOrderedDict([("x", 1), ("y", 2)]) assert "!!python/object/apply:test_oyaml.MyOrderedDict" in yaml.dump(data) with pytest.raises(RepresenterError, match="cannot represent an object"): yaml.safe_dump(data) def test_anchors_and_references(): text = """ defaults: all: &all product: foo development: &development <<: *all profile: bar development: platform: <<: *development host: baz """ expected_load = { "defaults": { "all": {"product": "foo"}, "development": {"product": "foo", "profile": "bar"}, }, "development": { "platform": {"host": "baz", "product": "foo", "profile": "bar"} }, } assert yaml.load(text) == expected_load def test_omap(): text = """ Bestiary: !!omap - aardvark: African pig-like ant eater. Ugly. - anteater: South-American ant eater. Two species. - anaconda: South-American constrictor snake. Scaly. """ expected_load = { "Bestiary": ( [ ("aardvark", "African pig-like ant eater. Ugly."), ("anteater", "South-American ant eater. Two species."), ("anaconda", "South-American constrictor snake. Scaly."), ] ) } assert yaml.load(text) == expected_load def test_omap_flow_style(): text = "Numbers: !!omap [ one: 1, two: 2, three : 3 ]" expected_load = {"Numbers": ([("one", 1), ("two", 2), ("three", 3)])} assert yaml.load(text) == expected_load def test_merge(): text = """ - &CENTER { x: 1, y: 2 } - &LEFT { x: 0, y: 2 } - &BIG { r: 10 } - &SMALL { r: 1 } # All the following maps are equal: - # Explicit keys x: 1 y: 2 r: 10 label: center/big - # Merge one map << : *CENTER r: 10 label: center/big - # Merge multiple maps << : [ *CENTER, *BIG ] label: center/big - # Override << : [ *BIG, *LEFT, *SMALL ] x: 1 label: center/big """ data = yaml.load(text) assert len(data) == 8 center, left, big, small, map1, map2, map3, map4 = data assert center == {"x": 1, "y": 2} assert left == {"x": 0, "y": 2} assert big == {"r": 10} assert small == {"r": 1} expected = {"x": 1, "y": 2, "r": 10, "label": "center/big"} assert map1 == expected assert map2 == expected assert map3 == expected assert map4 == expected def test_unhashable_error_context(): with pytest.raises(ConstructorError, match=r".*line.*column.*"): yaml.safe_load("{foo: bar}: baz") @pytest.mark.skipif(not hasattr(yaml, "CSafeLoader"), reason="requires cyaml loaders") def test_explicit_loader(): data = yaml.load("{x: 1, z: 3, y: 2}", Loader=yaml.CSafeLoader) assert data == {"x": 1, "z": 3, "y": 2} assert list(data) == ["x", "z", "y"] @pytest.mark.skipif(not hasattr(yaml, "CSafeDumper"), reason="requires cyaml dumpers") def test_explicit_dumper(): data = OrderedDict([("x", 1), ("z", 3), ("y", 2)]) text = yaml.dump(data, Dumper=yaml.CSafeDumper, default_flow_style=None) assert text == "{x: 1, z: 3, y: 2}\n" 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!23 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor