# HG changeset patch # User Dmitry Selyutin # Date 1530365402 -10800 # Node ID 7025642fe93e7866153b5cd0e836cad5d6f3a57b # Parent cb906289b04e92d40a5349260495c25ab017a68a vfs: simplify some code parts diff -r cb906289b04e -r 7025642fe93e pygnulib/vfs.py --- a/pygnulib/vfs.py Fri Jun 29 10:05:31 2018 +0300 +++ b/pygnulib/vfs.py Sat Jun 30 16:30:02 2018 +0300 @@ -127,21 +127,21 @@ diff = f"{name}.diff" if diff not in secondary: return (primary, name) - tmp = _tempfile.NamedTemporaryFile(mode="w+b", delete=False) - with _codecs.open(primary[name], "rb") as stream: - _shutil.copyfileobj(stream, tmp) - tmp.close() + with _codecs.open(primary[name], "rb") as istream: + with _tempfile.NamedTemporaryFile(mode="w+b", delete=False) as ostream: + path = ostream.name + _shutil.copyfileobj(istream, ostream) stdin = _codecs.open(secondary[diff], "rb") - cmd = (patch, "-s", tmp.name) + cmd = (patch, "-s", path) pipes = _sp.Popen(cmd, stdin=stdin, stdout=_sp.PIPE, stderr=_sp.PIPE) (stdout, stderr) = pipes.communicate() stdout = stdout.decode("UTF-8") stderr = stderr.decode("UTF-8") returncode = pipes.returncode if returncode != 0: - cmd = "patch -s {} < {}".format(tmp.name, secondary[diff]) + cmd = "patch -s {} < {}".format(path, secondary[diff]) raise _sp.CalledProcessError(returncode, cmd, stdout, stderr) - return (None, tmp.name) + return (None, path) def mkdir(root, name): @@ -192,10 +192,9 @@ dst_path = _os.path.join(dst_root.root, dst_root[dst_name]) with _codecs.open(src_path, "rb") as istream: with _codecs.open(dst_path, "wb") as ostream: - while 1: + data = True + while data: data = istream.read(limit) - if not data: - break ostream.write(data)