[pypy-svn] r47549 - pypy/dist/pypy/module/struct

fijal at codespeak.net fijal at codespeak.net
Thu Oct 18 15:06:23 CEST 2007


Author: fijal
Date: Thu Oct 18 15:06:20 2007
New Revision: 47549

Modified:
   pypy/dist/pypy/module/struct/standardfmttable.py
Log:
Refactor struct for easier reuse


Modified: pypy/dist/pypy/module/struct/standardfmttable.py
==============================================================================
--- pypy/dist/pypy/module/struct/standardfmttable.py	(original)
+++ pypy/dist/pypy/module/struct/standardfmttable.py	Thu Oct 18 15:06:20 2007
@@ -65,17 +65,7 @@
 
 native_int_size = struct.calcsize("l")
 
-def make_int_packer(size, signed, cpython_checks_range, _memo={}):
-    if cpython_checks_range:
-        check_range = True
-    else:
-        check_range = not PACK_ACCEPTS_BROKEN_INPUT
-    key = (size, signed, check_range)
-    try:
-        return _memo[key]
-    except KeyError:
-        pass
-
+def min_max_acc_method(size, signed):
     if signed:
         min = -(2 ** (8*size-1))
         max = (2 ** (8*size-1)) - 1
@@ -100,6 +90,19 @@
             accept_method = 'accept_ulonglong_arg'
             min = r_ulonglong(min)
             max = r_ulonglong(max)
+    return min, max, accept_method
+
+def make_int_packer(size, signed, cpython_checks_range, _memo={}):
+    if cpython_checks_range:
+        check_range = True
+    else:
+        check_range = not PACK_ACCEPTS_BROKEN_INPUT
+    key = (size, signed, check_range)
+    try:
+        return _memo[key]
+    except KeyError:
+        pass
+    min, max, accept_method = min_max_acc_method(size, signed)
     if size > 1:
         plural = "s"
     else:



More information about the Pypy-commit mailing list