Skip to content

Commit

Permalink
Py 3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielelanaro committed Jun 3, 2015
1 parent 038dd29 commit 67318d8
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions chemlab/utils/pexpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import errno
import traceback
import signal
except ImportError, e:
except ImportError as e:
raise ImportError (str(e) + """
A critical module was not found. Probably this operating system does not
Expand Down Expand Up @@ -247,10 +247,10 @@ def print_ticks(d):
else:
raise TypeError ('The callback must be a string or function type.')
event_count = event_count + 1
except TIMEOUT, e:
except TIMEOUT as e:
child_result_list.append(child.before)
break
except EOF, e:
except EOF as e:
child_result_list.append(child.before)
break
child_result = ''.join(child_result_list)
Expand Down Expand Up @@ -526,7 +526,7 @@ def _spawn(self,command,args=[]):
if self.use_native_pty_fork:
try:
self.pid, self.child_fd = pty.fork()
except OSError, e:
except OSError as e:
raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e))
else: # Use internal __fork_pty
self.pid, self.child_fd = self.__fork_pty()
Expand Down Expand Up @@ -582,11 +582,11 @@ def __fork_pty(self):

parent_fd, child_fd = os.openpty()
if parent_fd < 0 or child_fd < 0:
raise ExceptionPexpect, "Error! Could not open pty with os.openpty()."
raise ExceptionPexpect("Error! Could not open pty with os.openpty().")

pid = os.fork()
if pid < 0:
raise ExceptionPexpect, "Error! Failed os.fork()."
raise ExceptionPexpect("Error! Failed os.fork().")
elif pid == 0:
# Child.
os.close(parent_fd)
Expand Down Expand Up @@ -628,22 +628,22 @@ def __pty_make_controlling_tty(self, tty_fd):
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY);
if fd >= 0:
os.close(fd)
raise ExceptionPexpect, "Error! We are not disconnected from a controlling tty."
raise ExceptionPexpect("Error! We are not disconnected from a controlling tty.")
except:
# Good! We are disconnected from a controlling tty.
pass

# Verify we can open child pty.
fd = os.open(child_name, os.O_RDWR);
if fd < 0:
raise ExceptionPexpect, "Error! Could not open child pty, " + child_name
raise ExceptionPexpect("Error! Could not open child pty, " + child_name)
else:
os.close(fd)

# Verify we now have a controlling tty.
fd = os.open("/dev/tty", os.O_WRONLY)
if fd < 0:
raise ExceptionPexpect, "Error! Could not open controlling tty, /dev/tty"
raise ExceptionPexpect("Error! Could not open controlling tty, /dev/tty")
else:
os.close(fd)

Expand Down Expand Up @@ -831,7 +831,7 @@ def read_nonblocking (self, size = 1, timeout = -1):
if self.child_fd in r:
try:
s = os.read(self.child_fd, size)
except OSError, e: # Linux does this
except OSError as e: # Linux does this
self.flag_eof = True
raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.')
if s == '': # BSD style
Expand Down Expand Up @@ -1076,7 +1076,7 @@ def terminate(self, force=False):
else:
return False
return False
except OSError, e:
except OSError as e:
# I think there are kernel timing issues that sometimes cause
# this to happen. I think isalive() reports True, but the
# process is dead to the kernel.
Expand Down Expand Up @@ -1135,7 +1135,7 @@ def isalive(self):

try:
pid, status = os.waitpid(self.pid, waitpid_options)
except OSError, e: # No child processes
except OSError as e: # No child processes
if e[0] == errno.ECHILD:
raise ExceptionPexpect ('isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process?')
else:
Expand All @@ -1147,7 +1147,7 @@ def isalive(self):
if pid == 0:
try:
pid, status = os.waitpid(self.pid, waitpid_options) ### os.WNOHANG) # Solaris!
except OSError, e: # This should never happen...
except OSError as e: # This should never happen...
if e[0] == errno.ECHILD:
raise ExceptionPexpect ('isalive() encountered condition that should never happen. There was no child process. Did someone else call waitpid() on our process?')
else:
Expand Down Expand Up @@ -1386,7 +1386,7 @@ def expect_loop(self, searcher, timeout = -1, searchwindowsize = -1):
incoming = incoming + c
if timeout is not None:
timeout = end_time - time.time()
except EOF, e:
except EOF as e:
self.buffer = ''
self.before = incoming
self.after = EOF
Expand All @@ -1399,7 +1399,7 @@ def expect_loop(self, searcher, timeout = -1, searchwindowsize = -1):
self.match = None
self.match_index = None
raise EOF (str(e) + '\n' + str(self))
except TIMEOUT, e:
except TIMEOUT as e:
self.buffer = incoming
self.before = incoming
self.after = TIMEOUT
Expand All @@ -1424,7 +1424,7 @@ def getwinsize(self):
"""This returns the terminal window size of the child tty. The return
value is a tuple of (rows, cols). """

TIOCGWINSZ = getattr(termios, 'TIOCGWINSZ', 1074295912L)
TIOCGWINSZ = getattr(termios, 'TIOCGWINSZ', long(1074295912))
s = struct.pack('HHHH', 0, 0, 0, 0)
x = fcntl.ioctl(self.fileno(), TIOCGWINSZ, s)
return struct.unpack('HHHH', x)[0:2]
Expand All @@ -1446,7 +1446,7 @@ def setwinsize(self, r, c):
# Newer versions of Linux have totally different values for TIOCSWINSZ.
# Note that this fix is a hack.
TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
if TIOCSWINSZ == 2148037735L: # L is not required in Python >= 2.2.
if TIOCSWINSZ == long(2148037735): # L is not required in Python >= 2.2.
TIOCSWINSZ = -2146929561 # Same bits, but with sign.
# Note, assume ws_xpixel and ws_ypixel are zero.
s = struct.pack('HHHH', r, c, 0, 0)
Expand Down Expand Up @@ -1552,7 +1552,7 @@ def __select (self, iwtd, owtd, ewtd, timeout=None):
while True:
try:
return select.select (iwtd, owtd, ewtd, timeout)
except select.error, e:
except select.error as e:
if e[0] == errno.EINTR:
# if we loop back we have to subtract the amount of time we already waited.
if timeout is not None:
Expand Down

0 comments on commit 67318d8

Please sign in to comment.