Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
68f71a34
Commit
68f71a34
authored
Oct 28, 2011
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify and remove few dependencies on 'errno', thanks to PEP 3151.
parent
908ae24b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
45 deletions
+28
-45
Lib/importlib/__init__.py
Lib/importlib/__init__.py
+1
-2
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+5
-11
Lib/tarfile.py
Lib/tarfile.py
+2
-4
Lib/tempfile.py
Lib/tempfile.py
+18
-24
Lib/test/regrtest.py
Lib/test/regrtest.py
+2
-4
No files found.
Lib/importlib/__init__.py
View file @
68f71a34
...
@@ -81,11 +81,10 @@ except ImportError:
...
@@ -81,11 +81,10 @@ except ImportError:
except
ImportError
:
except
ImportError
:
raise
ImportError
(
'posix, nt, or os2 module required for importlib'
)
raise
ImportError
(
'posix, nt, or os2 module required for importlib'
)
_bootstrap
.
_os
=
_os
_bootstrap
.
_os
=
_os
import
imp
,
sys
,
marshal
,
errno
,
_io
import
imp
,
sys
,
marshal
,
_io
_bootstrap
.
imp
=
imp
_bootstrap
.
imp
=
imp
_bootstrap
.
sys
=
sys
_bootstrap
.
sys
=
sys
_bootstrap
.
marshal
=
marshal
_bootstrap
.
marshal
=
marshal
_bootstrap
.
errno
=
errno
_bootstrap
.
_io
=
_io
_bootstrap
.
_io
=
_io
import
_warnings
import
_warnings
_bootstrap
.
_warnings
=
_warnings
_bootstrap
.
_warnings
=
_warnings
...
...
Lib/importlib/_bootstrap.py
View file @
68f71a34
...
@@ -7,7 +7,7 @@ work. One should use importlib as the public-facing version of this module.
...
@@ -7,7 +7,7 @@ work. One should use importlib as the public-facing version of this module.
"""
"""
# Injected modules are '_warnings', 'imp', 'sys', 'marshal', '
errno', '
_io',
# Injected modules are '_warnings', 'imp', 'sys', 'marshal', '_io',
# and '_os' (a.k.a. 'posix', 'nt' or 'os2').
# and '_os' (a.k.a. 'posix', 'nt' or 'os2').
# Injected attribute is path_sep.
# Injected attribute is path_sep.
#
#
...
@@ -503,19 +503,13 @@ class _SourceFileLoader(_FileLoader, SourceLoader):
...
@@ -503,19 +503,13 @@ class _SourceFileLoader(_FileLoader, SourceLoader):
parent
=
_path_join
(
parent
,
part
)
parent
=
_path_join
(
parent
,
part
)
try
:
try
:
_os
.
mkdir
(
parent
)
_os
.
mkdir
(
parent
)
except
OSError
as
exc
:
except
FileExistsError
:
# Probably another Python process already created the dir.
# Probably another Python process already created the dir.
if
exc
.
errno
==
errno
.
EEXIST
:
continue
continue
except
PermissionError
:
else
:
raise
except
IOError
as
exc
:
# If can't get proper access, then just forget about writing
# If can't get proper access, then just forget about writing
# the data.
# the data.
if
exc
.
errno
==
errno
.
EACCES
:
return
return
else
:
raise
try
:
try
:
_write_atomic
(
path
,
data
)
_write_atomic
(
path
,
data
)
except
(
PermissionError
,
FileExistsError
):
except
(
PermissionError
,
FileExistsError
):
...
...
Lib/tarfile.py
View file @
68f71a34
...
@@ -42,7 +42,6 @@ import sys
...
@@ -42,7 +42,6 @@ import sys
import
os
import
os
import
shutil
import
shutil
import
stat
import
stat
import
errno
import
time
import
time
import
struct
import
struct
import
copy
import
copy
...
@@ -2281,9 +2280,8 @@ class TarFile(object):
...
@@ -2281,9 +2280,8 @@ class TarFile(object):
# Use a safe mode for the directory, the real mode is set
# Use a safe mode for the directory, the real mode is set
# later in _extract_member().
# later in _extract_member().
os.mkdir(targetpath, 0o700)
os.mkdir(targetpath, 0o700)
except EnvironmentError as e:
except FileExistsError:
if e.errno != errno.EEXIST:
pass
raise
def makefile(self, tarinfo, targetpath):
def makefile(self, tarinfo, targetpath):
"""Make a file called targetpath.
"""Make a file called targetpath.
...
...
Lib/tempfile.py
View file @
68f71a34
...
@@ -31,7 +31,6 @@ import warnings as _warnings
...
@@ -31,7 +31,6 @@ import warnings as _warnings
import
sys
as
_sys
import
sys
as
_sys
import
io
as
_io
import
io
as
_io
import
os
as
_os
import
os
as
_os
import
errno
as
_errno
from
random
import
Random
as
_Random
from
random
import
Random
as
_Random
try
:
try
:
...
@@ -43,7 +42,7 @@ else:
...
@@ -43,7 +42,7 @@ else:
def
_set_cloexec
(
fd
):
def
_set_cloexec
(
fd
):
try
:
try
:
flags
=
_fcntl
.
fcntl
(
fd
,
_fcntl
.
F_GETFD
,
0
)
flags
=
_fcntl
.
fcntl
(
fd
,
_fcntl
.
F_GETFD
,
0
)
except
IO
Error
:
except
OS
Error
:
pass
pass
else
:
else
:
# flags read successfully, modify
# flags read successfully, modify
...
@@ -85,19 +84,19 @@ if hasattr(_os, "lstat"):
...
@@ -85,19 +84,19 @@ if hasattr(_os, "lstat"):
elif
hasattr
(
_os
,
"stat"
):
elif
hasattr
(
_os
,
"stat"
):
_stat
=
_os
.
stat
_stat
=
_os
.
stat
else
:
else
:
# Fallback. All we need is something that raises
os.e
rror if the
# Fallback. All we need is something that raises
OSE
rror if the
# file doesn't exist.
# file doesn't exist.
def
_stat
(
fn
):
def
_stat
(
fn
):
try
:
try
:
f
=
open
(
fn
)
f
=
open
(
fn
)
except
IO
Error
:
except
OS
Error
:
raise
_os
.
e
rror
raise
OSE
rror
f
.
close
()
f
.
close
()
def
_exists
(
fn
):
def
_exists
(
fn
):
try
:
try
:
_stat
(
fn
)
_stat
(
fn
)
except
_os
.
e
rror
:
except
OSE
rror
:
return
False
return
False
else
:
else
:
return
True
return
True
...
@@ -144,7 +143,7 @@ def _candidate_tempdir_list():
...
@@ -144,7 +143,7 @@ def _candidate_tempdir_list():
# As a last resort, the current directory.
# As a last resort, the current directory.
try
:
try
:
dirlist
.
append
(
_os
.
getcwd
())
dirlist
.
append
(
_os
.
getcwd
())
except
(
AttributeError
,
_os
.
e
rror
):
except
(
AttributeError
,
OSE
rror
):
dirlist
.
append
(
_os
.
curdir
)
dirlist
.
append
(
_os
.
curdir
)
return
dirlist
return
dirlist
...
@@ -176,12 +175,11 @@ def _get_default_tempdir():
...
@@ -176,12 +175,11 @@ def _get_default_tempdir():
_os
.
unlink
(
filename
)
_os
.
unlink
(
filename
)
del
fp
,
fd
del
fp
,
fd
return
dir
return
dir
except
(
OSError
,
IOError
)
as
e
:
except
FileExistsError
:
if
e
.
args
[
0
]
!=
_errno
.
EEXIST
:
break
# no point trying more names in this directory
pass
pass
raise
IOError
(
_errno
.
ENOENT
,
except
OSError
:
"No usable temporary directory found in %s"
%
dirlist
)
break
# no point trying more names in this directory
raise
FileNotFoundError
(
"No usable temporary directory found in %s"
%
dirlist
)
_name_sequence
=
None
_name_sequence
=
None
...
@@ -211,12 +209,10 @@ def _mkstemp_inner(dir, pre, suf, flags):
...
@@ -211,12 +209,10 @@ def _mkstemp_inner(dir, pre, suf, flags):
fd
=
_os
.
open
(
file
,
flags
,
0o600
)
fd
=
_os
.
open
(
file
,
flags
,
0o600
)
_set_cloexec
(
fd
)
_set_cloexec
(
fd
)
return
(
fd
,
_os
.
path
.
abspath
(
file
))
return
(
fd
,
_os
.
path
.
abspath
(
file
))
except
OSError
as
e
:
except
FileExistsError
:
if
e
.
errno
==
_errno
.
EEXIST
:
continue
# try again
continue
# try again
raise
raise
IOError
(
_errno
.
EEXIST
,
"No usable temporary file name found"
)
raise
FileExistsError
(
"No usable temporary file name found"
)
# User visible interfaces.
# User visible interfaces.
...
@@ -300,12 +296,10 @@ def mkdtemp(suffix="", prefix=template, dir=None):
...
@@ -300,12 +296,10 @@ def mkdtemp(suffix="", prefix=template, dir=None):
try
:
try
:
_os
.
mkdir
(
file
,
0o700
)
_os
.
mkdir
(
file
,
0o700
)
return
file
return
file
except
OSError
as
e
:
except
FileExistsError
:
if
e
.
errno
==
_errno
.
EEXIST
:
continue
# try again
continue
# try again
raise
raise
IOError
(
_errno
.
EEXIST
,
"No usable temporary directory name found"
)
raise
FileExistsError
(
"No usable temporary directory name found"
)
def
mktemp
(
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
def
mktemp
(
suffix
=
""
,
prefix
=
template
,
dir
=
None
):
"""User-callable function to return a unique temporary file name. The
"""User-callable function to return a unique temporary file name. The
...
@@ -334,7 +328,7 @@ def mktemp(suffix="", prefix=template, dir=None):
...
@@ -334,7 +328,7 @@ def mktemp(suffix="", prefix=template, dir=None):
if
not
_exists
(
file
):
if
not
_exists
(
file
):
return
file
return
file
raise
IOError
(
_errno
.
EEXIST
,
"No usable temporary filename found"
)
raise
FileExistsError
(
"No usable temporary filename found"
)
class
_TemporaryFileWrapper
:
class
_TemporaryFileWrapper
:
...
@@ -664,7 +658,7 @@ class TemporaryDirectory(object):
...
@@ -664,7 +658,7 @@ class TemporaryDirectory(object):
_islink
=
staticmethod
(
_os
.
path
.
islink
)
_islink
=
staticmethod
(
_os
.
path
.
islink
)
_remove
=
staticmethod
(
_os
.
remove
)
_remove
=
staticmethod
(
_os
.
remove
)
_rmdir
=
staticmethod
(
_os
.
rmdir
)
_rmdir
=
staticmethod
(
_os
.
rmdir
)
_os_error
=
_os
.
e
rror
_os_error
=
OSE
rror
_warn
=
_warnings
.
warn
_warn
=
_warnings
.
warn
def
_rmtree
(
self
,
path
):
def
_rmtree
(
self
,
path
):
...
...
Lib/test/regrtest.py
View file @
68f71a34
...
@@ -166,7 +166,6 @@ option '-uall,-gui'.
...
@@ -166,7 +166,6 @@ option '-uall,-gui'.
"""
"""
import
builtins
import
builtins
import
errno
import
faulthandler
import
faulthandler
import
getopt
import
getopt
import
io
import
io
...
@@ -1721,9 +1720,8 @@ def _make_temp_dir_for_build(TEMPDIR):
...
@@ -1721,9 +1720,8 @@ def _make_temp_dir_for_build(TEMPDIR):
TEMPDIR = os.path.abspath(TEMPDIR)
TEMPDIR = os.path.abspath(TEMPDIR)
try:
try:
os.mkdir(TEMPDIR)
os.mkdir(TEMPDIR)
except OSError as e:
except FileExistsError:
if e.errno != errno.EEXIST:
pass
raise
# Define a writable temp dir that will be used as cwd while running
# Define a writable temp dir that will be used as cwd while running
# the tests. The name of the dir includes the pid to allow parallel
# the tests. The name of the dir includes the pid to allow parallel
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment