Source

pygame / pygame / array.py

Diff from to

pygame/array.py

 __version__ = '$Id$'
 
 from ctypes import *
+import sys
 
 class _Numeric_PyArrayObject(Structure):
     _fields_ = [('ob_refcnt', c_int),
         import Numeric
         return Numeric
 
+def _array_from_string(string, bpp, shape, signed=False):
+    if signed:
+        typecode = (_array.Int8, _array.Int16, None, _array.Int32)[bpp-1]
+    else:
+        typecode = (_array.UInt8, _array.UInt16, None, _array.UInt32)[bpp-1]
+
+    if _array.__name__ == 'numpy':
+        return _array.fromstring(string, typecode).reshape(shape)
+    elif _array.__name__ == 'numarray':
+        return _array.fromstring(string, typecode, shape)
+    elif _array.__name__ == 'Numeric':
+        return _array.reshape(_array.fromstring(string, typecode), shape)
+
 def _array_from_buffer(buffer, bpp, shape, signed=False):
     if signed:
         typecode = (_array.Int8, _array.Int16, None, _array.Int32)[bpp-1]
         array_obj = _Numeric_PyArrayObject.from_address(id(array))
         assert array_obj.flags & _OWN_DATA != 0
         try:
-            if sys.platform == 'windows':
-                libc = cdll.msvcrt
-            else:
-                libc = cdll.load_version('c', 6)
+            libc = _get_libc()
             libc.free(array_obj.data)
         except OSError:
             pass # Couldn't find libc; accept a small memory leak
 
     else:
         assert False
+
+def _get_libc():
+    if sys.platform == 'windows':
+        return cdll.msvcrt
+    else:
+        return cdll.load_version('c', 6)
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.