[pypy-commit] pypy stdlib-2.7.8: merged upstream

alex_gaynor noreply at buildbot.pypy.org
Sun Aug 24 19:38:40 CEST 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: stdlib-2.7.8
Changeset: r73032:b4661fbba593
Date: 2014-08-24 10:38 -0700
http://bitbucket.org/pypy/pypy/changeset/b4661fbba593/

Log:	merged upstream

diff --git a/pypy/module/_file/test/test_file.py b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -261,6 +261,17 @@
         with self.file(self.temppath, 'r') as f:
             raises(IOError, f.truncate, 100)
 
+    def test_write_full(self):
+        try:
+            f = self.file('/dev/full', 'w', 1)
+        except IOError:
+            skip("requires '/dev/full'")
+        try:
+            f.write('hello')
+            raises(IOError, f.write, '\n')
+        finally:
+            f.close()
+
 
 class AppTestNonblocking(object):
     def setup_class(cls):
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -200,6 +200,46 @@
                     self.mmap.setitem(start, value[i])
                     start += step
 
+    def descr_getslice(self, space, w_ilow, w_ihigh):
+        self.check_valid()
+        i = space.getindex_w(w_ilow, None)
+        j = space.getindex_w(w_ihigh, None)
+        if i < 0:
+            i = 0
+        elif i > self.mmap.size:
+            i = self.mmap.size
+        if j < 0:
+            j = 0
+        if j < i:
+            j = i
+        elif j > self.mmap.size:
+            j = self.mmap.size
+        return space.wrap(self.mmap.getslice(i, (j - i)))
+
+    def descr_setslice(self, space, w_ilow, w_ihigh, w_item):
+        self.check_valid()
+        i = space.getindex_w(w_ilow, None)
+        j = space.getindex_w(w_ihigh, None)
+        if i < 0:
+            i = 0
+        elif i > self.mmap.size:
+            i = self.mmap.size
+        if j < 0:
+            j = 0
+        if j < i:
+            j = i
+        elif j > self.mmap.size:
+            j = self.mmap.size
+        if not space.isinstance_w(w_item, space.w_str):
+            raise OperationError(space.w_IndexError, space.wrap(
+                "mmap slice assignment must be a string"))
+        value = space.realstr_w(w_item)
+        if len(value) != (j - i):
+            raise OperationError(space.w_IndexError, space.wrap(
+                "mmap slice assignment is wrong size"))
+        self.check_writeable()
+        self.mmap.setslice(i, value)
+
 if rmmap._POSIX:
 
     @unwrap_spec(fileno=int, length=int, flags=int,
@@ -255,6 +295,8 @@
     __len__ = interp2app(W_MMap.__len__),
     __getitem__ = interp2app(W_MMap.descr_getitem),
     __setitem__ = interp2app(W_MMap.descr_setitem),
+    __getslice__ = interp2app(W_MMap.descr_getslice),
+    __setslice__ = interp2app(W_MMap.descr_setslice),
 )
 
 constants = rmmap.constants
diff --git a/pypy/module/mmap/test/test_mmap.py b/pypy/module/mmap/test/test_mmap.py
--- a/pypy/module/mmap/test/test_mmap.py
+++ b/pypy/module/mmap/test/test_mmap.py
@@ -524,6 +524,11 @@
         f.seek(0)
         m = mmap(f.fileno(), 6)
         assert m[-3:7] == "bar"
+        assert m.__getslice__(-3, 7) == "foobar"
+        m.__setslice__(2, 4, "zz")
+        assert m.__getslice__(-3, 7) == "fozzar"
+        raises(TypeError, m.__getslice__, "abc", 2)
+        raises(IndexError, m.__setslice__, 2, 4, None)
 
         assert m[1:0:1] == ""
 
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -316,6 +316,13 @@
         exc = raises(IOError, os.fdopen, fd, 'r')
         assert exc.value.errno == errno.EISDIR
 
+    def test_fdopen_keeps_fd_open_on_errors(self):
+        path = self.path
+        posix = self.posix
+        fd = posix.open(path, posix.O_RDONLY)
+        raises(OSError, posix.fdopen, fd, 'w')
+        posix.close(fd)  # fd should not be closed
+
     def test_getcwd(self):
         assert isinstance(self.posix.getcwd(), str)
         assert isinstance(self.posix.getcwdu(), unicode)


More information about the pypy-commit mailing list