1. Pypy
  2. Untitled project
  3. pypy


Amaury Forgeot d'Arc  committed d76f430

Make lib_pypy/_marshal.py work for both Python2 and Python3.
This fixes sandbox tests.

  • Participants
  • Parent commits 746d373
  • Branches py3k

Comments (0)

Files changed (1)

File lib_pypy/_marshal.py

View file
 This module contains functions that can read and write Python values in a binary format. The format is specific to Python, but independent of machine architecture issues (e.g., you can write a Python value to a file on a PC, transport the file to a Sun, and read it back there). Details of the format may change between Python versions.
+# NOTE: This module is used in the Python3 interpreter, but also by
+# the "sandboxed" process.  It must work for Python2 as well.
 import types
 from _codecs import utf_8_decode, utf_8_encode
 import sys
     except NameError:
+    # In Python3, this function is not used; see dump_long() below.
     def dump_int(self, x):
         y = x>>31
         if y and y != -1:
         self.w_long(len(digits) * sign)
         for d in digits:
-    dispatch[int] = dump_long
+    try:
+        long
+    except NameError:
+        dispatch[int] = dump_long
+    else:
+        dispatch[long] = dump_long
     def dump_float(self, x):
         write = self._write
         s, len_s = utf_8_encode(x)
-    dispatch[str] = dump_unicode
+    try:
+        unicode
+    except NameError:
+        dispatch[str] = dump_unicode
+    else:
+        dispatch[unicode] = dump_unicode
     def dump_tuple(self, x):