summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorWilliam Woodruff <william@yossarian.net>2020-01-22 21:24:16 -0500
committerEthan Furman <ethan@stoneleaf.us>2020-01-22 18:24:16 -0800
commitdd754caf144009f0569dda5053465ba2accb7b4d (patch)
tree536217d96dcb3e1d5f57b0bcd53da66059a15ad3 /Lib/tarfile.py
parent41f0ef6abbd304409c55612a08788cdd59fbc8a3 (diff)
downloadcpython-git-dd754caf144009f0569dda5053465ba2accb7b4d.tar.gz
bpo-29435: Allow is_tarfile to take a filelike obj (GH-18090)
`is_tarfile()` now supports `name` being a file or file-like object.
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-xLib/tarfile.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 2c06f9160c..d0b748cea1 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2461,9 +2461,14 @@ class TarFile(object):
def is_tarfile(name):
"""Return True if name points to a tar archive that we
are able to handle, else return False.
+
+ 'name' should be a string, file, or file-like object.
"""
try:
- t = open(name)
+ if hasattr(name, "read"):
+ t = open(fileobj=name)
+ else:
+ t = open(name)
t.close()
return True
except TarError: