[Python-checkins] cpython: Get rig of EnvironmentError (#16705)

andrew.svetlov python-checkins at python.org
Mon Dec 17 22:35:33 CET 2012


http://hg.python.org/cpython/rev/061e9a439f54
changeset:   80922:061e9a439f54
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Mon Dec 17 23:35:18 2012 +0200
summary:
  Get rig of EnvironmentError (#16705)

files:
  Lib/compileall.py           |   2 +-
  Lib/getpass.py              |   2 +-
  Lib/mimetypes.py            |   4 ++--
  Lib/shutil.py               |  10 +++++-----
  Lib/subprocess.py           |   4 ++--
  Lib/tarfile.py              |   8 ++++----
  Lib/test/test_exceptions.py |   6 +++---
  Lib/test/test_fileio.py     |   2 +-
  Lib/test/test_io.py         |   2 +-
  Lib/test/test_signal.py     |   2 +-
  Lib/test/test_subprocess.py |   7 +++----
  Lib/test/test_tarfile.py    |   4 ++--
  Lib/test/test_tempfile.py   |   2 +-
  Lib/test/test_urllib2net.py |   2 +-
  Lib/test/test_winreg.py     |  10 +++++-----
  Lib/urllib/request.py       |   2 +-
  16 files changed, 34 insertions(+), 35 deletions(-)


diff --git a/Lib/compileall.py b/Lib/compileall.py
--- a/Lib/compileall.py
+++ b/Lib/compileall.py
@@ -209,7 +209,7 @@
             with (sys.stdin if args.flist=='-' else open(args.flist)) as f:
                 for line in f:
                     compile_dests.append(line.strip())
-        except EnvironmentError:
+        except OSError:
             print("Error reading file list {}".format(args.flist))
             return False
 
diff --git a/Lib/getpass.py b/Lib/getpass.py
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -47,7 +47,7 @@
         input = tty
         if not stream:
             stream = tty
-    except EnvironmentError as e:
+    except OSError as e:
         # If that fails, see if stdin can be controlled.
         try:
             fd = sys.stdin.fileno()
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -243,7 +243,7 @@
             while True:
                 try:
                     ctype = _winreg.EnumKey(mimedb, i)
-                except EnvironmentError:
+                except OSError:
                     break
                 else:
                     yield ctype
@@ -256,7 +256,7 @@
                     with _winreg.OpenKey(mimedb, ctype) as key:
                         suffix, datatype = _winreg.QueryValueEx(key,
                                                                 'Extension')
-                except EnvironmentError:
+                except OSError:
                     continue
                 if datatype != _winreg.REG_SZ:
                     continue
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -39,20 +39,20 @@
            "ignore_patterns", "chown", "which"]
            # disk_usage is added later, if available on the platform
 
-class Error(EnvironmentError):
+class Error(OSError):
     pass
 
 class SameFileError(Error):
     """Raised when source and destination are the same file."""
 
-class SpecialFileError(EnvironmentError):
+class SpecialFileError(OSError):
     """Raised when trying to do a kind of operation (e.g. copying) which is
     not supported on a special file (e.g. a named pipe)"""
 
-class ExecError(EnvironmentError):
+class ExecError(OSError):
     """Raised when a command could not be executed"""
 
-class ReadError(EnvironmentError):
+class ReadError(OSError):
     """Raised when an archive cannot be read"""
 
 class RegistryError(Exception):
@@ -329,7 +329,7 @@
         # continue with other files
         except Error as err:
             errors.extend(err.args[0])
-        except EnvironmentError as why:
+        except OSError as why:
             errors.append((srcname, dstname, str(why)))
     try:
         copystat(src, dst)
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -819,7 +819,7 @@
             for f in filter(None, (self.stdin, self.stdout, self.stderr)):
                 try:
                     f.close()
-                except EnvironmentError:
+                except OSError:
                     pass  # Ignore EBADF or other errors.
 
             # Make sure the child pipes are closed as well.
@@ -833,7 +833,7 @@
             for fd in to_close:
                 try:
                     os.close(fd)
-                except EnvironmentError:
+                except OSError:
                     pass
 
             raise
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2022,7 +2022,7 @@
         try:
             self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
                                  set_attrs=set_attrs)
-        except EnvironmentError as e:
+        except OSError as e:
             if self.errorlevel > 0:
                 raise
             else:
@@ -2212,7 +2212,7 @@
                     os.lchown(targetpath, u, g)
                 else:
                     os.chown(targetpath, u, g)
-            except EnvironmentError as e:
+            except OSError as e:
                 raise ExtractError("could not change owner")
 
     def chmod(self, tarinfo, targetpath):
@@ -2221,7 +2221,7 @@
         if hasattr(os, 'chmod'):
             try:
                 os.chmod(targetpath, tarinfo.mode)
-            except EnvironmentError as e:
+            except OSError as e:
                 raise ExtractError("could not change mode")
 
     def utime(self, tarinfo, targetpath):
@@ -2231,7 +2231,7 @@
             return
         try:
             os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
-        except EnvironmentError as e:
+        except OSError as e:
             raise ExtractError("could not change modification time")
 
     #--------------------------------------------------------------------------
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -255,11 +255,11 @@
                  'errno' : 'foo', 'strerror' : 'bar'}),
             (IOError, ('foo', 'bar', 'baz', 'quux'),
                 {'args' : ('foo', 'bar', 'baz', 'quux')}),
-            (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'),
+            (OSError, ('errnoStr', 'strErrorStr', 'filenameStr'),
                 {'args' : ('errnoStr', 'strErrorStr'),
                  'strerror' : 'strErrorStr', 'errno' : 'errnoStr',
                  'filename' : 'filenameStr'}),
-            (EnvironmentError, (1, 'strErrorStr', 'filenameStr'),
+            (OSError, (1, 'strErrorStr', 'filenameStr'),
                 {'args' : (1, 'strErrorStr'), 'errno' : 1,
                  'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}),
             (SyntaxError, (), {'msg' : None, 'text' : None,
@@ -409,7 +409,7 @@
         self.assertIsNone(e.__context__)
         self.assertIsNone(e.__cause__)
 
-        class MyException(EnvironmentError):
+        class MyException(OSError):
             pass
 
         e = MyException()
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -285,7 +285,7 @@
             if sys.platform != "win32":
                 try:
                     f = _FileIO("/dev/tty", "a")
-                except EnvironmentError:
+                except OSError:
                     # When run in a cron job there just aren't any
                     # ttys, so skip the test.  This also handles other
                     # OS'es that don't support /dev/tty.
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2825,7 +2825,7 @@
             for fd in fds:
                 try:
                     os.close(fd)
-                except EnvironmentError as e:
+                except OSError as e:
                     if e.errno != errno.EBADF:
                         raise
         self.addCleanup(cleanup_fds)
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -33,7 +33,7 @@
 def ignoring_eintr(__func, *args, **kwargs):
     try:
         return __func(*args, **kwargs)
-    except EnvironmentError as e:
+    except OSError as e:
         if e.errno != errno.EINTR:
             raise
         return None
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -925,8 +925,7 @@
         # value for that limit, but Windows has 2048, so we loop
         # 1024 times (each call leaked two fds).
         for i in range(1024):
-            # Windows raises IOError.  Others raise OSError.
-            with self.assertRaises(EnvironmentError) as c:
+            with self.assertRaises(OSError) as c:
                 subprocess.Popen(['nonexisting_i_hope'],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
@@ -1874,7 +1873,7 @@
         # let some time for the process to exit, and create a new Popen: this
         # should trigger the wait() of p
         time.sleep(0.2)
-        with self.assertRaises(EnvironmentError) as c:
+        with self.assertRaises(OSError) as c:
             with subprocess.Popen(['nonexisting_i_hope'],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE) as proc:
@@ -2155,7 +2154,7 @@
             self.assertEqual(proc.returncode, 1)
 
     def test_invalid_args(self):
-        with self.assertRaises(EnvironmentError) as c:
+        with self.assertRaises(OSError) as c:
             with subprocess.Popen(['nonexisting_i_hope'],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE) as proc:
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -342,7 +342,7 @@
             tar.extract("ustar/regtype", TEMPDIR)
             try:
                 tar.extract("ustar/lnktype", TEMPDIR)
-            except EnvironmentError as e:
+            except OSError as e:
                 if e.errno == errno.ENOENT:
                     self.fail("hardlink not extracted properly")
 
@@ -352,7 +352,7 @@
 
             try:
                 tar.extract("ustar/symtype", TEMPDIR)
-            except EnvironmentError as e:
+            except OSError as e:
                 if e.errno == errno.ENOENT:
                     self.fail("symlink not extracted properly")
 
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -149,7 +149,7 @@
                 # via any bugs above
                 try:
                     os.kill(pid, signal.SIGKILL)
-                except EnvironmentError:
+                except OSError:
                     pass
             os.close(read_fd)
             os.close(write_fd)
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -216,7 +216,7 @@
                 debug(url)
                 try:
                     f = urlopen(url, req, TIMEOUT)
-                except EnvironmentError as err:
+                except OSError as err:
                     debug(err)
                     if expected_err:
                         msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -97,7 +97,7 @@
             QueryInfoKey(int_sub_key)
             self.fail("It appears the CloseKey() function does "
                       "not close the actual key!")
-        except EnvironmentError:
+        except OSError:
             pass
         # ... and close that key that way :-)
         int_key = int(key)
@@ -106,7 +106,7 @@
             QueryInfoKey(int_key)
             self.fail("It appears the key.Close() function "
                       "does not close the actual key!")
-        except EnvironmentError:
+        except OSError:
             pass
 
     def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey):
@@ -123,7 +123,7 @@
             while 1:
                 try:
                     data = EnumValue(sub_key, index)
-                except EnvironmentError:
+                except OSError:
                     break
                 self.assertEqual(data in test_data, True,
                                  "Didn't read back the correct test data")
@@ -144,7 +144,7 @@
         try:
             EnumKey(key, 1)
             self.fail("Was able to get a second key when I only have one!")
-        except EnvironmentError:
+        except OSError:
             pass
 
         key.Close()
@@ -168,7 +168,7 @@
             # Shouldnt be able to delete it twice!
             DeleteKey(key, subkeystr)
             self.fail("Deleting the key twice succeeded")
-        except EnvironmentError:
+        except OSError:
             pass
         key.Close()
         DeleteKey(root_key, test_key_name)
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -232,7 +232,7 @@
     for temp_file in _url_tempfiles:
         try:
             os.unlink(temp_file)
-        except EnvironmentError:
+        except OSError:
             pass
 
     del _url_tempfiles[:]

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list