Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarfile.is_tarfile without read permissions raises AttributeError #61261

Closed
atagar mannequin opened this issue Jan 28, 2013 · 2 comments
Closed

tarfile.is_tarfile without read permissions raises AttributeError #61261

atagar mannequin opened this issue Jan 28, 2013 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@atagar
Copy link
Mannequin

atagar mannequin commented Jan 28, 2013

BPO 17059
Nosy @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/serhiy-storchaka'
closed_at = <Date 2013-01-28.09:18:09.183>
created_at = <Date 2013-01-28.03:50:01.648>
labels = ['type-bug', 'library']
title = 'tarfile.is_tarfile without read permissions raises AttributeError'
updated_at = <Date 2013-01-28.09:18:09.181>
user = 'https://bugs.python.org/atagar'

bugs.python.org fields:

activity = <Date 2013-01-28.09:18:09.181>
actor = 'serhiy.storchaka'
assignee = 'serhiy.storchaka'
closed = True
closed_date = <Date 2013-01-28.09:18:09.183>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2013-01-28.03:50:01.648>
creator = 'atagar'
dependencies = []
files = []
hgrepos = []
issue_num = 17059
keywords = []
message_count = 2.0
messages = ['180824', '180842']
nosy_count = 2.0
nosy_names = ['atagar', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue17059'
versions = ['Python 3.2']

@atagar
Copy link
Mannequin Author

atagar mannequin commented Jan 28, 2013

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

@atagar atagar mannequin added the type-bug An unexpected behavior, bug, or error label Jan 28, 2013
@serhiy-storchaka
Copy link
Member

Thank you for the report, Damian. This was fixed in bpo-11513.

@serhiy-storchaka serhiy-storchaka added the stdlib Python modules in the Lib dir label Jan 28, 2013
@serhiy-storchaka serhiy-storchaka self-assigned this Jan 28, 2013
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant