How to use the shyaml.ShyamlSafeLoader function in shyaml

To help you get started, we’ve selected a few shyaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0k / shyaml / shyaml.py View on Github external
def do(stream, action, key, default=None, dump=yaml_dump,
       loader=ShyamlSafeLoader):
    """Return string representations of target value in stream YAML

    The key is used for traversal of the YAML structure to target
    the value that will be dumped.

    :param stream:  file like input yaml content
    :param action:  string identifying one of the possible supported actions
    :param key:     string dotted expression to traverse yaml input
    :param default: optional default value in case of missing end value when
                    traversing input yaml.  (default is ``None``)
    :param dump:    callable that will be given python objet to dump in yaml
                    (default is ``yaml_dump``)
    :param loader:  PyYAML's *Loader subclass to parse YAML
                    (default is ShyamlSafeLoader)
    :return:        generator of string representation of target value per
                    YAML docs in the given stream.
github 0k / shyaml / shyaml.py View on Github external
class ForcedLineStream(object):

    def __init__(self, fileobj):
        self._file = fileobj

    def read(self, size=-1):
        ## don't care about size
        return self._file.readline()

    def close(self):
        ## XXXvlab: for some reason, ``.close(..)`` doesn't seem to
        ## be used by any code. I'll keep this to avoid any bad surprise.
        return self._file.close()  ## pragma: no cover


class LineLoader(ShyamlSafeLoader):
    """Forcing stream in line buffer mode"""

    def __init__(self, stream):
        stream = ForcedLineStream(stream)
        super(LineLoader, self).__init__(stream)


##
## Keep previous order in YAML
##

try:
    ## included in standard lib from Python 2.7
    from collections import OrderedDict
except ImportError:  ## pragma: no cover
    ## try importing the backported drop-in replacement