classification
Title: tarfile.is_tarfile without read permissions raises AttributeError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: atagar, serhiy.storchaka
Priority: normal Keywords:

Created on 2013-01-28 03:50 by atagar, last changed 2013-01-28 09:18 by serhiy.storchaka. This issue is now closed.

Messages (2)
msg180824 - (view) Author: Damian (atagar) Date: 2013-01-28 03:50
Hi. While porting a library of mine from python 2.7 to 3.2 I noticed that tarfile.is_tarfile() now raises an AttributeError rather than IOError when it lacks read permissions...

atagar@morrigan:~$ touch dummy_file.tar
atagar@morrigan:~$ chmod 000 dummy_file.tar 
atagar@morrigan:~$ pwd
/home/atagar

atagar@morrigan:~$ python
Python 2.7.1+ (r271:86832, Sep 27 2012, 21:16:52) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarfile
>>> tarfile.is_tarfile("/home/atagar/dummy_file.tar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/tarfile.py", line 2583, in is_tarfile
    t = open(name)
  File "/usr/lib/python2.7/tarfile.py", line 1658, in open
    return func(name, "r", fileobj, **kwargs)
  File "/usr/lib/python2.7/tarfile.py", line 1720, in gzopen
    fileobj = bltn_open(name, mode + "b")
IOError: [Errno 13] Permission denied: '/home/atagar/dummy_file.tar'

atagar@morrigan:~$ python3
Python 3.2 (r32:88445, Oct 20 2012, 14:09:50) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarfile
>>> tarfile.is_tarfile("/home/atagar/dummy_file.tar")
Traceback (most recent call last):
  File "/usr/lib/python3.2/tarfile.py", line 1805, in gzopen
    fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj)
  File "/usr/lib/python3.2/gzip.py", line 157, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
IOError: [Errno 13] Permission denied: '/home/atagar/dummy_file.tar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/tarfile.py", line 2593, in is_tarfile
    t = open(name)
  File "/usr/lib/python3.2/tarfile.py", line 1739, in open
    return func(name, "r", fileobj, **kwargs)
  File "/usr/lib/python3.2/tarfile.py", line 1809, in gzopen
    fileobj.close()
AttributeError: 'NoneType' object has no attribute 'close'

>>> try:
...   tarfile.is_tarfile("/home/atagar/dummy_file.tar")
... except IOError:
...   print("caught an IOError")
... except AttributeError:
...   print("caught an AttributeError")
... 
caught an AttributeError


... easy to work around, but I suspect this wasn't intentional. :)
msg180842 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-28 09:18
Thank you for the report, Damian. This was fixed in issue11513.
History
Date User Action Args
2013-01-28 09:18:09serhiy.storchakasetstatus: open -> closed

assignee: serhiy.storchaka
components: + Library (Lib), - None

nosy: + serhiy.storchaka
messages: + msg180842
resolution: out of date
stage: resolved
2013-01-28 03:50:01atagarcreate