[issue21044] tempfile.TemporaryFile() shouldn't have a name attribute

2014-03-24 Thread Antoine Pietri

Antoine Pietri added the comment:

I attached a patch for tarfile with eryksun's suggestion.

--
keywords: +patch
Added file: http://bugs.python.org/file34603/tarfile-fileobjname.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21044] tempfile.TemporaryFile() shouldn't have a name attribute

2014-03-23 Thread Martin Panter

Changes by Martin Panter :


--
nosy: +vadmium

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21044] tempfile.TemporaryFile() shouldn't have a name attribute

2014-03-23 Thread eryksun

eryksun added the comment:

This name attribute is documented here:

http://docs.python.org/3/library/io#io.FileIO.name

3.4 Source:

http://hg.python.org/cpython/file/04f714765c13/Modules/_io/fileio.c#l432

In PY2, os.fdopen sets the name to ''. See the related issue 13781. 
Here's the workaround in gzip.py:

filename = getattr(fileobj, 'name', '')
if not isinstance(filename, (str, bytes)):
filename = ''

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21044] tempfile.TemporaryFile() shouldn't have a name attribute

2014-03-23 Thread Antoine Pietri

Antoine Pietri added the comment:

Alternatively, if the "name" attribute can't be removed, I propose the 
following diff for the tarfile module:

-if name is None and hasattr(fileobj, "name"):
+if name is None and hasattr(fileobj, "name") and isinstance(fileobj.name, str):

:-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21044] tempfile.TemporaryFile() shouldn't have a name attribute

2014-03-23 Thread Antoine Pietri

New submission from Antoine Pietri:

The fact that tempfile.TemporaryFile() has a "name" integer attribute  causes 
weird behavior when interacting with libraries that rely on this attribute 
being a valid string for file objects.
For instance, it led to this exception with the "tarfile" module, which I 
resolved by using a NamedTemporaryFile():

>>> tarfile.open(fileobj=tempfile.TemporaryFile(), mode='w')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.4/tarfile.py", line 1585, in open
return cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.4/tarfile.py", line 1595, in taropen
return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.4/tarfile.py", line 1431, in __init__
self.name = os.path.abspath(name) if name else None
  File "/usr/lib/python3.4/posixpath.py", line 360, in abspath
if not isabs(path):
  File "/usr/lib/python3.4/posixpath.py", line 64, in isabs
return s.startswith(sep)
AttributeError: 'int' object has no attribute 'startswith'

Which is caused by these lines in the "tarfile" module:

if name is None and hasattr(fileobj, "name"):
name = fileobj.name

If TemporaryFile() didn't have a name attribute, tarfile, which doesn't really 
need the file name, would simply have continued without errors.

I am not aware of any place where this "name" integer attribute is actually 
useful, and, as a matter of fact, it is not even documented: 
http://docs.python.org/3.4/library/tempfile.html#tempfile.TemporaryFile

--
components: Library (Lib)
messages: 214662
nosy: seirl
priority: normal
severity: normal
status: open
title: tempfile.TemporaryFile() shouldn't have a name attribute
type: behavior
versions: Python 3.3, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com