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.
(name)
| 3039 | #-------------------- |
| 3040 | |
| 3041 | def is_tarfile(name): |
| 3042 | """Return True if name points to a tar archive that we |
| 3043 | are able to handle, else return False. |
| 3044 | |
| 3045 | 'name' should be a string, file, or file-like object. |
| 3046 | """ |
| 3047 | try: |
| 3048 | if hasattr(name, "read"): |
| 3049 | pos = name.tell() |
| 3050 | t = open(fileobj=name) |
| 3051 | name.seek(pos) |
| 3052 | else: |
| 3053 | t = open(name) |
| 3054 | t.close() |
| 3055 | return True |
| 3056 | except TarError: |
| 3057 | return False |
| 3058 | |
| 3059 | open = TarFile.open |
| 3060 |