summaryrefslogtreecommitdiff
path: root/Lib/shutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 78504b9d3f..2befb47dd4 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -63,15 +63,10 @@ def copyfile(src, dst):
# XXX What about other special files? (sockets, devices...)
if stat.S_ISFIFO(st.st_mode):
raise SpecialFileError("`%s` is a named pipe" % fn)
- try:
- fsrc = open(src, 'rb')
- fdst = open(dst, 'wb')
- copyfileobj(fsrc, fdst)
- finally:
- if fdst:
- fdst.close()
- if fsrc:
- fsrc.close()
+
+ with open(src, 'rb') as fsrc:
+ with open(dst, 'wb') as fdst:
+ copyfileobj(fsrc, fdst)
def copymode(src, dst):
"""Copy mode bits from src to dst"""