Commits

Anonymous committed 87bd824

Support Python 3

Comments (0)

Files changed (3)

         if self.logfile_send is not None:
             self.logfile_send.write (s)
             self.logfile_send.flush()
-        c = os.write(self.child_fd, s)
+        c = os.write(self.child_fd, s.encode('ascii'))
         return c
 
     def sendline(self, s=''):
         """
 
         while data != '' and self.isalive():
-            n = os.write(fd, data)
+            n = os.write(fd, data.encode('ascii'))
             data = data[n:]
 
     def __interact_read(self, fd):
                 if self.logfile is not None:
                     self.logfile.write (data)
                     self.logfile.flush()
-                os.write(self.STDOUT_FILENO, data)
+                os.write(self.STDOUT_FILENO, data.encode('ascii'))
             if self.STDIN_FILENO in r:
                 data = self.__interact_read(self.STDIN_FILENO)
                 if input_filter: data = input_filter(data)
         if self.timeout_index >= 0:
             ss.append ((self.timeout_index,'    %d: TIMEOUT' % self.timeout_index))
         ss.sort()
-        ss = zip(*ss)[1]
+        ss = [ s[1] for s in ss ]
         return '\n'.join(ss)
 
     def search(self, buffer, freshlen, searchwindowsize=None):
         if self.timeout_index >= 0:
             ss.append ((self.timeout_index,'    %d: TIMEOUT' % self.timeout_index))
         ss.sort()
-        ss = zip(*ss)[1]
+        ss = [ s[1] for s in ss ]
         return '\n'.join(ss)
 
     def search(self, buffer, freshlen, searchwindowsize=None):

lib/winpexpect.py

         d = dict(zip(fields, [None]*len(fields)))
         return type(name, (object,), d)
 
+# Compatbility wiht Python 3
+if sys.version_info[0] == 3:
+
+    _WriteFile = WriteFile
+    def WriteFile(handle, s):
+        return _WriteFile(handle, s.encode('ascii'))
+
+    _ReadFile = ReadFile
+    def ReadFile(handle, size):
+        err, data = _ReadFile(handle, size)
+        return err, data.decode('ascii')
+
 
 def split_command_line(cmdline):
     """Split a command line into a command and its arguments according to
 # WinPexpect is copyright (c) 2008-2010 by the WinPexpect authors. See the
 # file "AUTHORS" for a complete overview.
 
+import sys
 from setuptools import setup
 
+
+if sys.version_info[0] == 3:
+    from lib2to3.fixes import fix_types
+    print('fixing fixer')
+    fix_types._TYPE_MAPPING['StringTypes'] = '(str,)'
+
 setup(
     name = 'winpexpect',
     version = '1.3',
     package_dir = {'': 'lib'},
     py_modules = ['pexpect', 'winpexpect'],
     test_suite = 'nose.collector',
-    zip_safe = False
+    zip_safe = False,
+    use_2to3 = True
 )