Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r60627:d0b59874de62
Date: 2013-01-28 19:55 +0100
http://bitbucket.org/pypy/pypy/changeset/d0b59874de62/
Log: Now that rpython has its own copy of _marshal.py, undo the python3
specific change we made there.
diff --git a/rpython/translator/sandbox/_marshal.py
b/rpython/translator/sandbox/_marshal.py
--- a/rpython/translator/sandbox/_marshal.py
+++ b/rpython/translator/sandbox/_marshal.py
@@ -4,12 +4,8 @@
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
try: from __pypy__ import builtinify
except ImportError: builtinify = lambda f: f
@@ -54,7 +50,7 @@
if func:
break
else:
- raise ValueError("unmarshallable object")
+ raise ValueError, "unmarshallable object"
func(self, x)
def w_long64(self, x):
@@ -77,7 +73,7 @@
def dump_none(self, x):
self._write(TYPE_NONE)
- dispatch[type(None)] = dump_none
+ dispatch[types.NoneType] = dump_none
def dump_bool(self, x):
if x:
@@ -88,7 +84,7 @@
def dump_stopiter(self, x):
if x is not StopIteration:
- raise ValueError("unmarshallable object")
+ raise ValueError, "unmarshallable object"
self._write(TYPE_STOPITER)
dispatch[type(StopIteration)] = dump_stopiter
@@ -96,11 +92,10 @@
self._write(TYPE_ELLIPSIS)
try:
- dispatch[type(Ellipsis)] = dump_ellipsis
+ dispatch[types.EllipsisType] = dump_ellipsis
except NameError:
pass
- # In Python3, this function is not used; see dump_long() below.
def dump_int(self, x):
y = x>>31
if y and y != -1:
@@ -109,7 +104,7 @@
else:
self._write(TYPE_INT)
self.w_long(x)
- dispatch[int] = dump_int
+ dispatch[types.IntType] = dump_int
def dump_long(self, x):
self._write(TYPE_LONG)
@@ -124,32 +119,27 @@
self.w_long(len(digits) * sign)
for d in digits:
self.w_short(d)
- try:
- long
- except NameError:
- dispatch[int] = dump_long
- else:
- dispatch[long] = dump_long
+ dispatch[types.LongType] = dump_long
def dump_float(self, x):
write = self._write
write(TYPE_FLOAT)
- s = repr(x)
+ s = `x`
write(chr(len(s)))
write(s)
- dispatch[float] = dump_float
+ dispatch[types.FloatType] = dump_float
def dump_complex(self, x):
write = self._write
write(TYPE_COMPLEX)
- s = repr(x.real)
+ s = `x.real`
write(chr(len(s)))
write(s)
- s = repr(x.imag)
+ s = `x.imag`
write(chr(len(s)))
write(s)
try:
- dispatch[complex] = dump_complex
+ dispatch[types.ComplexType] = dump_complex
except NameError:
pass
@@ -159,7 +149,7 @@
self._write(TYPE_STRING)
self.w_long(len(x))
self._write(x)
- dispatch[bytes] = dump_string
+ dispatch[types.StringType] = dump_string
def dump_unicode(self, x):
self._write(TYPE_UNICODE)
@@ -167,26 +157,21 @@
s, len_s = utf_8_encode(x)
self.w_long(len_s)
self._write(s)
- try:
- unicode
- except NameError:
- dispatch[str] = dump_unicode
- else:
- dispatch[unicode] = dump_unicode
+ dispatch[types.UnicodeType] = dump_unicode
def dump_tuple(self, x):
self._write(TYPE_TUPLE)
self.w_long(len(x))
for item in x:
self.dump(item)
- dispatch[tuple] = dump_tuple
+ dispatch[types.TupleType] = dump_tuple
def dump_list(self, x):
self._write(TYPE_LIST)
self.w_long(len(x))
for item in x:
self.dump(item)
- dispatch[list] = dump_list
+ dispatch[types.ListType] = dump_list
def dump_dict(self, x):
self._write(TYPE_DICT)
@@ -194,7 +179,7 @@
self.dump(key)
self.dump(value)
self._write(TYPE_NULL)
- dispatch[dict] = dump_dict
+ dispatch[types.DictionaryType] = dump_dict
def dump_code(self, x):
self._write(TYPE_CODE)
@@ -268,7 +253,7 @@
try:
return self.dispatch[c](self)
except KeyError:
- raise ValueError("bad marshal code: %c (%d)" % (c, ord(c)))
+ raise ValueError, "bad marshal code: %c (%d)" % (c, ord(c))
def r_short(self):
lo = ord(self._read(1))
@@ -286,7 +271,7 @@
d = ord(s[3])
x = a | (b<<8) | (c<<16) | (d<<24)
if d & 0x80 and x > 0:
- x = -((1<<32) - x)
+ x = -((1L<<32) - x)
return int(x)
else:
return x
@@ -296,14 +281,14 @@
b = ord(self._read(1))
c = ord(self._read(1))
d = ord(self._read(1))
- e = int(ord(self._read(1)))
- f = int(ord(self._read(1)))
- g = int(ord(self._read(1)))
- h = int(ord(self._read(1)))
+ e = long(ord(self._read(1)))
+ f = long(ord(self._read(1)))
+ g = long(ord(self._read(1)))
+ h = long(ord(self._read(1)))
x = a | (b<<8) | (c<<16) | (d<<24)
x = x | (e<<32) | (f<<40) | (g<<48) | (h<<56)
if h & 0x80 and x > 0:
- x = -((1<<64) - x)
+ x = -((1L<<64) - x)
return x
def load_null(self):
@@ -340,10 +325,10 @@
if size < 0:
sign = -1
size = -size
- x = 0
+ x = 0L
for i in range(size):
d = self.r_short()
- x = x | (d<<(i*15))
+ x = x | (d<<(i*15L))
return x * sign
dispatch[TYPE_LONG] = load_long
@@ -370,7 +355,7 @@
def load_interned(self):
n = self.r_long()
- ret = sys.intern(self._read(n))
+ ret = intern(self._read(n))
self._stringtable.append(ret)
return ret
dispatch[TYPE_INTERNED] = load_interned
@@ -475,7 +460,7 @@
self.bufpos += 4
x = a | (b<<8) | (c<<16) | (d<<24)
if d & 0x80 and x > 0:
- x = -((1<<32) - x)
+ x = -((1L<<32) - x)
return int(x)
else:
return x
@@ -485,14 +470,14 @@
b = ord(_read1(self))
c = ord(_read1(self))
d = ord(_read1(self))
- e = int(ord(_read1(self)))
- f = int(ord(_read1(self)))
- g = int(ord(_read1(self)))
- h = int(ord(_read1(self)))
+ e = long(ord(_read1(self)))
+ f = long(ord(_read1(self)))
+ g = long(ord(_read1(self)))
+ h = long(ord(_read1(self)))
x = a | (b<<8) | (c<<16) | (d<<24)
x = x | (e<<32) | (f<<40) | (g<<48) | (h<<56)
if h & 0x80 and x > 0:
- x = -((1<<64) - x)
+ x = -((1L<<64) - x)
return x
_load_dispatch = {}
@@ -514,7 +499,7 @@
self.bufpos += 1
return _load_dispatch[c](self)
except KeyError:
- raise ValueError("bad marshal code: %c (%d)" % (c, ord(c)))
+ raise ValueError, "bad marshal code: %c (%d)" % (c, ord(c))
except IndexError:
raise EOFError
@@ -556,10 +541,10 @@
if size < 0:
sign = -1
size = -size
- x = 0
+ x = 0L
for i in range(size):
d = _r_short(self)
- x = x | (d<<(i*15))
+ x = x | (d<<(i*15L))
return x * sign
dispatch[TYPE_LONG] = load_long
@@ -586,7 +571,7 @@
def load_interned(self):
n = _r_long(self)
- ret = sys.intern(_read(self, n))
+ ret = intern(_read(self, n))
self._stringtable.append(ret)
return ret
dispatch[TYPE_INTERNED] = load_interned
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit