
from __future__ import print_function, unicode_literals

import yaml

from . import BaseHandler


class YamlHandler(BaseHandler):

    def load(self, data):
        return yaml.load(data)

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


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)

Make YAML handler safe by default
Make YAML handler safe by default

Fixes #43
  
  from __future__ import print_function, unicode_literals
  
  import yaml
  
  from . import BaseHandler
  
  
  class YamlHandler(BaseHandler):
  
-     def load(self, data):
+     def load(self, data, safe=True):
+         if safe:
+             func = yaml.safe_load
+         else:
+             func = yaml.load
-         return yaml.load(data)
+         return func(data)
  
-     def dump(self, data, safe=False, **kwargs):
+     def dump(self, data, safe=True, **kwargs):
-         if not safe:
+         if safe:
-             return yaml.dump(data, **kwargs)
+             func = yaml.safe_dump
          else:
+             func = yaml.dump
-             return yaml.safe_dump(data, **kwargs)
+         return func(data, **kwargs)
  
Make YAML handler safe by default
## Code Before:

from __future__ import print_function, unicode_literals

import yaml

from . import BaseHandler


class YamlHandler(BaseHandler):

    def load(self, data):
        return yaml.load(data)

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

## Instruction:
Make YAML handler safe by default
## Code After:

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)
