File: yaml_handler.py

package info (click to toggle)
python-kaptan 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: python: 542; sh: 7; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf8 -*-
"""
    kaptan.handlers.yaml_handler
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: (c) 2013 by the authors and contributors (See AUTHORS file).
    :license: BSD, see LICENSE for more details.
"""

from __future__ import print_function, unicode_literals

import yaml

from . import BaseHandler


class YamlHandler(BaseHandler):

    def load(self, data, safe=True):
        if safe:
            func = yaml.safe_load
        else:
            func = yaml.load
        return func(data)

    def dump(self, data, safe=True, **kwargs):
        if safe:
            func = yaml.safe_dump
        else:
            func = yaml.dump
        return func(data, **kwargs)