changeset 402:f03688bdb858

jp: use with statement to open fifo
author Goffi <goffi@goffi.org>
date Fri, 07 Oct 2011 11:19:15 +0200
parents b2caa2615c4c
children c513328ade9d
files frontends/src/jp/jp
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 <http://www.gnu.org/licenses/>.
 """
 
+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()