factotum: use try/except/finally
authorMatt Mackall <mpm@selenic.com>
Fri, 15 May 2015 09:54:56 -0500
changeset 25078 e8348f1cc228
parent 25077 68633ff2b608
child 25079 bee00e0c2e45
factotum: use try/except/finally
hgext/factotum.py
--- a/hgext/factotum.py	Fri May 15 09:54:35 2015 -0500
+++ b/hgext/factotum.py	Fri May 15 09:54:56 2015 -0500
@@ -67,21 +67,20 @@
     while True:
         fd = os.open('%s/rpc' % _mountpoint, os.O_RDWR)
         try:
-            try:
-                os.write(fd, 'start %s' % params)
-                l = os.read(fd, ERRMAX).split()
-                if l[0] == 'ok':
-                    os.write(fd, 'read')
-                    status, user, passwd = os.read(fd, ERRMAX).split(None, 2)
-                    if status == 'ok':
-                        if passwd.startswith("'"):
-                            if passwd.endswith("'"):
-                                passwd = passwd[1:-1].replace("''", "'")
-                            else:
-                                raise util.Abort(_('malformed password string'))
-                        return (user, passwd)
-            except (OSError, IOError):
-                raise util.Abort(_('factotum not responding'))
+            os.write(fd, 'start %s' % params)
+            l = os.read(fd, ERRMAX).split()
+            if l[0] == 'ok':
+                os.write(fd, 'read')
+                status, user, passwd = os.read(fd, ERRMAX).split(None, 2)
+                if status == 'ok':
+                    if passwd.startswith("'"):
+                        if passwd.endswith("'"):
+                            passwd = passwd[1:-1].replace("''", "'")
+                        else:
+                            raise util.Abort(_('malformed password string'))
+                    return (user, passwd)
+        except (OSError, IOError):
+            raise util.Abort(_('factotum not responding'))
         finally:
             os.close(fd)
         getkey(self, params)