Lenard Lindstrom avatar Lenard Lindstrom committed c35441d

allow all Python modules to install with Python 3.1, though some may not work correctly

Comments (0)

Files changed (9)

examples/testsprite.py

         import psyco
         psyco.full()
     except Exception:
-        print "No psyco for you!  psyco failed to import and run."
+        print ("No psyco for you!  psyco failed to import and run.")
 
 main_dir = os.path.split(os.path.abspath(__file__))[0]
 data_dir = os.path.join(main_dir, 'data')
 else:
     use_alpha = False
 
-print screen_dims
+print (screen_dims)
 
 
 ##class Thingy(pygame.sprite.Sprite):
     if len(sys.argv) > 1:
         try:
             numsprites = int(sys.argv[-1])
-        except:
+        except Exception:
             numsprites = 100
     else:
         numsprites = 100
 
         frames += 1
     end = time()
-    print "FPS: %f" % (frames / ((end - start)))
+    print ("FPS: %f" % (frames / ((end - start))))
     pygame.quit()
 
 

lib/_numpysndarray.py

     # Info is a (freq, format, stereo) tuple
     info = mixer.get_init ()
     if not info:
-        raise pygame.error, "Mixer not initialized"
+        raise pygame.error("Mixer not initialized")
     fmtbytes = (abs (info[1]) & 0xff) >> 3
     channels = info[2]
     if raw:
     # Info is a (freq, format, stereo) tuple
     info = pygame.mixer.get_init ()
     if not info:
-        raise pygame.error, "Mixer not initialized"
+        raise pygame.error("Mixer not initialized")
     fmtbytes = (abs (info[1]) & 0xff) >> 3
     channels = info[2]
     data = sound.get_buffer ()
     # Info is a (freq, format, stereo) tuple
     info = pygame.mixer.get_init ()
     if not info:
-        raise pygame.error, "Mixer not initialized"
+        raise pygame.error("Mixer not initialized")
     channels = info[2]
 
     shape = array.shape
     if channels == 1:
         if len (shape) != 1:
-            raise ValueError, "Array must be 1-dimensional for mono mixer"
+            raise ValueError("Array must be 1-dimensional for mono mixer")
     else:
         if len (shape) != 2:
-            raise ValueError, "Array must be 2-dimensional for stereo mixer"
+            raise ValueError("Array must be 2-dimensional for stereo mixer")
         elif shape[1] != channels:
-            raise ValueError, "Array depth must match number of mixer channels"
+            raise ValueError("Array depth must match number of mixer channels")
     return mixer.Sound (array)

lib/_numpysurfarray.py

     """
     bpp = surface.get_bytesize ()
     if bpp <= 0 or bpp > 4:
-        raise ValueError, "unsupported bit depth for 2D array"
+        raise ValueError("unsupported bit depth for 2D array")
 
     # Taken from Alex Holkner's pygame-ctypes package. Thanks a lot.
     data = surface.get_buffer ().raw
     """
     bpp = surface.get_bytesize ()
     if bpp == 3 or bpp < 1 or bpp > 4:
-        raise ValueError, "unsupported bit depth for 2D reference array"
+        raise ValueError("unsupported bit depth for 2D reference array")
 
     typecode = (numpy.uint8, numpy.uint16, None, numpy.int32)[bpp - 1]
     array = numpy.frombuffer (surface.get_buffer (), typecode)
     """
     bpp = surface.get_bytesize ()
     if bpp < 3 or bpp > 4:
-        raise ValueError, "unsupported bit depth for 3D reference array"
+        raise ValueError("unsupported bit depth for 3D reference array")
     lilendian = pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN
 
     start = 0
             start = 2
             step = -1
     else:
-        raise ValueError, "unsupported colormasks for 3D reference array"
+        raise ValueError("unsupported colormasks for 3D reference array")
 
     if bpp == 4 and not lilendian:
         start += 1
     lifetime of the array.
     """
     if surface.get_bytesize () != 4:
-        raise ValueError, "unsupported bit depth for alpha reference array"
+        raise ValueError("unsupported bit depth for alpha reference array")
     lilendian = pygame.get_sdl_byteorder () == pygame.LIL_ENDIAN
 
     # ARGB surface.
     elif surface.get_shifts ()[3] == 0 and not lilendian:
         start = 3
     else:
-        raise ValueError, "unsupported colormasks for alpha reference array"
+        raise ValueError("unsupported colormasks for alpha reference array")
 
     array = numpy.ndarray \
             (shape=(surface.get_width (), surface.get_height ()),
         g = 0xff << 8
         b = 0xff
     else:
-        raise ValueError, "must be a valid 2d or 3d array"
+        raise ValueError("must be a valid 2d or 3d array")
 
     surface = pygame.Surface ((shape[0], shape[1]), 0, bpp, (r, g, b, 0))
     blit_array (surface, array)
     """
     bpp = surface.get_bytesize ()
     if bpp <= 0 or bpp > 4:
-        raise ValueError, "unsupported bit depth for surface"
+        raise ValueError("unsupported bit depth for surface")
     
     shape = array.shape
     width = surface.get_width ()
     elif len (shape) == 2:
         array = numpy.transpose (array)
     else:
-        raise ValueError, "must be a valid 2d or 3d array"
+        raise ValueError("must be a valid 2d or 3d array")
 
     if width != shape[0] or surface.get_height () != shape[1]:
-        raise ValueError, "array must match the surface dimensions"
+        raise ValueError("array must match the surface dimensions")
 
     itemsize = array.itemsize
     data = array.tostring ()
     # lot.
     bpp = surface.get_bytesize ()
     if bpp <= 1 or bpp > 4:
-        raise ValueError, "unsupported bit depth for surface array"
+        raise ValueError("unsupported bit depth for surface array")
 
     shape = array.shape
     if shape[-1] != 3:
-        raise ValueError, "array must be a 3d array of 3-value color data"
+        raise ValueError("array must be a 3d array of 3-value color data")
 
     shifts = surface.get_shifts ()
     losses = surface.get_losses ()
 import pygame.image
 from pygame.locals import SCRAP_TEXT, SCRAP_BMP, SCRAP_SELECTION, SCRAP_CLIPBOARD
 from cStringIO import StringIO
+from pygame.compat import unicode_
 
-ScrapPboardType = u'org.pygame.scrap'
+ScrapPboardType = unicode_('org.pygame.scrap')
 
 
 err = "Only text has been implemented for scrap on mac. See lib/mac_scrap.py to debug."
     board = NSPasteboard.generalPasteboard()
     
     if 0:
-        print board.types
-        print dir(board.types)
-        print dir(board)
-        print board.__doc__
+        print (board.types)
+        print (dir(board.types))
+        print (dir(board))
+        print (board.__doc__)
 
     if scrap_type == SCRAP_TEXT:
         return board.stringForType_(NSStringPboardType)
         else:
             text_thing = unicode(thing, 'utf-8')
         board.setString_forType_(text_thing, NSStringPboardType)
-        board.setString_forType_(u'', ScrapPboardType)
+        board.setString_forType_(unicode_(''), ScrapPboardType)
     elif 1:
         raise NotImplementedError(err)
 
         fh.close()
         board.declareTypes_owner_([NSTIFFPboardType, ScrapPboardType], None)
         board.setData_forType_(tiff, NSTIFFPboardType)
-        board.setString_forType_(u'', ScrapPboardType)
+        board.setString_forType_(unicode_(''), ScrapPboardType)
     elif scrap_type == SCRAP_BMP:
         
         other_type = scrap_type
        just before the display module is initialized"""
     if not MacOS.WMAvailable():
         if not sdlmain_osx.WMEnable():
-            raise ImportError, "Can not access the window manager.  Use py2app or execute with the pythonw script."
+            raise ImportError("Can not access the window manager.  Use py2app or execute with the pythonw script.")
     if not sdlmain_osx.RunningFromBundleWithNSApplication():
         try:
             default_icon_data = getResource('pygame_icon.tiff').read()
     import pygame._numpysndarray as numpysnd
     __hasnumpy = True
     __arraytype = "numpy"
-except ImportError, msg:
+except ImportError:
     __hasnumpy = False
 
 try:
     __hasnumeric = False
 
 if not __hasnumpy and not __hasnumeric:
-    raise ImportError, "no module named numpy or Numeric found"
+    raise ImportError("no module named numpy or Numeric found")
 
 def array (sound):
     """pygame.sndarray.array(Sound): return array
         return numericsnd.array (sound)
     elif __arraytype == "numpy":
         return numpysnd.array (sound)
-    raise NotImplementedError, "sound arrays are not supported"
+    raise NotImplementedError("sound arrays are not supported")
 
 def samples (sound):
     """pygame.sndarray.samples(Sound): return array
         return numericsnd.samples (sound)
     elif __arraytype == "numpy":
         return numpysnd.samples (sound)
-    raise NotImplementedError, "sound arrays are not supported"
+    raise NotImplementedError("sound arrays are not supported")
 
 def make_sound (array):
     """pygame.sndarray.make_sound(array): return Sound
         return numericsnd.make_sound (array)
     elif __arraytype == "numpy":
         return numpysnd.make_sound (array)
-    raise NotImplementedError, "sound arrays are not supported"
+    raise NotImplementedError("sound arrays are not supported")
 
 def use_arraytype (arraytype):
     """pygame.sndarray.use_arraytype (arraytype): return None
         if __hasnumeric:
             __arraytype = arraytype
         else:
-            raise ValueError, "Numeric arrays are not available"
+            raise ValueError("Numeric arrays are not available")
         
     elif arraytype == "numpy":
         if __hasnumpy:
             __arraytype = arraytype
         else:
-            raise ValueError, "numpy arrays are not available"
+            raise ValueError("numpy arrays are not available")
     else:
-        raise ValueError, "invalid array type"
+        raise ValueError("invalid array type")
 
 def get_arraytype ():
     """pygame.sndarray.get_arraytype (): return str

test/movie_test.py

 
 def within_seq(a,b,error_range):
     for x,y in zip(a,b):
-	#print x,y
-	if not within(x,y,error_range):
-	    return 0
+        #print x,y
+        if not within(x,y,error_range):
+            return 0
     return 1
 
 class MovieTypeTest( unittest.TestCase ):            

test/sndarray_test.py

                     snd = pygame.mixer.Sound(buffer(zeroed))
                     samples = pygame.sndarray.samples(snd)
                     self._assert_compatible(samples, size)
-                    print 'X', samples.shape
-                    print 'Y', test_data
+                    print ('X %s' % samples.shape)
+                    print ('Y %s' % test_data)
                     samples[...] = test_data
                     arr = pygame.sndarray.array(snd)
                     self.failUnless(alltrue(samples == arr),

test/surfarray_test.py

             self.assertEquals (sf.get_locked (), False)
             self.assertEquals (sf.get_locks (), ())
 
-        #print "test_surf_lock - end"
+        #print ("test_surf_lock - end")
 
 
 if __name__ == '__main__':
     if not arraytype:
-        print "No array package is installed. Cannot run unit tests."
+        print ("No array package is installed. Cannot run unit tests.")
     else:
         unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.