diff options
Diffstat (limited to 'qtip/loader/yaml_file.py')
-rw-r--r-- | qtip/loader/yaml_file.py | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/qtip/loader/yaml_file.py b/qtip/loader/yaml_file.py index f1cd4614..8b78a47c 100644 --- a/qtip/loader/yaml_file.py +++ b/qtip/loader/yaml_file.py @@ -7,11 +7,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from collections import defaultdict from os import path import yaml -from qtip.base.error import InvalidFormat +from qtip.base.error import InvalidContent from qtip.base.constant import BaseProp from qtip.loader.file import FileLoader @@ -21,13 +20,11 @@ class YamlFileLoader(FileLoader): def __init__(self, name, paths=None): super(YamlFileLoader, self).__init__(name, paths) - content = defaultdict(lambda: None) + abspath = self.abspath - try: - content.update(yaml.safe_load(file(self._abspath))) - except yaml.YAMLError: - # TODO(yujunz) log yaml error - raise InvalidFormat(self._abspath) - - self.name = content[BaseProp.NAME] or path.splitext(name)[0] - self.content = content + with open(abspath, 'r') as stream: + content = yaml.safe_load(stream) + if not isinstance(content, dict): + raise InvalidContent(abspath) + self.content = content + self.name = content.get(BaseProp.NAME, path.splitext(name)[0]) |