Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r62234:3108a9e42aec Date: 2013-03-08 15:23 +0100 http://bitbucket.org/pypy/pypy/changeset/3108a9e42aec/
Log: merge heads diff --git a/lib_pypy/__init__.py b/lib_pypy/__init__.py --- a/lib_pypy/__init__.py +++ b/lib_pypy/__init__.py @@ -1,4 +1,4 @@ # This __init__.py shows up in PyPy's app-level standard library. # Let's try to prevent that confusion... if __name__ != 'lib_pypy': - raise ImportError, '__init__' + raise ImportError('__init__') diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py --- a/lib_pypy/_collections.py +++ b/lib_pypy/_collections.py @@ -10,7 +10,7 @@ import operator try: - from thread import get_ident as _thread_ident + from threading import _get_ident as _thread_ident except ImportError: def _thread_ident(): return -1 @@ -97,7 +97,7 @@ def pop(self): if self.left is self.right and self.leftndx > self.rightndx: - raise IndexError, "pop from an empty deque" + raise IndexError("pop from an empty deque") x = self.right[self.rightndx] self.right[self.rightndx] = None self.length -= 1 @@ -118,7 +118,7 @@ def popleft(self): if self.left is self.right and self.leftndx > self.rightndx: - raise IndexError, "pop from an empty deque" + raise IndexError("pop from an empty deque") x = self.left[self.leftndx] self.left[self.leftndx] = None self.length -= 1 @@ -322,7 +322,7 @@ return type(self), (list(self), self.maxlen) def __hash__(self): - raise TypeError, "deque objects are unhashable" + raise TypeError("deque objects are unhashable") def __copy__(self): return self.__class__(self, self.maxlen) @@ -374,11 +374,11 @@ self.counter = len(deq) def giveup(): self.counter = 0 - raise RuntimeError, "deque mutated during iteration" + raise RuntimeError("deque mutated during iteration") self._gen = itergen(deq.state, giveup) def next(self): - res = self._gen.next() + res = next(self._gen) self.counter -= 1 return res diff --git a/lib_pypy/_csv.py b/lib_pypy/_csv.py --- a/lib_pypy/_csv.py +++ b/lib_pypy/_csv.py @@ -225,7 +225,7 @@ self._parse_reset() while True: try: - line = self.input_iter.next() + line = next(self.input_iter) except StopIteration: # End of input OR exception if len(self.field) > 0: diff --git a/lib_pypy/_marshal.py b/lib_pypy/_marshal.py --- a/lib_pypy/_marshal.py +++ b/lib_pypy/_marshal.py @@ -3,9 +3,17 @@ 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 +try: + intern +except NameError: + from sys import intern + try: from __pypy__ import builtinify except ImportError: builtinify = lambda f: f @@ -49,7 +57,7 @@ if func: break else: - raise ValueError, "unmarshallable object" + raise ValueError("unmarshallable object") func(self, x) def w_long64(self, x): @@ -72,7 +80,7 @@ def dump_none(self, x): self._write(TYPE_NONE) - dispatch[types.NoneType] = dump_none + dispatch[type(None)] = dump_none def dump_bool(self, x): if x: @@ -83,7 +91,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 @@ -91,10 +99,11 @@ self._write(TYPE_ELLIPSIS) try: - dispatch[types.EllipsisType] = dump_ellipsis + dispatch[type(Ellipsis)] = 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: @@ -103,7 +112,7 @@ else: self._write(TYPE_INT) self.w_long(x) - dispatch[types.IntType] = dump_int + dispatch[int] = dump_int def dump_long(self, x): self._write(TYPE_LONG) @@ -118,27 +127,32 @@ self.w_long(len(digits) * sign) for d in digits: self.w_short(d) - dispatch[types.LongType] = dump_long + try: + long + except NameError: + dispatch[int] = dump_long + else: + dispatch[long] = dump_long def dump_float(self, x): write = self._write write(TYPE_FLOAT) - s = `x` + s = repr(x) write(chr(len(s))) write(s) - dispatch[types.FloatType] = dump_float + dispatch[float] = dump_float def dump_complex(self, x): write = self._write write(TYPE_COMPLEX) - s = `x.real` + s = repr(x.real) write(chr(len(s))) write(s) - s = `x.imag` + s = repr(x.imag) write(chr(len(s))) write(s) try: - dispatch[types.ComplexType] = dump_complex + dispatch[complex] = dump_complex except NameError: pass @@ -148,7 +162,7 @@ self._write(TYPE_STRING) self.w_long(len(x)) self._write(x) - dispatch[types.StringType] = dump_string + dispatch[bytes] = dump_string def dump_unicode(self, x): self._write(TYPE_UNICODE) @@ -156,21 +170,26 @@ s, len_s = utf_8_encode(x) self.w_long(len_s) self._write(s) - dispatch[types.UnicodeType] = dump_unicode + try: + unicode + except NameError: + dispatch[str] = dump_unicode + else: + dispatch[unicode] = dump_unicode def dump_tuple(self, x): self._write(TYPE_TUPLE) self.w_long(len(x)) for item in x: self.dump(item) - dispatch[types.TupleType] = dump_tuple + dispatch[tuple] = dump_tuple def dump_list(self, x): self._write(TYPE_LIST) self.w_long(len(x)) for item in x: self.dump(item) - dispatch[types.ListType] = dump_list + dispatch[list] = dump_list def dump_dict(self, x): self._write(TYPE_DICT) @@ -178,7 +197,7 @@ self.dump(key) self.dump(value) self._write(TYPE_NULL) - dispatch[types.DictionaryType] = dump_dict + dispatch[dict] = dump_dict def dump_code(self, x): self._write(TYPE_CODE) @@ -252,7 +271,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)) @@ -270,7 +289,7 @@ d = ord(s[3]) x = a | (b<<8) | (c<<16) | (d<<24) if d & 0x80 and x > 0: - x = -((1L<<32) - x) + x = -((1<<32) - x) return int(x) else: return x @@ -280,14 +299,14 @@ b = ord(self._read(1)) c = ord(self._read(1)) d = 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))) + e = ord(self._read(1)) + f = ord(self._read(1)) + g = ord(self._read(1)) + h = 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 = -((1L<<64) - x) + x = -((1<<64) - x) return x def load_null(self): @@ -324,10 +343,10 @@ if size < 0: sign = -1 size = -size - x = 0L + x = 0 for i in range(size): d = self.r_short() - x = x | (d<<(i*15L)) + x = x | (d<<(i*15)) return x * sign dispatch[TYPE_LONG] = load_long @@ -459,7 +478,7 @@ self.bufpos += 4 x = a | (b<<8) | (c<<16) | (d<<24) if d & 0x80 and x > 0: - x = -((1L<<32) - x) + x = -((1<<32) - x) return int(x) else: return x @@ -469,14 +488,14 @@ b = ord(_read1(self)) c = ord(_read1(self)) d = ord(_read1(self)) - e = long(ord(_read1(self))) - f = long(ord(_read1(self))) - g = long(ord(_read1(self))) - h = long(ord(_read1(self))) + e = ord(_read1(self)) + f = ord(_read1(self)) + g = ord(_read1(self)) + h = 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 = -((1L<<64) - x) + x = -((1<<64) - x) return x _load_dispatch = {} @@ -498,7 +517,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 @@ -540,10 +559,10 @@ if size < 0: sign = -1 size = -size - x = 0L + x = 0 for i in range(size): d = _r_short(self) - x = x | (d<<(i*15L)) + x = x | (d<<(i*15)) return x * sign dispatch[TYPE_LONG] = load_long diff --git a/lib_pypy/_md5.py b/lib_pypy/_md5.py --- a/lib_pypy/_md5.py +++ b/lib_pypy/_md5.py @@ -47,16 +47,16 @@ def _bytelist2long(list): "Transform a list of characters into a list of longs." - imax = len(list)/4 - hl = [0L] * imax + imax = len(list) // 4 + hl = [0] * imax j = 0 i = 0 while i < imax: - b0 = long(ord(list[j])) - b1 = (long(ord(list[j+1]))) << 8 - b2 = (long(ord(list[j+2]))) << 16 - b3 = (long(ord(list[j+3]))) << 24 + b0 = ord(list[j]) + b1 = ord(list[j+1]) << 8 + b2 = ord(list[j+2]) << 16 + b3 = ord(list[j+3]) << 24 hl[i] = b0 | b1 |b2 | b3 i = i+1 j = j+4 @@ -100,16 +100,16 @@ (now summed-up in one function). """ - res = 0L + res = 0 res = res + a + func(b, c, d) res = res + x res = res + ac - res = res & 0xffffffffL + res = res & 0xffffffff res = _rotateLeft(res, s) - res = res & 0xffffffffL + res = res & 0xffffffff res = res + b - return res & 0xffffffffL + return res & 0xffffffff class MD5Type: @@ -122,7 +122,7 @@ "Initialisation." # Initial message length in bits(!). - self.length = 0L + self.length = 0 self.count = [0, 0] # Initial empty message as a sequence of bytes (8 bit characters). @@ -136,15 +136,15 @@ def init(self): "Initialize the message-digest and set all fields to zero." - self.length = 0L + self.length = 0 self.count = [0, 0] self.input = [] # Load magic initialization constants. - self.A = 0x67452301L - self.B = 0xefcdab89L - self.C = 0x98badcfeL - self.D = 0x10325476L + self.A = 0x67452301 + self.B = 0xefcdab89 + self.C = 0x98badcfe + self.D = 0x10325476 def _transform(self, inp): @@ -161,90 +161,90 @@ S11, S12, S13, S14 = 7, 12, 17, 22 - a = XX(F, a, b, c, d, inp[ 0], S11, 0xD76AA478L) # 1 - d = XX(F, d, a, b, c, inp[ 1], S12, 0xE8C7B756L) # 2 - c = XX(F, c, d, a, b, inp[ 2], S13, 0x242070DBL) # 3 - b = XX(F, b, c, d, a, inp[ 3], S14, 0xC1BDCEEEL) # 4 - a = XX(F, a, b, c, d, inp[ 4], S11, 0xF57C0FAFL) # 5 - d = XX(F, d, a, b, c, inp[ 5], S12, 0x4787C62AL) # 6 - c = XX(F, c, d, a, b, inp[ 6], S13, 0xA8304613L) # 7 - b = XX(F, b, c, d, a, inp[ 7], S14, 0xFD469501L) # 8 - a = XX(F, a, b, c, d, inp[ 8], S11, 0x698098D8L) # 9 - d = XX(F, d, a, b, c, inp[ 9], S12, 0x8B44F7AFL) # 10 - c = XX(F, c, d, a, b, inp[10], S13, 0xFFFF5BB1L) # 11 - b = XX(F, b, c, d, a, inp[11], S14, 0x895CD7BEL) # 12 - a = XX(F, a, b, c, d, inp[12], S11, 0x6B901122L) # 13 - d = XX(F, d, a, b, c, inp[13], S12, 0xFD987193L) # 14 - c = XX(F, c, d, a, b, inp[14], S13, 0xA679438EL) # 15 - b = XX(F, b, c, d, a, inp[15], S14, 0x49B40821L) # 16 + a = XX(F, a, b, c, d, inp[ 0], S11, 0xD76AA478) # 1 + d = XX(F, d, a, b, c, inp[ 1], S12, 0xE8C7B756) # 2 + c = XX(F, c, d, a, b, inp[ 2], S13, 0x242070DB) # 3 + b = XX(F, b, c, d, a, inp[ 3], S14, 0xC1BDCEEE) # 4 + a = XX(F, a, b, c, d, inp[ 4], S11, 0xF57C0FAF) # 5 + d = XX(F, d, a, b, c, inp[ 5], S12, 0x4787C62A) # 6 + c = XX(F, c, d, a, b, inp[ 6], S13, 0xA8304613) # 7 + b = XX(F, b, c, d, a, inp[ 7], S14, 0xFD469501) # 8 + a = XX(F, a, b, c, d, inp[ 8], S11, 0x698098D8) # 9 + d = XX(F, d, a, b, c, inp[ 9], S12, 0x8B44F7AF) # 10 + c = XX(F, c, d, a, b, inp[10], S13, 0xFFFF5BB1) # 11 + b = XX(F, b, c, d, a, inp[11], S14, 0x895CD7BE) # 12 + a = XX(F, a, b, c, d, inp[12], S11, 0x6B901122) # 13 + d = XX(F, d, a, b, c, inp[13], S12, 0xFD987193) # 14 + c = XX(F, c, d, a, b, inp[14], S13, 0xA679438E) # 15 + b = XX(F, b, c, d, a, inp[15], S14, 0x49B40821) # 16 # Round 2. S21, S22, S23, S24 = 5, 9, 14, 20 - a = XX(G, a, b, c, d, inp[ 1], S21, 0xF61E2562L) # 17 - d = XX(G, d, a, b, c, inp[ 6], S22, 0xC040B340L) # 18 - c = XX(G, c, d, a, b, inp[11], S23, 0x265E5A51L) # 19 - b = XX(G, b, c, d, a, inp[ 0], S24, 0xE9B6C7AAL) # 20 - a = XX(G, a, b, c, d, inp[ 5], S21, 0xD62F105DL) # 21 - d = XX(G, d, a, b, c, inp[10], S22, 0x02441453L) # 22 - c = XX(G, c, d, a, b, inp[15], S23, 0xD8A1E681L) # 23 - b = XX(G, b, c, d, a, inp[ 4], S24, 0xE7D3FBC8L) # 24 - a = XX(G, a, b, c, d, inp[ 9], S21, 0x21E1CDE6L) # 25 - d = XX(G, d, a, b, c, inp[14], S22, 0xC33707D6L) # 26 - c = XX(G, c, d, a, b, inp[ 3], S23, 0xF4D50D87L) # 27 - b = XX(G, b, c, d, a, inp[ 8], S24, 0x455A14EDL) # 28 - a = XX(G, a, b, c, d, inp[13], S21, 0xA9E3E905L) # 29 - d = XX(G, d, a, b, c, inp[ 2], S22, 0xFCEFA3F8L) # 30 - c = XX(G, c, d, a, b, inp[ 7], S23, 0x676F02D9L) # 31 - b = XX(G, b, c, d, a, inp[12], S24, 0x8D2A4C8AL) # 32 + a = XX(G, a, b, c, d, inp[ 1], S21, 0xF61E2562) # 17 + d = XX(G, d, a, b, c, inp[ 6], S22, 0xC040B340) # 18 + c = XX(G, c, d, a, b, inp[11], S23, 0x265E5A51) # 19 + b = XX(G, b, c, d, a, inp[ 0], S24, 0xE9B6C7AA) # 20 + a = XX(G, a, b, c, d, inp[ 5], S21, 0xD62F105D) # 21 + d = XX(G, d, a, b, c, inp[10], S22, 0x02441453) # 22 + c = XX(G, c, d, a, b, inp[15], S23, 0xD8A1E681) # 23 + b = XX(G, b, c, d, a, inp[ 4], S24, 0xE7D3FBC8) # 24 + a = XX(G, a, b, c, d, inp[ 9], S21, 0x21E1CDE6) # 25 + d = XX(G, d, a, b, c, inp[14], S22, 0xC33707D6) # 26 + c = XX(G, c, d, a, b, inp[ 3], S23, 0xF4D50D87) # 27 + b = XX(G, b, c, d, a, inp[ 8], S24, 0x455A14ED) # 28 + a = XX(G, a, b, c, d, inp[13], S21, 0xA9E3E905) # 29 + d = XX(G, d, a, b, c, inp[ 2], S22, 0xFCEFA3F8) # 30 + c = XX(G, c, d, a, b, inp[ 7], S23, 0x676F02D9) # 31 + b = XX(G, b, c, d, a, inp[12], S24, 0x8D2A4C8A) # 32 # Round 3. S31, S32, S33, S34 = 4, 11, 16, 23 - a = XX(H, a, b, c, d, inp[ 5], S31, 0xFFFA3942L) # 33 - d = XX(H, d, a, b, c, inp[ 8], S32, 0x8771F681L) # 34 - c = XX(H, c, d, a, b, inp[11], S33, 0x6D9D6122L) # 35 - b = XX(H, b, c, d, a, inp[14], S34, 0xFDE5380CL) # 36 - a = XX(H, a, b, c, d, inp[ 1], S31, 0xA4BEEA44L) # 37 - d = XX(H, d, a, b, c, inp[ 4], S32, 0x4BDECFA9L) # 38 - c = XX(H, c, d, a, b, inp[ 7], S33, 0xF6BB4B60L) # 39 - b = XX(H, b, c, d, a, inp[10], S34, 0xBEBFBC70L) # 40 - a = XX(H, a, b, c, d, inp[13], S31, 0x289B7EC6L) # 41 - d = XX(H, d, a, b, c, inp[ 0], S32, 0xEAA127FAL) # 42 - c = XX(H, c, d, a, b, inp[ 3], S33, 0xD4EF3085L) # 43 - b = XX(H, b, c, d, a, inp[ 6], S34, 0x04881D05L) # 44 - a = XX(H, a, b, c, d, inp[ 9], S31, 0xD9D4D039L) # 45 - d = XX(H, d, a, b, c, inp[12], S32, 0xE6DB99E5L) # 46 - c = XX(H, c, d, a, b, inp[15], S33, 0x1FA27CF8L) # 47 - b = XX(H, b, c, d, a, inp[ 2], S34, 0xC4AC5665L) # 48 + a = XX(H, a, b, c, d, inp[ 5], S31, 0xFFFA3942) # 33 + d = XX(H, d, a, b, c, inp[ 8], S32, 0x8771F681) # 34 + c = XX(H, c, d, a, b, inp[11], S33, 0x6D9D6122) # 35 + b = XX(H, b, c, d, a, inp[14], S34, 0xFDE5380C) # 36 + a = XX(H, a, b, c, d, inp[ 1], S31, 0xA4BEEA44) # 37 + d = XX(H, d, a, b, c, inp[ 4], S32, 0x4BDECFA9) # 38 + c = XX(H, c, d, a, b, inp[ 7], S33, 0xF6BB4B60) # 39 + b = XX(H, b, c, d, a, inp[10], S34, 0xBEBFBC70) # 40 + a = XX(H, a, b, c, d, inp[13], S31, 0x289B7EC6) # 41 + d = XX(H, d, a, b, c, inp[ 0], S32, 0xEAA127FA) # 42 + c = XX(H, c, d, a, b, inp[ 3], S33, 0xD4EF3085) # 43 + b = XX(H, b, c, d, a, inp[ 6], S34, 0x04881D05) # 44 + a = XX(H, a, b, c, d, inp[ 9], S31, 0xD9D4D039) # 45 + d = XX(H, d, a, b, c, inp[12], S32, 0xE6DB99E5) # 46 + c = XX(H, c, d, a, b, inp[15], S33, 0x1FA27CF8) # 47 + b = XX(H, b, c, d, a, inp[ 2], S34, 0xC4AC5665) # 48 # Round 4. S41, S42, S43, S44 = 6, 10, 15, 21 - a = XX(I, a, b, c, d, inp[ 0], S41, 0xF4292244L) # 49 - d = XX(I, d, a, b, c, inp[ 7], S42, 0x432AFF97L) # 50 - c = XX(I, c, d, a, b, inp[14], S43, 0xAB9423A7L) # 51 - b = XX(I, b, c, d, a, inp[ 5], S44, 0xFC93A039L) # 52 - a = XX(I, a, b, c, d, inp[12], S41, 0x655B59C3L) # 53 - d = XX(I, d, a, b, c, inp[ 3], S42, 0x8F0CCC92L) # 54 - c = XX(I, c, d, a, b, inp[10], S43, 0xFFEFF47DL) # 55 - b = XX(I, b, c, d, a, inp[ 1], S44, 0x85845DD1L) # 56 - a = XX(I, a, b, c, d, inp[ 8], S41, 0x6FA87E4FL) # 57 - d = XX(I, d, a, b, c, inp[15], S42, 0xFE2CE6E0L) # 58 - c = XX(I, c, d, a, b, inp[ 6], S43, 0xA3014314L) # 59 - b = XX(I, b, c, d, a, inp[13], S44, 0x4E0811A1L) # 60 - a = XX(I, a, b, c, d, inp[ 4], S41, 0xF7537E82L) # 61 - d = XX(I, d, a, b, c, inp[11], S42, 0xBD3AF235L) # 62 - c = XX(I, c, d, a, b, inp[ 2], S43, 0x2AD7D2BBL) # 63 - b = XX(I, b, c, d, a, inp[ 9], S44, 0xEB86D391L) # 64 + a = XX(I, a, b, c, d, inp[ 0], S41, 0xF4292244) # 49 + d = XX(I, d, a, b, c, inp[ 7], S42, 0x432AFF97) # 50 + c = XX(I, c, d, a, b, inp[14], S43, 0xAB9423A7) # 51 + b = XX(I, b, c, d, a, inp[ 5], S44, 0xFC93A039) # 52 + a = XX(I, a, b, c, d, inp[12], S41, 0x655B59C3) # 53 + d = XX(I, d, a, b, c, inp[ 3], S42, 0x8F0CCC92) # 54 + c = XX(I, c, d, a, b, inp[10], S43, 0xFFEFF47D) # 55 + b = XX(I, b, c, d, a, inp[ 1], S44, 0x85845DD1) # 56 + a = XX(I, a, b, c, d, inp[ 8], S41, 0x6FA87E4F) # 57 + d = XX(I, d, a, b, c, inp[15], S42, 0xFE2CE6E0) # 58 + c = XX(I, c, d, a, b, inp[ 6], S43, 0xA3014314) # 59 + b = XX(I, b, c, d, a, inp[13], S44, 0x4E0811A1) # 60 + a = XX(I, a, b, c, d, inp[ 4], S41, 0xF7537E82) # 61 + d = XX(I, d, a, b, c, inp[11], S42, 0xBD3AF235) # 62 + c = XX(I, c, d, a, b, inp[ 2], S43, 0x2AD7D2BB) # 63 + b = XX(I, b, c, d, a, inp[ 9], S44, 0xEB86D391) # 64 - A = (A + a) & 0xffffffffL - B = (B + b) & 0xffffffffL - C = (C + c) & 0xffffffffL - D = (D + d) & 0xffffffffL + A = (A + a) & 0xffffffff + B = (B + b) & 0xffffffff + C = (C + c) & 0xffffffff + D = (D + d) & 0xffffffff self.A, self.B, self.C, self.D = A, B, C, D @@ -267,10 +267,10 @@ the hashed string. """ - leninBuf = long(len(inBuf)) + leninBuf = len(inBuf) # Compute number of bytes mod 64. - index = (self.count[0] >> 3) & 0x3FL + index = (self.count[0] >> 3) & 0x3F # Update number of bits. self.count[0] = self.count[0] + (leninBuf << 3) @@ -309,7 +309,7 @@ input = [] + self.input count = [] + self.count - index = (self.count[0] >> 3) & 0x3fL + index = (self.count[0] >> 3) & 0x3f if index < 56: padLen = 56 - index diff --git a/lib_pypy/_pypy_wait.py b/lib_pypy/_pypy_wait.py --- a/lib_pypy/_pypy_wait.py +++ b/lib_pypy/_pypy_wait.py @@ -1,6 +1,6 @@ +from resource import _struct_rusage, struct_rusage from ctypes import CDLL, c_int, POINTER, byref from ctypes.util import find_library -from resource import _struct_rusage, struct_rusage __all__ = ["wait3", "wait4"] diff --git a/lib_pypy/_sha.py b/lib_pypy/_sha.py --- a/lib_pypy/_sha.py +++ b/lib_pypy/_sha.py @@ -35,15 +35,15 @@ """ # After much testing, this algorithm was deemed to be the fastest. - s = '' + s = b'' pack = struct.pack while n > 0: - s = pack('>I', n & 0xffffffffL) + s + s = pack('>I', n & 0xffffffff) + s n = n >> 32 # Strip off leading zeros. for i in range(len(s)): - if s[i] <> '\000': + if s[i] != '\000': break else: # Only happens when n == 0. @@ -63,16 +63,16 @@ def _bytelist2longBigEndian(list): "Transform a list of characters into a list of longs." - imax = len(list)/4 - hl = [0L] * imax + imax = len(list) // 4 + hl = [0] * imax j = 0 i = 0 while i < imax: - b0 = long(ord(list[j])) << 24 - b1 = long(ord(list[j+1])) << 16 - b2 = long(ord(list[j+2])) << 8 - b3 = long(ord(list[j+3])) + b0 = ord(list[j]) << 24 + b1 = ord(list[j+1]) << 16 + b2 = ord(list[j+2]) << 8 + b3 = ord(list[j+3]) hl[i] = b0 | b1 | b2 | b3 i = i+1 j = j+4 @@ -108,10 +108,10 @@ # Constants to be used K = [ - 0x5A827999L, # ( 0 <= t <= 19) - 0x6ED9EBA1L, # (20 <= t <= 39) - 0x8F1BBCDCL, # (40 <= t <= 59) - 0xCA62C1D6L # (60 <= t <= 79) + 0x5A827999, # ( 0 <= t <= 19) + 0x6ED9EBA1, # (20 <= t <= 39) + 0x8F1BBCDC, # (40 <= t <= 59) + 0xCA62C1D6 # (60 <= t <= 79) ] class sha: @@ -124,7 +124,7 @@ "Initialisation." # Initial message length in bits(!). - self.length = 0L + self.length = 0 self.count = [0, 0] # Initial empty message as a sequence of bytes (8 bit characters). @@ -138,21 +138,21 @@ def init(self): "Initialize the message-digest and set all fields to zero." - self.length = 0L + self.length = 0 self.input = [] # Initial 160 bit message digest (5 times 32 bit). - self.H0 = 0x67452301L - self.H1 = 0xEFCDAB89L - self.H2 = 0x98BADCFEL - self.H3 = 0x10325476L - self.H4 = 0xC3D2E1F0L + self.H0 = 0x67452301 + self.H1 = 0xEFCDAB89 + self.H2 = 0x98BADCFE + self.H3 = 0x10325476 + self.H4 = 0xC3D2E1F0 def _transform(self, W): for t in range(16, 80): W.append(_rotateLeft( - W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1) & 0xffffffffL) + W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16], 1) & 0xffffffff) A = self.H0 B = self.H1 @@ -166,49 +166,49 @@ TEMP = _rotateLeft(A, 5) + f[t/20] + E + W[t] + K[t/20] E = D D = C - C = _rotateLeft(B, 30) & 0xffffffffL + C = _rotateLeft(B, 30) & 0xffffffff B = A - A = TEMP & 0xffffffffL + A = TEMP & 0xffffffff """ for t in range(0, 20): TEMP = _rotateLeft(A, 5) + ((B & C) | ((~ B) & D)) + E + W[t] + K[0] E = D D = C - C = _rotateLeft(B, 30) & 0xffffffffL + C = _rotateLeft(B, 30) & 0xffffffff B = A - A = TEMP & 0xffffffffL + A = TEMP & 0xffffffff for t in range(20, 40): TEMP = _rotateLeft(A, 5) + (B ^ C ^ D) + E + W[t] + K[1] E = D D = C - C = _rotateLeft(B, 30) & 0xffffffffL + C = _rotateLeft(B, 30) & 0xffffffff B = A - A = TEMP & 0xffffffffL + A = TEMP & 0xffffffff for t in range(40, 60): TEMP = _rotateLeft(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2] E = D D = C - C = _rotateLeft(B, 30) & 0xffffffffL + C = _rotateLeft(B, 30) & 0xffffffff B = A - A = TEMP & 0xffffffffL + A = TEMP & 0xffffffff for t in range(60, 80): TEMP = _rotateLeft(A, 5) + (B ^ C ^ D) + E + W[t] + K[3] E = D D = C - C = _rotateLeft(B, 30) & 0xffffffffL + C = _rotateLeft(B, 30) & 0xffffffff B = A - A = TEMP & 0xffffffffL + A = TEMP & 0xffffffff - self.H0 = (self.H0 + A) & 0xffffffffL - self.H1 = (self.H1 + B) & 0xffffffffL - self.H2 = (self.H2 + C) & 0xffffffffL - self.H3 = (self.H3 + D) & 0xffffffffL - self.H4 = (self.H4 + E) & 0xffffffffL + self.H0 = (self.H0 + A) & 0xffffffff + self.H1 = (self.H1 + B) & 0xffffffff + self.H2 = (self.H2 + C) & 0xffffffff + self.H3 = (self.H3 + D) & 0xffffffff + self.H4 = (self.H4 + E) & 0xffffffff # Down from here all methods follow the Python Standard Library @@ -230,10 +230,10 @@ to the hashed string. """ - leninBuf = long(len(inBuf)) + leninBuf = len(inBuf) # Compute number of bytes mod 64. - index = (self.count[1] >> 3) & 0x3FL + index = (self.count[1] >> 3) & 0x3F # Update number of bits. self.count[1] = self.count[1] + (leninBuf << 3) @@ -273,7 +273,7 @@ input = [] + self.input count = [] + self.count - index = (self.count[1] >> 3) & 0x3fL + index = (self.count[1] >> 3) & 0x3f if index < 56: padLen = 56 - index diff --git a/lib_pypy/_sha512.py b/lib_pypy/_sha512.py --- a/lib_pypy/_sha512.py +++ b/lib_pypy/_sha512.py @@ -10,7 +10,7 @@ def new_shaobject(): return { - 'digest': [0L]*8, + 'digest': [0]*8, 'count_lo': 0, 'count_hi': 0, 'data': [0]* SHA_BLOCKSIZE, diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -1219,6 +1219,7 @@ val = None elif typ == _lib.SQLITE_INTEGER: val = _lib.sqlite3_column_int64(self._statement, i) + val = int(val) elif typ == _lib.SQLITE_FLOAT: val = _lib.sqlite3_column_double(self._statement, i) elif typ == _lib.SQLITE_TEXT: @@ -1342,6 +1343,7 @@ val = None elif typ == _lib.SQLITE_INTEGER: val = _lib.sqlite3_value_int64(params[i]) + val = int(val) elif typ == _lib.SQLITE_FLOAT: val = _lib.sqlite3_value_double(params[i]) elif typ == _lib.SQLITE_TEXT: diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py --- a/lib_pypy/cPickle.py +++ b/lib_pypy/cPickle.py @@ -225,10 +225,7 @@ elif data == TRUE[1:]: val = True else: - try: - val = int(data) - except ValueError: - val = long(data) + val = int(data) self.append(val) dispatch[INT] = load_int diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -16,14 +16,20 @@ Thanks to Tim Peters for suggesting using it. """ +from __future__ import division import time as _time import math as _math +import struct as _struct + +def _cmp(x, y): + return 0 if x == y else 1 if x > y else -1 def _round(x): return _math.floor(x + 0.5) if x >= 0.0 else _math.ceil(x - 0.5) MINYEAR = 1 MAXYEAR = 9999 +_MINYEARFMT = 1900 # Utility functions, adapted from Python's Demo/classes/Dates.py, which # also assumes the current Gregorian calendar indefinitely extended in @@ -172,13 +178,14 @@ # Correctly substitute for %z and %Z escapes in strftime formats. def _wrap_strftime(object, format, timetuple): year = timetuple[0] - if year < 1900: - raise ValueError("year=%d is before 1900; the datetime strftime() " - "methods require year >= 1900" % year) - # Don't call _utcoffset() or tzname() unless actually needed. - freplace = None # the string to use for %f - zreplace = None # the string to use for %z - Zreplace = None # the string to use for %Z + if year < _MINYEARFMT: + raise ValueError("year=%d is before %d; the datetime strftime() " + "methods require year >= %d" % + (year, _MINYEARFMT, _MINYEARFMT)) + # Don't call utcoffset() or tzname() unless actually needed. + freplace = None # the string to use for %f + zreplace = None # the string to use for %z + Zreplace = None # the string to use for %Z # Scan format for %z and %Z escapes, replacing as needed. newformat = [] @@ -263,9 +270,9 @@ raise ValueError("tzinfo.%s() must return a whole number " "of minutes" % name) offset = minutes - if -1440 < offset < 1440: - return offset - raise ValueError("%s()=%d, must be in -1439..1439" % (name, offset)) + if not -1440 < offset < 1440: + raise ValueError("%s()=%d, must be in -1439..1439" % (name, offset)) + return offset def _check_int_field(value): if isinstance(value, int): @@ -571,7 +578,7 @@ def total_seconds(self): """Total seconds in the duration.""" return ((self.days * 86400 + self.seconds) * 10**6 + - self.microseconds) / 1e6 + self.microseconds) / 10**6 # Read-only field accessors @property @@ -641,12 +648,15 @@ __rmul__ = __mul__ + def _to_microseconds(self): + return ((self._days * (24*3600) + self._seconds) * 1000000 + + self._microseconds) + def __div__(self, other): - if isinstance(other, (int, long)): - usec = ((self._days * (24*3600L) + self._seconds) * 1000000 + - self._microseconds) - return timedelta(0, 0, usec // other) - return NotImplemented + if not isinstance(other, (int, long)): + return NotImplemented + usec = self._to_microseconds() + return timedelta(0, 0, usec // other) __floordiv__ = __div__ @@ -690,7 +700,7 @@ def _cmp(self, other): assert isinstance(other, timedelta) - return cmp(self._getstate(), other._getstate()) + return _cmp(self._getstate(), other._getstate()) def __hash__(self): return hash(self._getstate()) @@ -750,7 +760,8 @@ year, month, day (required, base 1) """ - if isinstance(year, str) and len(year) == 4: + if month is None and isinstance(year, bytes) and len(year) == 4 and \ + 1 <= ord(year[2]) <= 12: # Pickle support self = object.__new__(cls) self.__setstate(year) @@ -938,7 +949,7 @@ assert isinstance(other, date) y, m, d = self._year, self._month, self._day y2, m2, d2 = other._year, other._month, other._day - return cmp((y, m, d), (y2, m2, d2)) + return _cmp((y, m, d), (y2, m2, d2)) def __hash__(self): "Hash." @@ -1016,13 +1027,12 @@ def _getstate(self): yhi, ylo = divmod(self._year, 256) - return ("%c%c%c%c" % (yhi, ylo, self._month, self._day), ) + return (_struct.pack('4B', yhi, ylo, self._month, self._day),) def __setstate(self, string): - if len(string) != 4 or not (1 <= ord(string[2]) <= 12): - raise TypeError("not enough arguments") - self._month, self._day = ord(string[2]), ord(string[3]) - self._year = ord(string[0]) * 256 + ord(string[1]) + yhi, ylo, self._month, self._day = (ord(string[0]), ord(string[1]), + ord(string[2]), ord(string[3])) + self._year = yhi * 256 + ylo def __reduce__(self): return (self.__class__, self._getstate()) @@ -1140,7 +1150,7 @@ second, microsecond (default to zero) tzinfo (default to None) """ - if isinstance(hour, str): + if isinstance(hour, bytes) and len(hour) == 6 and ord(hour[0]) < 24: # Pickle support self = object.__new__(cls) self.__setstate(hour, minute or None) @@ -1235,21 +1245,21 @@ base_compare = myoff == otoff if base_compare: - return cmp((self._hour, self._minute, self._second, - self._microsecond), - (other._hour, other._minute, other._second, - other._microsecond)) + return _cmp((self._hour, self._minute, self._second, + self._microsecond), + (other._hour, other._minute, other._second, + other._microsecond)) if myoff is None or otoff is None: raise TypeError("cannot compare naive and aware times") myhhmm = self._hour * 60 + self._minute - myoff othhmm = other._hour * 60 + other._minute - otoff - return cmp((myhhmm, self._second, self._microsecond), - (othhmm, other._second, other._microsecond)) + return _cmp((myhhmm, self._second, self._microsecond), + (othhmm, other._second, other._microsecond)) def __hash__(self): """Hash.""" tzoff = self._utcoffset() - if not tzoff: # zero or None + if not tzoff: # zero or None return hash(self._getstate()[0]) h, m = divmod(self.hour * 60 + self.minute - tzoff, 60) if 0 <= h < 24: @@ -1306,7 +1316,7 @@ """Format using strftime(). The date part of the timestamp passed to underlying strftime should not be used. """ - # The year must be >= 1900 else Python's strftime implementation + # The year must be >= _MINYEARFMT else Python's strftime implementation # can raise a bogus exception. timetuple = (1900, 1, 1, self._hour, self._minute, self._second, @@ -1389,29 +1399,27 @@ def __nonzero__(self): if self.second or self.microsecond: - return 1 + return True offset = self._utcoffset() or 0 - return self.hour * 60 + self.minute - offset != 0 + return self.hour * 60 + self.minute != offset # Pickle support. def _getstate(self): us2, us3 = divmod(self._microsecond, 256) us1, us2 = divmod(us2, 256) - basestate = ("%c" * 6) % (self._hour, self._minute, self._second, - us1, us2, us3) + basestate = _struct.pack('6B', self._hour, self._minute, self._second, + us1, us2, us3) if self._tzinfo is None: return (basestate,) else: return (basestate, self._tzinfo) def __setstate(self, string, tzinfo): - if len(string) != 6 or ord(string[0]) >= 24: - raise TypeError("an integer is required") - self._hour, self._minute, self._second = ord(string[0]), \ - ord(string[1]), ord(string[2]) - self._microsecond = (((ord(string[3]) << 8) | \ - ord(string[4])) << 8) | ord(string[5]) + self._hour, self._minute, self._second, us1, us2, us3 = ( + ord(string[0]), ord(string[1]), ord(string[2]), + ord(string[3]), ord(string[4]), ord(string[5])) + self._microsecond = (((us1 << 8) | us2) << 8) | us3 self._tzinfo = tzinfo def __reduce__(self): @@ -1433,7 +1441,8 @@ def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0, microsecond=0, tzinfo=None): - if isinstance(year, str) and len(year) == 10: + if isinstance(year, bytes) and len(year) == 10 and \ + 1 <= ord(year[2]) <= 12: # Pickle support self = date.__new__(cls, year[:4]) self.__setstate(year, month) @@ -1608,8 +1617,8 @@ year, month, day = _check_date_fields(year, month, day) hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond) _check_tzinfo_arg(tzinfo) - return datetime(year, month, day, hour, minute, second, - microsecond, tzinfo) + return datetime(year, month, day, hour, minute, second, microsecond, + tzinfo) def astimezone(self, tz): if not isinstance(tz, tzinfo): @@ -1655,10 +1664,9 @@ Optional argument sep specifies the separator between date and time, default 'T'. """ - s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, - sep) + - _format_time(self._hour, self._minute, self._second, - self._microsecond)) + s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) + + _format_time(self._hour, self._minute, self._second, + self._microsecond)) off = self._utcoffset() if off is not None: if off < 0: @@ -1672,7 +1680,7 @@ def __repr__(self): """Convert to formal string, for repr().""" - L = [self._year, self._month, self._day, # These are never zero + L = [self._year, self._month, self._day, # These are never zero self._hour, self._minute, self._second, self._microsecond] if L[-1] == 0: del L[-1] @@ -1812,12 +1820,12 @@ base_compare = myoff == otoff if base_compare: - return cmp((self._year, self._month, self._day, - self._hour, self._minute, self._second, - self._microsecond), - (other._year, other._month, other._day, - other._hour, other._minute, other._second, - other._microsecond)) + return _cmp((self._year, self._month, self._day, + self._hour, self._minute, self._second, + self._microsecond), + (other._year, other._month, other._day, + other._hour, other._minute, other._second, + other._microsecond)) if myoff is None or otoff is None: raise TypeError("cannot compare naive and aware datetimes") # XXX What follows could be done more efficiently... @@ -1883,20 +1891,22 @@ yhi, ylo = divmod(self._year, 256) us2, us3 = divmod(self._microsecond, 256) us1, us2 = divmod(us2, 256) - basestate = ("%c" * 10) % (yhi, ylo, self._month, self._day, - self._hour, self._minute, self._second, - us1, us2, us3) + basestate = _struct.pack('10B', yhi, ylo, self._month, self._day, + self._hour, self._minute, self._second, + us1, us2, us3) if self._tzinfo is None: return (basestate,) else: return (basestate, self._tzinfo) def __setstate(self, string, tzinfo): - (self._month, self._day, self._hour, self._minute, - self._second) = (ord(string[2]), ord(string[3]), ord(string[4]), - ord(string[5]), ord(string[6])) - self._year = ord(string[0]) * 256 + ord(string[1]) - self._microsecond = (((ord(string[7]) << 8) | ord(string[8])) << 8) | ord(string[9]) + (yhi, ylo, self._month, self._day, self._hour, + self._minute, self._second, us1, us2, us3) = (ord(string[0]), + ord(string[1]), ord(string[2]), ord(string[3]), + ord(string[4]), ord(string[5]), ord(string[6]), + ord(string[7]), ord(string[8]), ord(string[9])) + self._year = yhi * 256 + ylo + self._microsecond = (((us1 << 8) | us2) << 8) | us3 self._tzinfo = tzinfo def __reduce__(self): @@ -1913,7 +1923,7 @@ # XXX This could be done more efficiently THURSDAY = 3 firstday = _ymd2ord(year, 1, 1) - firstweekday = (firstday + 6) % 7 # See weekday() above + firstweekday = (firstday + 6) % 7 # See weekday() above week1monday = firstday - firstweekday if firstweekday > THURSDAY: week1monday += 7 diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py --- a/lib_pypy/greenlet.py +++ b/lib_pypy/greenlet.py @@ -111,7 +111,7 @@ # Internal stuff try: - from thread import _local + from threading import local as _local except ImportError: class _local(object): # assume no threads pass diff --git a/lib_pypy/grp.py b/lib_pypy/grp.py --- a/lib_pypy/grp.py +++ b/lib_pypy/grp.py @@ -59,6 +59,12 @@ libc.getgrent.argtypes = [] libc.getgrent.restype = POINTER(GroupStruct) +libc.setgrent.argtypes = [] +libc.setgrent.restype = None + +libc.endgrent.argtypes = [] +libc.endgrent.restype = None + def _group_from_gstruct(res): i = 0 mem = [] diff --git a/lib_pypy/stackless.py b/lib_pypy/stackless.py --- a/lib_pypy/stackless.py +++ b/lib_pypy/stackless.py @@ -93,7 +93,7 @@ try: - from thread import _local + from threading import local as _local except ImportError: class _local(object): # assume no threads pass @@ -433,16 +433,16 @@ def insert(self): if self.blocked: - raise RuntimeError, "You cannot run a blocked tasklet" + raise RuntimeError("You cannot run a blocked tasklet") if not self.alive: - raise RuntimeError, "You cannot run an unbound(dead) tasklet" + raise RuntimeError("You cannot run an unbound(dead) tasklet") _scheduler_append(self) def remove(self): if self.blocked: - raise RuntimeError, "You cannot remove a blocked tasklet." + raise RuntimeError("You cannot remove a blocked tasklet.") if self is getcurrent(): - raise RuntimeError, "The current tasklet cannot be removed." + raise RuntimeError("The current tasklet cannot be removed.") # not sure if I will revive this " Use t=tasklet().capture()" _scheduler_remove(self) diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -4281,6 +4281,35 @@ """ self.optimize_loop(ops, expected) + def test_add_sub_ovf_second_operation_regular(self): + py.test.skip("Smalltalk would like this to pass") + # This situation occurs in Smalltalk because it uses 1-based indexing. + # The below code is equivalent to a loop over an array. + ops = """ + [i1] + i2 = int_sub(i1, 1) + escape(i2) + i3 = int_add_ovf(i1, 1) + guard_no_overflow() [] + jump(i3) + """ + preamble = """ + [i1] + i2 = int_sub(i1, 1) + escape(i2) + i3 = int_add_ovf(i1, 1) + guard_no_overflow() [] + jump(i3, i1) + """ + expected = """ + [i1, i2] + escape(i2) + i3 = int_add_ovf(i1, 1) + guard_no_overflow() [] + jump(i3, i1) + """ + self.optimize_loop(ops, expected, preamble) + def test_add_sub_ovf_virtual_unroll(self): ops = """ [p15] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit