[Python-3000-checkins] r61535 - in python/branches/py3k: Lib/shutil.py Lib/test/test_errno.py Lib/test/test_shutil.py Makefile.pre.in Modules/_fileio.c Modules/main.c Modules/posixmodule.c Modules/socketmodule.c Tools/scripts Tools/scripts/patchcheck.py Tools/scripts/reindent.py

christian.heimes python-3000-checkins at python.org
Tue Mar 18 19:27:03 CET 2008


Author: christian.heimes
Date: Tue Mar 18 19:26:33 2008
New Revision: 61535

Added:
   python/branches/py3k/Tools/scripts/patchcheck.py
      - copied, changed from r61528, python/trunk/Tools/scripts/patchcheck.py
Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/shutil.py
   python/branches/py3k/Lib/test/test_errno.py
   python/branches/py3k/Lib/test/test_shutil.py
   python/branches/py3k/Makefile.pre.in
   python/branches/py3k/Modules/_fileio.c
   python/branches/py3k/Modules/main.c
   python/branches/py3k/Modules/posixmodule.c
   python/branches/py3k/Modules/socketmodule.c
   python/branches/py3k/Tools/scripts/   (props changed)
   python/branches/py3k/Tools/scripts/reindent.py
Log:
Merged revisions 61520,61523-61528,61532 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61520 | thomas.heller | 2008-03-18 16:03:17 +0100 (Di, 18 Mär 2008) | 5 lines
  
  Include <alloca.h> on Solaris, see issue #1506.
  
  It would probably be better to have a configure test for that, but
  this is outside of my configure expertise.
........
  r61523 | brett.cannon | 2008-03-18 16:35:58 +0100 (Di, 18 Mär 2008) | 5 lines
  
  Remove all traces of HAVE_STRERROR.
  
  The removal of strerror.c led to the function check being removed from
  configure.in.
........
  r61524 | brett.cannon | 2008-03-18 16:52:00 +0100 (Di, 18 Mär 2008) | 2 lines
  
  Fix test_errno to only check for error numbers that are defined by Standard C.
........
  r61525 | steven.bethard | 2008-03-18 17:00:19 +0100 (Di, 18 Mär 2008) | 1 line
  
  Use test_support.unlink instead of os.unlink in tearDown().  (Seems to fix an occasional failure in Windows Vista.)
........
  r61526 | brett.cannon | 2008-03-18 17:47:51 +0100 (Di, 18 Mär 2008) | 3 lines
  
  Cast the arguments to PyString_AsStringAndSize() to silence compiler warnings
  on OS X.
........
  r61527 | sean.reifschneider | 2008-03-18 18:24:12 +0100 (Di, 18 Mär 2008) | 3 lines
  
  Issue 1577: shutil.move() where destination is a directory was doing a
  copy, now it is doing a os.rename() if it's on the same file-system.
........
  r61528 | brett.cannon | 2008-03-18 18:25:13 +0100 (Di, 18 Mär 2008) | 12 lines
  
  Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
  some verification:
  
  - Runs reindent.py on all .py files.
  - Checks if any changes in Doc exist.
  - Whether Misc/ACKS was changed.
  - Whether Misc/NEWS was changed.
  
  The hope is that ``make check`` can become a command anybody can run to get
  reminders about what all the requisite steps needed to create a proper
  patch/checkin.
........
  r61532 | neal.norwitz | 2008-03-18 18:58:02 +0100 (Di, 18 Mär 2008) | 1 line
  
  Get regrtest working when re-running tests
........


Modified: python/branches/py3k/Lib/shutil.py
==============================================================================
--- python/branches/py3k/Lib/shutil.py	(original)
+++ python/branches/py3k/Lib/shutil.py	Tue Mar 18 19:26:33 2008
@@ -187,26 +187,44 @@
     except os.error:
         onerror(os.rmdir, path, sys.exc_info())
 
+
+def _basename(path):
+    # A basename() variant which first strips the trailing slash, if present.
+    # Thus we always get the last component of the path, even for directories.
+    return os.path.basename(path.rstrip(os.path.sep))
+
 def move(src, dst):
-    """Recursively move a file or directory to another location.
+    """Recursively move a file or directory to another location. This is
+    similar to the Unix "mv" command.
+
+    If the destination is a directory or a symlink to a directory, the source
+    is moved inside the directory. The destination path must not already
+    exist.
 
-    If the destination is on our current filesystem, then simply use
-    rename.  Otherwise, copy src to the dst and then remove src.
+    If the destination already exists but is not a directory, it may be
+    overwritten depending on os.rename() semantics.
+
+    If the destination is on our current filesystem, then rename() is used.
+    Otherwise, src is copied to the destination and then removed.
     A lot more could be done here...  A look at a mv.c shows a lot of
     the issues this implementation glosses over.
 
     """
-
+    real_dst = dst
+    if os.path.isdir(dst):
+        real_dst = os.path.join(dst, _basename(src))
+        if os.path.exists(real_dst):
+            raise Error("Destination path '%s' already exists" % real_dst)
     try:
-        os.rename(src, dst)
+        os.rename(src, real_dst)
     except OSError:
         if os.path.isdir(src):
             if destinsrc(src, dst):
                 raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
-            copytree(src, dst, symlinks=True)
+            copytree(src, real_dst, symlinks=True)
             rmtree(src)
         else:
-            copy2(src,dst)
+            copy2(src, real_dst)
             os.unlink(src)
 
 def destinsrc(src, dst):

Modified: python/branches/py3k/Lib/test/test_errno.py
==============================================================================
--- python/branches/py3k/Lib/test/test_errno.py	(original)
+++ python/branches/py3k/Lib/test/test_errno.py	Tue Mar 18 19:26:33 2008
@@ -7,61 +7,15 @@
 from test import test_support
 import unittest
 
-errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
-          'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF',
-          'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT',
-          'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM',
-          'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET',
-          'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOTDOT', 'EDOM',
-          'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN',
-          'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS',
-          'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', 'EISNAM',
-          'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC',
-          'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG',
-          'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP',
-          'ENAMETOOLONG', 'ENAVAIL', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH',
-          'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA',
-          'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
-          'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
-          'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
-          'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTNAM', 'ENOTOBACCO', 'ENOTSOCK',
-          'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
-          'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
-          'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
-          'ERANGE', 'EREMCHG', 'EREMOTE', 'EREMOTEIO', 'ERESTART',
-          'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE',
-          'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME',
-          'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUCLEAN', 'EUNATCH',
-          'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL',
-          'WSABASEERR', 'WSADESCRIPTIO', 'WSAEACCES', 'WSAEADDRINUSE',
-          'WSAEADDRNOTAVAIL', 'WSAEAFNOSUPPORT', 'WSAEALREADY',
-          'WSAEBADF', 'WSAECONNABORTED', 'WSAECONNREFUSED',
-          'WSAECONNRESET', 'WSAEDESTADDRREQ', 'WSAEDISCON',
-          'WSAEDQUOT', 'WSAEFAULT', 'WSAEHOSTDOWN', 'WSAEHOSTUNREACH',
-          'WSAEINPROGRESS', 'WSAEINTR', 'WSAEINVAL', 'WSAEISCONN',
-          'WSAELOOP', 'WSAEMFILE', 'WSAEMSGSIZE', 'WSAENAMETOOLONG',
-          'WSAENETDOWN', 'WSAENETRESET', 'WSAENETUNREACH',
-          'WSAENOBUFS', 'WSAENOPROTOOPT', 'WSAENOTCONN',
-          'WSAENOTEMPTY', 'WSAENOTSOCK', 'WSAEOPNOTSUPP',
-          'WSAEPFNOSUPPORT', 'WSAEPROCLIM', 'WSAEPROTONOSUPPORT',
-          'WSAEPROTOTYPE', 'WSAEREMOTE', 'WSAESHUTDOWN',
-          'WSAESOCKTNOSUPPORT', 'WSAESTALE', 'WSAETIMEDOUT',
-          'WSAETOOMANYREFS', 'WSAEUSERS', 'WSAEWOULDBLOCK',
-          'WSAGETASYNCBUFLE', 'WSAGETASYNCERRO', 'WSAGETSELECTERRO',
-          'WSAGETSELECTEVEN', 'WSAHOS', 'WSAMAKEASYNCREPL',
-          'WSAMAKESELECTREPL', 'WSAN', 'WSANOTINITIALISED', 'WSASY',
-          'WSASYSNOTREADY', 'WSATR', 'WSAVERNOTSUPPORTED']
-
+std_c_errors = frozenset(['EDOM', 'ERANGE'])
 
 class ErrnoAttributeTests(unittest.TestCase):
 
     def test_for_improper_attributes(self):
         # No unexpected attributes should be on the module.
-        errors_set = set(errors)
-        for attribute in errno.__dict__.keys():
-            if attribute.isupper():
-                self.assert_(attribute in errors_set,
-                                "%s is an unexpected error value" % attribute)
+        for error_code in std_c_errors:
+            self.assert_(hasattr(errno, error_code),
+                            "errno is missing %s" % error_code)
 
     def test_using_errorcode(self):
         # Every key value in errno.errorcode should be on the module.

Modified: python/branches/py3k/Lib/test/test_shutil.py
==============================================================================
--- python/branches/py3k/Lib/test/test_shutil.py	(original)
+++ python/branches/py3k/Lib/test/test_shutil.py	Tue Mar 18 19:26:33 2008
@@ -63,17 +63,6 @@
         self.assertRaises(OSError, shutil.rmtree, path)
         os.remove(path)
 
-    def test_dont_move_dir_in_itself(self):
-        src_dir = tempfile.mkdtemp()
-        try:
-            dst = os.path.join(src_dir, 'foo')
-            self.assertRaises(shutil.Error, shutil.move, src_dir, dst)
-        finally:
-            try:
-                os.rmdir(src_dir)
-            except:
-                pass
-
     def test_copytree_simple(self):
         def write_data(path, data):
             f = open(path, "w")
@@ -162,9 +151,123 @@
                 shutil.rmtree(TESTFN, ignore_errors=True)
 
 
+class TestMove(unittest.TestCase):
+
+    def setUp(self):
+        filename = "foo"
+        self.src_dir = tempfile.mkdtemp()
+        self.dst_dir = tempfile.mkdtemp()
+        self.src_file = os.path.join(self.src_dir, filename)
+        self.dst_file = os.path.join(self.dst_dir, filename)
+        # Try to create a dir in the current directory, hoping that it is
+        # not located on the same filesystem as the system tmp dir.
+        try:
+            self.dir_other_fs = tempfile.mkdtemp(
+                dir=os.path.dirname(__file__))
+            self.file_other_fs = os.path.join(self.dir_other_fs,
+                filename)
+        except OSError:
+            self.dir_other_fs = None
+        with open(self.src_file, "wb") as f:
+            f.write(b"spam")
+
+    def tearDown(self):
+        for d in (self.src_dir, self.dst_dir, self.dir_other_fs):
+            try:
+                if d:
+                    shutil.rmtree(d)
+            except:
+                pass
+
+    def _check_move_file(self, src, dst, real_dst):
+        contents = open(src, "rb").read()
+        shutil.move(src, dst)
+        self.assertEqual(contents, open(real_dst, "rb").read())
+        self.assertFalse(os.path.exists(src))
+
+    def _check_move_dir(self, src, dst, real_dst):
+        contents = sorted(os.listdir(src))
+        shutil.move(src, dst)
+        self.assertEqual(contents, sorted(os.listdir(real_dst)))
+        self.assertFalse(os.path.exists(src))
+
+    def test_move_file(self):
+        # Move a file to another location on the same filesystem.
+        self._check_move_file(self.src_file, self.dst_file, self.dst_file)
+
+    def test_move_file_to_dir(self):
+        # Move a file inside an existing dir on the same filesystem.
+        self._check_move_file(self.src_file, self.dst_dir, self.dst_file)
+
+    def test_move_file_other_fs(self):
+        # Move a file to an existing dir on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_file(self.src_file, self.file_other_fs,
+            self.file_other_fs)
+
+    def test_move_file_to_dir_other_fs(self):
+        # Move a file to another location on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_file(self.src_file, self.dir_other_fs,
+            self.file_other_fs)
+
+    def test_move_dir(self):
+        # Move a dir to another location on the same filesystem.
+        dst_dir = tempfile.mktemp()
+        try:
+            self._check_move_dir(self.src_dir, dst_dir, dst_dir)
+        finally:
+            try:
+                shutil.rmtree(dst_dir)
+            except:
+                pass
+
+    def test_move_dir_other_fs(self):
+        # Move a dir to another location on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        dst_dir = tempfile.mktemp(dir=self.dir_other_fs)
+        try:
+            self._check_move_dir(self.src_dir, dst_dir, dst_dir)
+        finally:
+            try:
+                shutil.rmtree(dst_dir)
+            except:
+                pass
+
+    def test_move_dir_to_dir(self):
+        # Move a dir inside an existing dir on the same filesystem.
+        self._check_move_dir(self.src_dir, self.dst_dir,
+            os.path.join(self.dst_dir, os.path.basename(self.src_dir)))
+
+    def test_move_dir_to_dir_other_fs(self):
+        # Move a dir inside an existing dir on another filesystem.
+        if not self.dir_other_fs:
+            # skip
+            return
+        self._check_move_dir(self.src_dir, self.dir_other_fs,
+            os.path.join(self.dir_other_fs, os.path.basename(self.src_dir)))
+
+    def test_existing_file_inside_dest_dir(self):
+        # A file with the same name inside the destination dir already exists.
+        with open(self.dst_file, "wb"):
+            pass
+        self.assertRaises(shutil.Error, shutil.move, self.src_file, self.dst_dir)
+
+    def test_dont_move_dir_in_itself(self):
+        # Moving a dir inside itself raises an Error.
+        dst = os.path.join(self.src_dir, "bar")
+        self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst)
+
+
 
 def test_main():
-    test_support.run_unittest(TestShutil)
+    test_support.run_unittest(TestShutil, TestMove)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/py3k/Makefile.pre.in
==============================================================================
--- python/branches/py3k/Makefile.pre.in	(original)
+++ python/branches/py3k/Makefile.pre.in	Tue Mar 18 19:26:33 2008
@@ -1150,6 +1150,10 @@
 		-o -name MANIFEST \
 		-o -print
 
+# Perform some verification checks on any modified files.
+check:
+	./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py
+
 # Dependencies
 
 Python/thread.o: @THREADHEADERS@

Modified: python/branches/py3k/Modules/_fileio.c
==============================================================================
--- python/branches/py3k/Modules/_fileio.c	(original)
+++ python/branches/py3k/Modules/_fileio.c	Tue Mar 18 19:26:33 2008
@@ -104,11 +104,7 @@
 	if (self->fd < 0)
 		return 0;
 	if (fstat(self->fd, &buf) == 0 && S_ISDIR(buf.st_mode)) {
-#ifdef HAVE_STRERROR
 		char *msg = strerror(EISDIR);
-#else
-		char *msg = "Is a directory";
-#endif
 		PyObject *exc;
 		internal_close(self);
 
@@ -295,12 +291,8 @@
 	if (self->fd >= 0 && self->closefd) {
 		errno = internal_close(self);
 		if (errno < 0) {
-#ifdef HAVE_STRERROR
 			PySys_WriteStderr("close failed: [Errno %d] %s\n",
                                           errno, strerror(errno));
-#else
-			PySys_WriteStderr("close failed: [Errno %d]\n", errno);
-#endif
 		}
 	}
 

Modified: python/branches/py3k/Modules/main.c
==============================================================================
--- python/branches/py3k/Modules/main.c	(original)
+++ python/branches/py3k/Modules/main.c	Tue Mar 18 19:26:33 2008
@@ -507,13 +507,9 @@
 
 		if (sts==-1 && filename!=NULL) {
 			if ((fp = fopen(filename, "r")) == NULL) {
-#ifdef HAVE_STRERROR
 				fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n",
 					argv[0], filename, errno, strerror(errno));
-#else
-				fprintf(stderr, "%s: can't open file '%s': Errno %d\n",
-					argv[0], filename, errno);
-#endif
+
 				return 2;
 			}
 			else if (skipfirstline) {

Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Tue Mar 18 19:26:33 2008
@@ -5239,7 +5239,6 @@
 }
 #endif /* unsetenv */
 
-#ifdef HAVE_STRERROR
 PyDoc_STRVAR(posix_strerror__doc__,
 "strerror(code) -> string\n\n\
 Translate an error code to a message string.");
@@ -5259,7 +5258,6 @@
 	}
 	return PyUnicode_FromString(message);
 }
-#endif /* strerror */
 
 
 #ifdef HAVE_SYS_WAIT_H
@@ -6977,9 +6975,7 @@
 #ifdef HAVE_UNSETENV
 	{"unsetenv",	posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
 #endif
-#ifdef HAVE_STRERROR
 	{"strerror",	posix_strerror, METH_VARARGS, posix_strerror__doc__},
-#endif
 #ifdef HAVE_FCHDIR
 	{"fchdir",	posix_fchdir, METH_O, posix_fchdir__doc__},
 #endif

Modified: python/branches/py3k/Modules/socketmodule.c
==============================================================================
--- python/branches/py3k/Modules/socketmodule.c	(original)
+++ python/branches/py3k/Modules/socketmodule.c	Tue Mar 18 19:26:33 2008
@@ -2922,15 +2922,10 @@
 	}
 
 	if (h->h_addrtype != af) {
-#ifdef HAVE_STRERROR
 		/* Let's get real error message to return */
 		PyErr_SetString(socket_error,
 				(char *)strerror(EAFNOSUPPORT));
-#else
-		PyErr_SetString(
-			socket_error,
-			"Address family not supported by protocol family");
-#endif
+
 		return NULL;
 	}
 

Copied: python/branches/py3k/Tools/scripts/patchcheck.py (from r61528, python/trunk/Tools/scripts/patchcheck.py)
==============================================================================
--- python/trunk/Tools/scripts/patchcheck.py	(original)
+++ python/branches/py3k/Tools/scripts/patchcheck.py	Tue Mar 18 19:26:33 2008
@@ -13,14 +13,14 @@
             sys.stdout.flush()
             result = fxn(*args, **kwargs)
             if not modal and not info:
-                print "done"
+                print("done")
             elif info:
-                print info(result)
+                print(info(result))
             else:
                 if result:
-                    print "yes"
+                    print("yes")
                 else:
-                    print "NO"
+                    print("NO")
             return result
         return call_fxn
     return decorated_fxn
@@ -48,7 +48,7 @@
 def normalize_whitespace(file_paths):
     """Make sure that the whitespace for .py files have been normalized."""
     reindent.makebackup = False  # No need to create backups.
-    result = map(reindent.check, (x for x in file_paths if x.endswith('.py')))
+    result = list(map(reindent.check, (x for x in file_paths if x.endswith('.py'))))
     return sum(result)
 
 @status("Docs modified", modal=True)
@@ -82,8 +82,8 @@
     reported_news(file_paths)
 
     # Test suite run and passed.
-    print
-    print "Did you run the test suite?"
+    print()
+    print("Did you run the test suite?")
 
 
 if __name__ == '__main__':

Modified: python/branches/py3k/Tools/scripts/reindent.py
==============================================================================
--- python/branches/py3k/Tools/scripts/reindent.py	(original)
+++ python/branches/py3k/Tools/scripts/reindent.py	Tue Mar 18 19:26:33 2008
@@ -130,9 +130,11 @@
             f.close()
             if verbose:
                 print("wrote new", file)
+        return True
     else:
         if verbose:
             print("unchanged.")
+        return False
 
 def _rstrip(line, JUNK='\n \t'):
     """Return line stripped of trailing spaces, tabs, newlines.


More information about the Python-3000-checkins mailing list