[New-bugs-announce] [issue17059] tarfile.is_tarfile without read permissions raises AttributeError

Damian report at bugs.python.org
Mon Jan 28 04:50:01 CET 2013


New submission from Damian:

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 at morrigan:~$ touch dummy_file.tar
atagar at morrigan:~$ chmod 000 dummy_file.tar 
atagar at morrigan:~$ pwd
/home/atagar

atagar at 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 at 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. :)

----------
components: None
messages: 180824
nosy: atagar
priority: normal
severity: normal
status: open
title: tarfile.is_tarfile without read permissions raises AttributeError
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17059>
_______________________________________


More information about the New-bugs-announce mailing list