# HG changeset patch # User Goffi # Date 1317979155 -7200 # Node ID f03688bdb85863c20c34686669695af51edc4d68 # Parent b2caa2615c4cf81ad00174ad255a57cfc89689a2 jp: use with statement to open fifo diff -r b2caa2615c4c -r f03688bdb858 frontends/src/jp/jp --- a/frontends/src/jp/jp Fri Oct 07 00:25:15 2011 +0200 +++ b/frontends/src/jp/jp Fri Oct 07 11:19:15 2011 +0200 @@ -19,6 +19,8 @@ along with this program. If not, see . """ +from __future__ import with_statement + #consts name = u"jp" about = name+u""" v%s (c) Jérôme Poisson (aka Goffi) 2009, 2010, 2011 @@ -210,9 +212,8 @@ fifopath = os.path.join(tmp_dir,"pipe_out") os.mkfifo(fifopath) self.bridge.pipeOut(self._getFullJid(self.dest_jid), fifopath, {}, profile_key=self.profile) - f = open(fifopath, 'w+') - shutil.copyfileobj(sys.stdin, f) - f.close() + with open(fifopath, 'w') as f: + shutil.copyfileobj(sys.stdin, f) shutil.rmtree(tmp_dir) @@ -296,9 +297,8 @@ answer_data["dest_path"] = fifopath os.mkfifo(fifopath) self.bridge.confirmationAnswer(id, True, answer_data) - f = open(fifopath, 'r') - shutil.copyfileobj(f, sys.stdout) - f.close() + with open(fifopath, 'r') as f: + shutil.copyfileobj(f, sys.stdout) shutil.rmtree(tmp_dir) self.loop.quit()