Commits

Philip Jenvey committed bd87e59

some quick fixes

  • Participants
  • Parent commits 870d536
  • Branches py3k

Comments (0)

Files changed (4)

File lib_pypy/_ctypes/array.py

                     for i in range(len(val)):
                         self[i] = val[i]
                     if len(val) < self._length_:
-                        self[len(val)] = '\x00'
+                        self[len(val)] = b'\x00'
                 res.value = property(getvalue, setvalue)
 
                 def getraw(self):
         # or function argument...
         from ctypes import c_char, c_wchar
         if issubclass(self._type_, (c_char, c_wchar)):
-            if isinstance(value, basestring):
+             # XXX: this should maybe be stricer for py3 (c_char disallowing str?)
+            if isinstance(value, (bytes, str)):
                 if len(value) > self._length_:
                     raise ValueError("Invalid length")
                 value = self(*value)
             elif not isinstance(value, self):
-                raise TypeError("expected string or Unicode object, %s found"
+                raise TypeError("expected string, %s found"
                                 % (value.__class__.__name__,))
         else:
             if isinstance(value, tuple):

File lib_pypy/_ctypes/basics.py

             return self.value
 
     def __buffer__(self):
-        return buffer(self._buffer)
+        return self._buffer.__buffer__()
 
     def _get_b_base(self):
         try:

File lib_pypy/_ctypes/function.py

             except:
                 exc_info = sys.exc_info()
                 traceback.print_tb(exc_info[2], file=sys.stderr)
-                print >>sys.stderr, "%s: %s" % (exc_info[0].__name__, exc_info[1])
+                print("%s: %s" % (exc_info[0].__name__, exc_info[1]),
+                      file=sys.stderr)
                 return 0
             if self._restype_ is not None:
                 return res

File lib_pypy/_ctypes/primitive.py

 
         elif tp == 'u':
             def _setvalue(self, val):
-                if isinstance(val, str):
+                if isinstance(val, bytes):
                     val = val.decode(ConvMode.encoding, ConvMode.errors)
                 # possible if we use 'ignore'
                 if val:
 
         elif tp == 'c':
             def _setvalue(self, val):
-                if isinstance(val, unicode):
+                if isinstance(val, str):
                     val = val.encode(ConvMode.encoding, ConvMode.errors)
                 if val:
                     self._buffer[0] = val