From 0d599fdf1f275adbb7b8b90292064628a4e020c2 Mon Sep 17 00:00:00 2001 From: Lukas Brabec Date: Wed, 18 Mar 2015 13:11:59 +0100 Subject: faster source handling in load() --- yamlish.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yamlish.py b/yamlish.py index bb616bc..98ead64 100644 --- a/yamlish.py +++ b/yamlish.py @@ -203,23 +203,23 @@ def load(source, ignore_wrong_characters=False): out = yaml.load(source, Loader=_YamlishLoader) log.debug("out (string) = %s", out) elif hasattr(source, "__iter__"): - inobj = u"" + inobj = [] for line in source: try: if not py3k or isinstance(line, bytes): line = line.decode('utf8') logging.debug('inobj, line ... %s, %s', type(inobj), type(line)) - inobj += line + u'\n' + inobj.append(line) except UnicodeDecodeError: log.debug('in ignore_wrong_characters = %s', ignore_wrong_characters) if ignore_wrong_characters: - inobj += line.decode('utf8', 'ignore') + '\n' + inobj.append(line.decode('utf8', 'ignore')) else: raise log.debug('restarting load with inobj as string') - out = load(inobj, ignore_wrong_characters) + out = load('\n'.join(inobj), ignore_wrong_characters) log.debug("out (iter) = %s", out) log.debug("out (iter) = type %s", type(out)) return out -- cgit