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): ...@@ -203,23 +203,23 @@ def load(source, ignore_wrong_characters=False):
out = yaml.load(source, Loader=_YamlishLoader) out = yaml.load(source, Loader=_YamlishLoader)
log.debug("out (string) = %s", out) log.debug("out (string) = %s", out)
elif hasattr(source, "__iter__"): elif hasattr(source, "__iter__"):
inobj = u"" inobj = []
for line in source: for line in source:
try: try:
if not py3k or isinstance(line, bytes): if not py3k or isinstance(line, bytes):
line = line.decode('utf8') line = line.decode('utf8')
logging.debug('inobj, line ... %s, %s', logging.debug('inobj, line ... %s, %s',
type(inobj), type(line)) type(inobj), type(line))
inobj += line + u'\n' inobj.append(line)
except UnicodeDecodeError: except UnicodeDecodeError:
log.debug('in ignore_wrong_characters = %s', log.debug('in ignore_wrong_characters = %s',
ignore_wrong_characters) ignore_wrong_characters)
if ignore_wrong_characters: if ignore_wrong_characters:
inobj += line.decode('utf8', 'ignore') + '\n' inobj.append(line.decode('utf8', 'ignore'))
else: else:
raise raise
log.debug('restarting load with inobj as string') 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) = %s", out)
log.debug("out (iter) = type %s", type(out)) log.debug("out (iter) = type %s", type(out))
return 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