Author: Matti Picus <[email protected]>
Branch: win32-stdlib
Changeset: r55030:24e9d3884170
Date: 2012-05-11 11:41 +0300
http://bitbucket.org/pypy/pypy/changeset/24e9d3884170/

Log:    fix merges

diff --git a/lib-python/2.7/mailbox.py b/lib-python/2.7/mailbox.py
--- a/lib-python/2.7/mailbox.py
+++ b/lib-python/2.7/mailbox.py
@@ -19,6 +19,7 @@
 import email.message
 import email.generator
 import StringIO
+import contextlib
 try:
     if sys.platform == 'os2emx':
         # OS/2 EMX fcntl() not adequate
@@ -81,8 +82,7 @@
         if not self._factory:
             return self.get_message(key)
         else:
-            with contextlib.closing(self.get_file(key)) as file:
-                return self._factory(file)
+               return self._factory(self.get_file(key))
 
     def get_message(self, key):
         """Return a Message representation or raise a KeyError."""
@@ -1933,12 +1933,6 @@
             size = remaining
         return _ProxyFile._read(self, size, read_method)
 
-    def close(self):
-        # do *not* close the underlying file object for partial files,
-        # since it's global to the mailbox object
-        if hasattr(self, '_file'):
-            del self._file
-
 
 def _lock_file(f, dotlock=True):
     """Lock file f using lockf and dot locking."""
diff --git a/lib-python/2.7/test/test_mailbox.py 
b/lib-python/2.7/test/test_mailbox.py
--- a/lib-python/2.7/test/test_mailbox.py
+++ b/lib-python/2.7/test/test_mailbox.py
@@ -240,7 +240,11 @@
 
     def test_contains(self):
         # Check existence of keys using __contains__()
-        self.assertNotIn('foo', self._box)
+        self._test_has_key_or_contains(self._box.__contains__)
+
+    def _test_has_key_or_contains(self, method):
+        # (Used by test_has_key() and test_contains().)
+        self.assertFalse(method('foo'))
         key0 = self._box.add(self._template % 0)
         self.assertTrue(method(key0))
         self.assertFalse(method('foo'))
@@ -837,17 +841,15 @@
             return
         pid = os.fork()
         if pid == 0:
-            # child
-            try:
-                # lock the mailbox, and signal the parent it can proceed
-                self._box.lock()
-                time.sleep(2)
-                self._box.unlock()
-            finally:
-                os._exit(0)
-
-        # In the parent, wait until the child signals it locked the mailbox.
-        p.recv(1)
+            # In the child, lock the mailbox.
+            self._box.lock()
+            time.sleep(2)
+            self._box.unlock()
+            os._exit(0)
+ 
+        # In the parent, sleep a bit to give the child time to acquire
+        # the lock.
+        time.sleep(0.5)
         try:
             self.assertRaises(mailbox.ExternalClashError,
                               self._box.lock)
diff --git a/lib-python/2.7/test/test_tarfile.py 
b/lib-python/2.7/test/test_tarfile.py
--- a/lib-python/2.7/test/test_tarfile.py
+++ b/lib-python/2.7/test/test_tarfile.py
@@ -65,10 +65,8 @@
         tarinfo = self.tar.getmember("ustar/regtype")
         with open(os.path.join(TEMPDIR, "ustar/regtype"), "rU") as fobj1:
             lines1 = fobj1.readlines()
-
-        fobj = self.tar.extractfile(tarinfo)
+        fobj2 = self.tar.extractfile(tarinfo)
         try:
-            fobj2 = io.TextIOWrapper(fobj)
             lines2 = fobj2.readlines()
             self.assertTrue(lines1 == lines2,
                     "fileobj.readlines() failed")
@@ -78,7 +76,7 @@
                     "I will gladly admit that Python is not the fastest 
running scripting language.\n",
                     "fileobj.readlines() failed")
         finally:
-            fobj.close()
+            fobj2.close()
 
     def test_fileobj_iter(self):
         self.tar.extract("ustar/regtype", TEMPDIR)
@@ -323,7 +321,8 @@
 
     @unittest.skipUnless(hasattr(os, "link"),
                          "Missing hardlink implementation")
-    @support.skip_unless_symlink
+    @unittest.skipUnless(hasattr(os, "symlink"),
+                         "Missing symlink implementation")
     def test_extract_hardlink(self):
         # Test hardlink extraction (e.g. bug #857297).
         tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1")
@@ -642,6 +641,8 @@
             self.assertEqual(tarinfo.uname, "tarfile")
             self.assertEqual(tarinfo.gname, "tarfile")
             self.assertEqual(tarinfo.pax_headers.get("VENDOR.umlauts"), 
u"&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;")
+        finally:
+            tar.close()
 
     def test_pax_number_fields(self):
         # All following number fields are read from the pax header.
@@ -758,7 +759,8 @@
                 os.remove(target)
                 os.remove(link)
 
-    @support.skip_unless_symlink
+    @unittest.skipUnless(hasattr(os, "symlink"),
+                         "Missing symlink implementation")
     def test_symlink_size(self):
         path = os.path.join(TEMPDIR, "symlink")
         os.symlink("link_target", path)
@@ -801,7 +803,7 @@
 
             tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1")
             try:
-                with support.check_warnings(("use the filter argument",
+                with test_support.check_warnings(("use the filter argument",
                                              DeprecationWarning)):
                     tar.add(tempdir, arcname="empty_dir", exclude=exclude)
             finally:
@@ -919,6 +921,7 @@
             try:
                 for t in tar:
                     self.assert_(t.name == "." or t.name.startswith("./"))
+            finally:
                 tar.close()
         finally:
             os.chdir(cwd)
@@ -1358,7 +1361,7 @@
             t = tarfile.TarInfo()
             t.pax_headers["path"] = name
             tar.addfile(t)
-       finally:
+        finally:
             tar.close()
 
     def test_error_handlers(self):
diff --git a/lib-python/2.7/test/test_zipfile.py 
b/lib-python/2.7/test/test_zipfile.py
--- a/lib-python/2.7/test/test_zipfile.py
+++ b/lib-python/2.7/test/test_zipfile.py
@@ -1288,16 +1288,16 @@
             for sep, fn in self.arcfiles.items():
                 with zipfp.open(fn, "rU") as zipopen:
                     data = ''
-                while True:
-                    read = zipopen.readline()
-                    if not read:
-                        break
-                    data += read
+                    while True:
+                        read = zipopen.readline()
+                        if not read:
+                            break
+                        data += read
 
-                    read = zipopen.read(5)
-                    if not read:
-                        break
-                    data += read
+                        read = zipopen.read(5)
+                        if not read:
+                            break
+                        data += read
 
             self.assertEqual(data, self.arcdata['\n'])
 
diff --git a/lib-python/2.7/zipfile.py b/lib-python/2.7/zipfile.py
--- a/lib-python/2.7/zipfile.py
+++ b/lib-python/2.7/zipfile.py
@@ -473,7 +473,8 @@
     # Search for universal newlines or line chunks.
     PATTERN = re.compile(r'^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)')
 
-    def __init__(self, fileobj, mode, zipinfo, decrypter=None):
+    def __init__(self, fileobj, mode, zipinfo, decrypter=None,
+                 close_fileobj=False):
         self._fileobj = fileobj
         self._decrypter = decrypter
         self._close_fileobj = close_fileobj
@@ -653,7 +654,7 @@
             if self._close_fileobj:
                 self._fileobj.close()
         finally:
-            super().close()
+            super(io.BufferedIOBase, self).close()
 
 
 class ZipFile:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to