Skip to main content

Node tree implementation for yaml files

Project description

Latest PyPI version Number of PyPI downloads

node.ext.yaml provides a node implementation to yaml files.

For more information on nodes see node package.

For more information on plumbing see plumber package.

Usage

Create a yaml file:

from node.ext.yaml import YamlFile

class MyYamlFile(YamlFile):

    @property
    def fs_path(self):
        return '/path/to/file.yaml'

file = MyYamlFile()
file['child'] = 'Value'

# write file to disk
file()

Define factories for child nodes:

from node.ext.yaml import YamlNode

class SpecificChild(YamlNode):
    pass

class DefaultChild(YamlNode):
    pass

class MyYamlFile(YamlFile):
    factories = {
        'child': SpecificChild,
        '*': DefaultChild
    }

Define a schema for node members:

from node import schema
from node.behaviors import SchemaAsAttributes
from plumber import plumbing

@plumbing(SchemaAsAttributes)
class MyYamlFile(YamlFile):
    schema = {
        'int_member': schema.Int(),
        'str_member': schema.Str()
    }

file = MyYamlFile()
file.attr['int_member'] = 1
file.attr['str_member'] = u'String'

Schema members can be defined directly on class.

Note: Be careful not to override existing API members.

from node.behaviors import SchemaProperties

@plumbing(SchemaProperties)
class MyYamlFile(YamlFile):
    int_member = schema.Int()
    str_member = schema.Str()

file = MyYamlFile()
file.int_member = 1
file.str_member = u'String'

Python Versions

  • Python 2.7, 3.3+

Contributors

  • Robert Niederreiter

Changes

0.2 (2022-10-06)

  • Inherit YamlRootStorage from node.ext.fs.FSLocation, which provides fs_path property. Note that fs_path is handled as list now. [rnix]

  • Inherit IYamlRoot from node.ext.fs.interfaces.IFile. [rnix]

  • Package depends on node.ext.fs now. [rnix]

  • Replace deprecated use of Adopt by MappingAdopt. [rnix]

  • node.ext.yaml.YamlNode and node.ext.yaml.YamlFile not provides a default child factory any more. [rnix]

0.1 (2021-11-22)

  • Initial work [rnix]

License

Copyright (c) 2021-2022, Node Contributors All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

node.ext.yaml-0.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

node.ext.yaml-0.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file node.ext.yaml-0.2.tar.gz.

File metadata

  • Download URL: node.ext.yaml-0.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.3

File hashes

Hashes for node.ext.yaml-0.2.tar.gz
Algorithm Hash digest
SHA256 3c503964364820638051450216fabdebe13bd1242d031710dc29fe4b15a2da2e
MD5 6a9f0d0c2c5ae17f9ffefa48e1ba645e
BLAKE2b-256 d87563ec644f2440914b2a46badb5b17fae78a350a3e12ecf6faa3471c4f7da3

See more details on using hashes here.

File details

Details for the file node.ext.yaml-0.2-py3-none-any.whl.

File metadata

  • Download URL: node.ext.yaml-0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.3

File hashes

Hashes for node.ext.yaml-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 70c949245f2f274fc7375a2dc12c3593595a4c88c95cc21f9b6be40680d5cbc2
MD5 3e0d305962a2f3fc42cf18a462a701fd
BLAKE2b-256 330a35e92db441a45139ffc0d42c8b681fcd9b0f4d6a087107cf6b4680c06f10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page