]> git.phdru.name Git - bookmarks_db.git/blobdiff - subproc.py
Feat(Python3): `raise Error, value` -> `raise Error(value)`
[bookmarks_db.git] / subproc.py
index f5e89c5ffc75c003e22b8335ea4bdb9d9d39d9c9..a0099c290db088a168181802ee91153ac2b920c9 100644 (file)
@@ -135,22 +135,20 @@ class Subprocess:
                 pid, err = os.waitpid(self.pid, os.WNOHANG)
             except os.error, (errno, msg):
                 if errno == 10:
-                    raise SubprocessError, \
-                          "Subprocess '%s' failed." % self.cmd
-                raise SubprocessError, \
-                      "Subprocess failed[%d]: %s" % (errno, msg)
+                    raise SubprocessError("Subprocess '%s' failed." % self.cmd)
+                raise SubprocessError("Subprocess failed[%d]: %s" % (errno, msg))
             if pid == self.pid:
                 # child exited already
                 self.pid == None
                 sig = err & 0xff
                 rc = (err & 0xff00) >> 8
                 if sig:
-                    raise SubprocessError(
+                    raise SubprocessError(
                     "child killed by signal %d with a return code of %d"
                     % (sig, rc))
                 if rc:
-                    raise SubprocessError, \
-                          "child exited with return code %d" % rc
+                    raise SubprocessError(
+                          "child exited with return code %d" % rc)
                 # Child may have exited, but not in error, so we won't say
                 # anything more at this point.
 
@@ -160,13 +158,13 @@ class Subprocess:
         """Write a STRING to the subprocess."""
 
         if not self.pid:
-            raise SubprocessError, "no child"                           # ===>
+            raise SubprocessError("no child")                           # ===>
         if select.select([],self.toChild_fdlist,[],0)[1]:
             self.toChild.write(str)
             self.toChild.flush()
         else:
             # XXX Can write-buffer full be handled better??
-            raise IOError, "write to %s blocked" % self                 # ===>
+            raise IOError("write to %s blocked" % self)                 # ===>
 
     def writeline(self, line=''):
         """Write STRING, with added newline termination, to subprocess."""
@@ -217,7 +215,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readPendingChars()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     def readPendingLine(self):
         """Read currently pending subprocess output, up to a complete line
@@ -229,7 +227,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readPendingLine()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     def readline(self):
         """Return next complete line of subprocess output, blocking until
@@ -241,7 +239,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readline()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     ### Subprocess Control ###
 
@@ -297,9 +295,9 @@ class Subprocess:
         SubprocessError is raised if process is not successfully killed."""
 
         if not self.pid:
-            raise SubprocessError, "No process"                         # ===>
+            raise SubprocessError("No process")                         # ===>
         elif not self.cont():
-            raise SubprocessError, "Can't signal subproc %s" % self     # ===>
+            raise SubprocessError("Can't signal subproc %s" % self)     # ===>
 
         # Try sending first a TERM and then a KILL signal.
         keep_trying = 1
@@ -324,9 +322,9 @@ class Subprocess:
                     return None                                         # ===>
                 time.sleep(.1)
         # Only got here if subprocess is not gone:
-        raise (SubprocessError,
-               ("Failed kill of subproc %d, '%s', with signals %s" %
-                (self.pid, self.cmd, map(lambda(x): x[0], sigs))))
+        raise SubprocessError(
+               "Failed kill of subproc %d, '%s', with signals %s" %
+                (self.pid, self.cmd, map(lambda(x): x[0], sigs)))
 
     def __del__(self):
         """Terminate the subprocess"""
@@ -508,8 +506,8 @@ class RecordFile:
             try:
                 l = string.atoi(line)
             except ValueError:
-                raise IOError("corrupt %s file structure"
-                                % self.__class__.__name__)
+                raise IOError(("corrupt %s file structure"
+                                % self.__class__.__name__))
             return f.read(l)
         else:
             # EOF.
@@ -521,7 +519,7 @@ class RecordFile:
         if hasattr(f, attr):
             return getattr(f, attr)
         else:
-            raise AttributeError, attr
+            raise AttributeError(attr)
 
     def __repr__(self):
         return "<%s of %s at %s>" % (self.__class__.__name__,
@@ -540,7 +538,7 @@ def record_trial(s):
     r = c.read()
     show = " start:\t %s\n end:\t %s\n" % (`s`, `r`)
     if r != s:
-        raise IOError, "String distorted:\n%s" % show
+        raise IOError("String distorted:\n%s" % show)
 
 #############################################################################
 #####                   An example subprocess interfaces                #####
@@ -562,7 +560,7 @@ class Ph:
         try:
             self.proc = Subprocess('ph', 1)
         except:
-            raise SubprocessError('failure starting ph: %s' %         # ===>
+            raise SubprocessError('failure starting ph: %s' %         # ===>
                                     str(sys.exc_value))
 
     def query(self, q):
@@ -585,7 +583,7 @@ class Ph:
             if not response:
                 return got                                              # ===>
             elif type(response) == types.StringType:
-                raise ValueError, "ph failed match: '%s'" % response    # ===>
+                raise ValueError("ph failed match: '%s'" % response)    # ===>
             for line in response:
                 # convert to a dict:
                 line = string.splitfields(line, ':')
@@ -603,7 +601,7 @@ class Ph:
 
         nextChar = self.proc.waitForPendingChar(60)
         if not nextChar:
-            raise SubprocessError, 'ph subprocess not responding'       # ===>
+            raise SubprocessError('ph subprocess not responding')       # ===>
         elif nextChar == '-':
             # dashed line - discard it, and continue reading:
             self.proc.readline()
@@ -636,7 +634,7 @@ class Ph:
             got = string.splitfields(got, '\n')[-1]
             if got == 'ph> ': return    # Ok.                             ===>
             time.sleep(pause)
-        raise SubprocessError('ph not responding within %s secs' %
+        raise SubprocessError('ph not responding within %s secs' %
                                 pause * maxIter)
 
 #############################################################################