[Reproducible-commits] [diffoscope] 04/05: Handle closing stdin for Command implementing feed_stdin
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Sep 24 09:38:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 29caab875bb4ad68d002b5470b5303a7b5be9eb8
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Sep 24 09:27:41 2015 +0000
Handle closing stdin for Command implementing feed_stdin
Let's not duplicate the same code in every class implementing feed_stdin.
---
diffoscope/comparators/png.py | 9 +++------
diffoscope/comparators/utils.py | 12 +++++++++---
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/diffoscope/comparators/png.py b/diffoscope/comparators/png.py
index 1eceacd..845441e 100644
--- a/diffoscope/comparators/png.py
+++ b/diffoscope/comparators/png.py
@@ -31,12 +31,9 @@ class Sng(Command):
return ['sng']
def feed_stdin(self, stdin):
- try:
- with open(self.path, 'rb') as f:
- for buf in iter(partial(f.read, 32768), b''):
- stdin.write(buf)
- finally:
- stdin.close()
+ with open(self.path, 'rb') as f:
+ for buf in iter(partial(f.read, 32768), b''):
+ stdin.write(buf)
class PngFile(File):
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 2cff408..6b586bc 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -62,7 +62,7 @@ class Command(object, metaclass=ABCMeta):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if hasattr(self, 'feed_stdin'):
- self._stdin_feeder = Thread(target=self.feed_stdin, args=(self._process.stdin,))
+ self._stdin_feeder = Thread(target=self._feed_stdin, args=(self._process.stdin,))
self._stdin_feeder.daemon = True
self._stdin_feeder.start()
else:
@@ -82,8 +82,14 @@ class Command(object, metaclass=ABCMeta):
def cmdline(self):
raise NotImplemented
- # Define only if needed
- #def feed_stdin(self, f)
+ # Define only if needed. We take care of closing stdin.
+ #def feed_stdin(self, stdin)
+
+ def _feed_stdin(self, stdin):
+ try:
+ self.feed_stdin(stdin)
+ finally:
+ stdin.close()
def filter(self, line):
# Assume command output is utf-8 by default
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list