This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tarfile._FileInFile.seekable is broken in stream mode
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Bill Lee, charmander, jarondl, lars.gustaebel, louielu
Priority: normal Keywords: patch

Created on 2016-02-25 16:49 by Bill Lee, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 8553 closed Tiger-222, 2018-07-29 14:30
Messages (4)
msg260866 - (view) Author: Bill Lee (Bill Lee) Date: 2016-02-25 16:49
Description
===========
With a file object, retrieved by the `extractfile` method of a TarFile object opened in stream mode, calling its `seekable` method will raise an AttributeError.

How to Reproduce
================
cat > seekable.py << EOF
import sys
import tarfile
tar = tarfile.open(fileobj=sys.stdin.buffer, mode='r|')
contentFile = tar.extractfile(tar.next())
print(contentFile.seekable())
EOF

tar -cf test.tar seekable.py
python seekable.py < test.tar


Traceback
=========
Traceback (most recent call last):
  File "seekable.py", line 5, in <module>
    print(contentFile.seekable())
  File "/usr/local/lib/python3.5/tarfile.py", line 649, in seekable
    return self.fileobj.seekable()

How to Fix
==========
I think that adding a method seekable(), which always return False, to tarfile._Stream will works.
msg260867 - (view) Author: Bill Lee (Bill Lee) Date: 2016-02-25 16:57
I posted an incomplete traceback by mistake. Here is the whole traceback.

Traceback
=========
Traceback (most recent call last):
  File "seekable.py", line 5, in <module>
    print(contentFile.seekable())
  File "/usr/local/lib/python3.5/tarfile.py", line 649, in seekable
    return self.fileobj.seekable()
AttributeError: '_Stream' object has no attribute 'seekable'
msg290777 - (view) Author: Louie Lu (louielu) * Date: 2017-03-29 10:40
Actually, _Stream does provide seek method, should the seekable just return True?
msg299577 - (view) Author: Yaron de Leeuw (jarondl) * Date: 2017-07-31 18:44
_Stream provides seek, but only positive seeking is allowed. Is that considered seekable? Also, maybe _Stream should inherit from io.BaseIO. WDYT?
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70627
2018-07-29 14:30:27Tiger-222setkeywords: + patch
stage: patch review
pull_requests: + pull_request8069
2018-06-22 01:43:24charmandersetnosy: + charmander
2017-07-31 18:44:54jarondlsetnosy: + jarondl
messages: + msg299577
2017-03-29 10:40:07louielusetnosy: + louielu
messages: + msg290777
2016-02-28 06:29:45ned.deilysetnosy: + lars.gustaebel
2016-02-25 16:57:25Bill Leesetmessages: + msg260867
2016-02-25 16:49:19Bill Leecreate