Commit 0d599fdf authored by Lukas Brabec's avatar Lukas Brabec Committed by Matěj Cepl

faster source handling in load()

parent 98fb1139
......@@ -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:
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'
except UnicodeDecodeError:
log.debug('in ignore_wrong_characters = %s',
if ignore_wrong_characters:
inobj += line.decode('utf8', 'ignore') + '\n'
inobj.append(line.decode('utf8', 'ignore'))
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment