[pypy-commit] pypy py3.3: Merge
Arjun Naik
noreply at buildbot.pypy.org
Sat Jul 26 15:54:10 CEST 2014
Author: Arjun Naik <arjun at arjunnaik.in>
Branch: py3.3
Changeset: r72515:2c99b4f912ad
Date: 2014-07-26 15:52 +0200
http://bitbucket.org/pypy/pypy/changeset/2c99b4f912ad/
Log: Merge
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -317,7 +317,6 @@
# Order is significant!
sys_flags = (
"debug",
- "division_warning",
"inspect",
"interactive",
"optimize",
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -711,6 +711,13 @@
if pred ^ self.reverse:
return w_obj
+ def descr_reduce(self, space):
+ w_filter = space.getattr(space.getbuiltinmodule('builtins'),
+ space.wrap('filter'))
+ args = [space.w_None if self.no_predicate else self.w_predicate,
+ self.iterable]
+ return space.newtuple([w_filter, space.newtuple(args)])
+
def W_Filter___new__(space, w_subtype, w_predicate, w_iterable):
r = space.allocate_instance(W_Filter, w_subtype)
@@ -722,6 +729,7 @@
__new__ = interp2app(W_Filter___new__),
__iter__ = interp2app(W_Filter.iter_w),
__next__ = interp2app(W_Filter.next_w),
+ __reduce__ = interp2app(W_Filter.descr_reduce),
__doc__ = """\
Return an iterator yielding those items of iterable for which function(item)
is true. If function is None, return the items that are true.""")
diff --git a/pypy/module/__builtin__/test/test_filter_pickle.py b/pypy/module/__builtin__/test/test_filter_pickle.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/test/test_filter_pickle.py
@@ -0,0 +1,72 @@
+class AppTestFilterPickle:
+
+ def test_filter_unpickle(self):
+ """Test just the unpickling."""
+ import pickle
+
+ # This is filter(None, 'abc') pickled with cpython
+ dump = b'\x80\x03cbuiltins\nfilter\nq\x00Ncbuiltins\niter\nq\x01X\x03'\
+ b'\x00\x00\x00abcq\x02\x85q\x03Rq\x04K\x00b\x86q\x05Rq\x06.'
+ t = pickle.loads(dump)
+ assert list(t) == ['a', 'b', 'c']
+
+ def test_iterator_pickle(self):
+ """Pickle and unpickle just a simple iterator."""
+ import pickle
+
+ i0 = iter("abc")
+ i1 = iter("abc")
+
+ d = pickle.dumps(i1)
+ i1 = pickle.loads(d)
+
+ assert list(i0) == list(i1)
+
+ def test_reduce_ex(self):
+ """"""
+ f0 = filter(None, "abc")
+ f1 = filter(None, "abc")
+
+ print(f0)
+ r = f1.__reduce_ex__(3)
+ # __reduce_ex__ doesn't return any arguments to the filter, so the next
+ # line will fail with TypeError.
+ f1 = r[0](*r[1])
+
+ assert list(f0) == list(f1)
+
+ def test_nonfilter_pickle(self):
+ """Pickle and unpickle a filter with no filtering."""
+ import pickle
+
+ f0 = filter(None, "abc")
+ d = pickle.dumps(f0)
+ f1 = pickle.loads(d)
+
+ def test_filter_pickle(self):
+ """Clone of the original test."""
+ import pickle
+
+ def check_iter_pickle(it, seq):
+ itorg = it
+ d = pickle.dumps(it)
+ it = pickle.loads(d)
+ assert type(itorg) == type(it)
+ assert list(it) == seq
+
+ #test the iterator after dropping one from it
+ it = pickle.loads(d)
+ try:
+ next(it)
+ except StopIteration:
+ return
+ d = pickle.dumps(it)
+ it = pickle.loads(d)
+ assert list(it) == seq[1:]
+
+ # We use ord instead of filter_char because the filter function has to
+ # be defined in the global scope for the picking to work and we can't
+ # do it from this test.
+ f1 = filter(ord, "abcdeabcde")
+ f2 = filter(ord, "abcdeabcde")
+ check_iter_pickle(f1, list(f2))
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -94,20 +94,19 @@
name = "sys.flags"
debug = structseqfield(0)
- division_warning = structseqfield(1)
- inspect = structseqfield(2)
- interactive = structseqfield(3)
- optimize = structseqfield(4)
- dont_write_bytecode = structseqfield(5)
- no_user_site = structseqfield(6)
- no_site = structseqfield(7)
- ignore_environment = structseqfield(8)
- verbose = structseqfield(9)
- bytes_warning = structseqfield(10)
- quiet = structseqfield(11)
- hash_randomization = structseqfield(12)
+ inspect = structseqfield(1)
+ interactive = structseqfield(2)
+ optimize = structseqfield(3)
+ dont_write_bytecode = structseqfield(4)
+ no_user_site = structseqfield(5)
+ no_site = structseqfield(6)
+ ignore_environment = structseqfield(7)
+ verbose = structseqfield(8)
+ bytes_warning = structseqfield(9)
+ quiet = structseqfield(10)
+ hash_randomization = structseqfield(11)
-null_sysflags = sysflags((0,)*13)
+null_sysflags = sysflags((0,)*12)
null__xoptions = {}
diff --git a/pypy/module/zlib/test/test_zlib.py b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -177,6 +177,16 @@
assert dco.eof == True
dco.flush()
assert dco.eof == True
+
+ def test_decompress_eof_incomplete_stream(self):
+ import zlib
+ x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E' # 'foo'
+ dco = zlib.decompressobj()
+ assert dco.eof == False
+ dco.decompress(x[:-5])
+ assert dco.eof == False
+ dco.flush()
+ assert dco.eof == False
def test_decompress_incomplete_stream(self):
import zlib
More information about the pypy-commit
mailing list