mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Merge 3.3 (#4931)
This commit is contained in:
commit
a0fe1f74f9
6 changed files with 20 additions and 38 deletions
|
@ -207,25 +207,10 @@ def subst_vars (s, local_vars):
|
|||
|
||||
|
||||
def grok_environment_error (exc, prefix="error: "):
|
||||
"""Generate a useful error message from an OSError
|
||||
exception object. Handles Python 1.5.1 and 1.5.2 styles, and
|
||||
does what it can to deal with exception objects that don't have a
|
||||
filename (which happens when the error is due to a two-file operation,
|
||||
such as 'rename()' or 'link()'. Returns the error message as a string
|
||||
prefixed with 'prefix'.
|
||||
"""
|
||||
# check for Python 1.5.2-style {IO,OS}Error exception objects
|
||||
if hasattr(exc, 'filename') and hasattr(exc, 'strerror'):
|
||||
if exc.filename:
|
||||
error = prefix + "%s: %s" % (exc.filename, exc.strerror)
|
||||
else:
|
||||
# two-argument functions in posix module don't
|
||||
# include the filename in the exception object!
|
||||
error = prefix + "%s" % exc.strerror
|
||||
else:
|
||||
error = prefix + str(exc.args[-1])
|
||||
|
||||
return error
|
||||
# Function kept for backward compatibility.
|
||||
# Used to try clever things with EnvironmentErrors,
|
||||
# but nowadays str(exception) produces good messages.
|
||||
return prefix + str(exc)
|
||||
|
||||
|
||||
# Needed by 'split_quoted()'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue