1# -*- coding: utf-8 -*- 2# This Source Code Form is subject to the terms of the Mozilla Public 3# License, v. 2.0. If a copy of the MPL was not distributed with this 4# file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6from __future__ import absolute_import, print_function, unicode_literals 7 8from yaml.loader import SafeLoader 9 10 11class UnicodeLoader(SafeLoader): 12 def construct_yaml_str(self, node): 13 return self.construct_scalar(node) 14 15 16UnicodeLoader.add_constructor( 17 'tag:yaml.org,2002:str', 18 UnicodeLoader.construct_yaml_str) 19 20 21def load(stream): 22 """ 23 Parse the first YAML document in a stream 24 and produce the corresponding Python object. 25 """ 26 loader = UnicodeLoader(stream) 27 try: 28 return loader.get_single_data() 29 finally: 30 loader.dispose() 31