python3.2 fixes: use array.tobytes()
authorZac Medico <zmedico@gentoo.org>
Thu, 25 Aug 2011 02:48:17 +0000 (19:48 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 25 Aug 2011 02:48:17 +0000 (19:48 -0700)
pym/_emerge/PipeReader.py
pym/_emerge/SpawnProcess.py
pym/portage/tests/ebuild/test_array_fromfile_eof.py
pym/portage/util/_pty.py
pym/portage/xpak.py

index 375c98f6ad1c0eb19bd9562ccfba2cff3a21e645..02e550dce27059498d33254cef40f09626f53fff 100644 (file)
@@ -70,7 +70,11 @@ class PipeReader(AbstractPollTask):
                                pass
 
                        if buf:
-                               self._read_data.append(buf.tostring())
+                               try:
+                                       data = buf.tobytes()
+                               except AttributeError:
+                                       data = buf.tostring()
+                               self._read_data.append(data)
                        else:
                                self._unregister()
                                self.wait()
index b72971c875d2d67fede17718394baa82c1d63173..aa4160572a1270df713fe2255d6c32e253397c1a 100644 (file)
@@ -206,7 +206,11 @@ class SpawnProcess(SubProcess):
                                        buf.tofile(files.log)
                                except TypeError:
                                        # array.tofile() doesn't work with GzipFile
-                                       files.log.write(buf.tostring())
+                                       try:
+                                               data = buf.tobytes()
+                                       except AttributeError:
+                                               data = buf.tostring()
+                                       files.log.write(data)
                                files.log.flush()
                        else:
                                self._unregister()
index d8277f2755482376223cd20b901a5d2664f26e41..f965b838484e178de688d9654c39fd313ca82986 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2009 Gentoo Foundation
+# Copyright 2009-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import array
@@ -35,9 +35,12 @@ class ArrayFromfileEofTestCase(TestCase):
                        if not a:
                                eof = True
                        else:
-                               data.append(_unicode_decode(a.tostring(),
-                                       encoding='utf_8', errors='strict'))
+                               try:
+                                       data.append(a.tobytes())
+                               except AttributeError:
+                                       data.append(a.tostring())
 
                f.close()
 
-               self.assertEqual(input_data, ''.join(data))
+               self.assertEqual(input_data, _unicode_decode(b''.join(data),
+                       encoding='utf_8', errors='strict'))
index f45ff0aa1d05d7d902115071bb2185543fd52cab..f308ccbce88211287981dafd26c4b898a5da096d 100644 (file)
@@ -112,12 +112,14 @@ def _test_pty_eof(fdopen_buffered=False):
                if not buf:
                        eof = True
                else:
-                       data.append(_unicode_decode(buf.tostring(),
-                               encoding='utf_8', errors='strict'))
+                       try:
+                               data.append(buf.tobytes())
+                       except AttributeError:
+                               data.append(buf.tostring())
 
        master_file.close()
 
-       return test_string == ''.join(data)
+       return test_string == _unicode_decode(b''.join(data), encoding='utf_8', errors='strict')
 
 # If _test_pty_eof() can't be used for runtime detection of
 # http://bugs.python.org/issue5380, openpty can't safely be used
index 7487d67289cead2c842dce3837ef075781900b5d..b13e257dcb09dcde3956c5579822e1ba8e45641d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2001-2010 Gentoo Foundation
+# Copyright 2001-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 
@@ -66,7 +66,10 @@ def encodeint(myint):
        a.append((myint >> 16 ) & 0xff)
        a.append((myint >> 8 ) & 0xff)
        a.append(myint & 0xff)
-       return a.tostring()
+       try:
+               return a.tobytes()
+       except AttributeError:
+               return a.tostring()
 
 def decodeint(mystring):
        """Takes a 4 byte string and converts it into a 4 byte integer.