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)
| 2779 | #-------------------- |
| 2780 | |
| 2781 | def is_tarfile(name): |
| 2782 | """Return True if name points to a tar archive that we |
| 2783 | are able to handle, else return False. |
| 2784 | |
| 2785 | 'name' should be a string, file, or file-like object. |
| 2786 | """ |
| 2787 | try: |
| 2788 | if hasattr(name, "read"): |
| 2789 | pos = name.tell() |
| 2790 | t = open(fileobj=name) |
| 2791 | name.seek(pos) |
| 2792 | else: |
| 2793 | t = open(name) |
| 2794 | t.close() |
| 2795 | return True |
| 2796 | except TarError: |
| 2797 | return False |
| 2798 | |
| 2799 | open = TarFile.open |
| 2800 |