Issue 26440: tarfile._FileInFile.seekable is broken in stream mode (original) (raw)

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 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 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:28 admin set github: 70627
2018-07-29 14:30:27 Tiger-222 set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest8069>
2018-06-22 01:43:24 charmander set nosy: + charmander
2017-07-31 18:44:54 jarondl set nosy: + jarondlmessages: +
2017-03-29 10:40:07 louielu set nosy: + louielumessages: +
2016-02-28 06:29:45 ned.deily set nosy: + lars.gustaebel
2016-02-25 16:57:25 Bill Lee set messages: +
2016-02-25 16:49:19 Bill Lee create