a first very rough step towards python3
[nepi.git] / src / nepi / util / sshfuncs.py
index 176afd3..a6aeb14 100644 (file)
@@ -203,15 +203,15 @@ def eintr_retry(func):
     @functools.wraps(func)
     def rv(*p, **kw):
         retry = kw.pop("_retry", False)
-        for i in xrange(0 if retry else 4):
+        for i in range(0 if retry else 4):
             try:
                 return func(*p, **kw)
-            except (select.error, socket.error), args:
+            except (select.error, socket.error) as args:
                 if args[0] == errno.EINTR:
                     continue
                 else:
                     raise 
-            except OSError, e:
+            except OSError as e:
                 if e.errno == errno.EINTR:
                     continue
                 else:
@@ -337,7 +337,7 @@ def rcopy(source, dest,
     elif isinstance(source, str) and ':' in source:
         remspec, path = source.split(':',1)
     else:
-        raise ValueError, "Both endpoints cannot be local"
+        raise ValueError("Both endpoints cannot be local")
     user,host = remspec.rsplit('@',1)
     
     # plain scp
@@ -498,7 +498,7 @@ def rspawn(command, pidfile,
         )
     
     if proc.wait():
-        raise RuntimeError, "Failed to set up application on host %s: %s %s" % (host, out,err,)
+        raise RuntimeError("Failed to set up application on host %s: %s %s" % (host, out,err,))
 
     return ((out, err), proc)
 
@@ -549,7 +549,7 @@ def rgetpid(pidfile,
     
     if out:
         try:
-            return map(int,out.strip().split(' ',1))
+            return list(map(int,out.strip().split(' ',1)))
         except:
             # Ignore, many ways to fail that don't matter that much
             return None
@@ -692,7 +692,7 @@ def _retry_rexec(args,
         tmp_known_hosts = None,
         blocking = True):
 
-    for x in xrange(retry):
+    for x in range(retry):
         # display command actually invoked when debug is turned on
         message = " ".join( [ "'{}'".format(arg) for arg in args ] )
         log("sshfuncs: invoking {}".format(message), logging.DEBUG)
@@ -744,7 +744,7 @@ def _retry_rexec(args,
                     time.sleep(t)
                     continue
             break
-        except RuntimeError, e:
+        except RuntimeError as e:
             msg = " rexec EXCEPTION - TIMEOUT -> %s \n %s" % ( e.args, log_msg )
             log(msg, logging.DEBUG, out, err)
 
@@ -810,7 +810,7 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True):
 
         try:
             rlist, wlist, xlist = select.select(read_set, write_set, [], select_timeout)
-        except select.error,e:
+        except select.error as e:
             if e[0] != 4:
                 raise
             else:
@@ -864,7 +864,7 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True):
 
     if killed and err_on_timeout:
         errcode = proc.poll()
-        raise RuntimeError("Operation timed out", errcode, stdout, stderr)
+        raise RuntimeError("Operation timed out", errcode, stdout, stderr)
     else:
         if killed:
             proc.poll()