homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: aifc.open expects only str or file pointer
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: alastairp, berker.peksag, petri.lehtinen
Priority: normal Keywords: easy, patch

Created on 2012年09月01日 22:33 by alastairp, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue15843.patch berker.peksag, 2012年09月02日 15:01
Messages (4)
msg169673 - (view) Author: Alastair Porter (alastairp) Date: 2012年09月01日 22:33
Passing a unicode filename to aifc.open() results in the argument being treated like a filepointer instead of opening the file.
The argument check,
http://hg.python.org/cpython/file/default/Lib/aifc.py#l332
only checks if the argument is a str. Should this be extended to accept all string-type objects?
Example usage:
>>> import aifc
>>> aifc.open(u"/some/path")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 924, in open
 return Aifc_read(f)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 335, in __init__
 self.initfp(f)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/aifc.py", line 286, in initfp
 chunk = Chunk(file)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/chunk.py", line 61, in __init__
 self.chunkname = file.read(4)
AttributeError: 'unicode' object has no attribute 'read'
msg169691 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012年09月02日 10:41
Since this problem is specific to 2.7, the offending line is actually http://hg.python.org/cpython/file/2.7/Lib/aifc.py#l344:
344 if type(f) == type(''):
msg169706 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012年09月02日 15:01
I've attached a patch with a test case.
msg169715 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012年09月02日 18:22
My fellow coredevs confirm that this would be a new feature, so it's out of scope for 2.7 (which is in bugfix-only mode). It's also deterministic in the sense that you can easily work around it by encoding the unicode filename to the filesystem encoding first.
Closing as wontfix.
History
Date User Action Args
2022年04月11日 14:57:35adminsetgithub: 60047
2012年09月02日 18:22:03petri.lehtinensetstatus: open -> closed
resolution: wont fix
messages: + msg169715

stage: needs patch -> resolved
2012年09月02日 15:01:49berker.peksagsetfiles: + issue15843.patch

nosy: + berker.peksag
messages: + msg169706

keywords: + patch
2012年09月02日 10:41:20petri.lehtinensetnosy: + petri.lehtinen
messages: + msg169691

components: + Library (Lib), - None
keywords: + easy
stage: needs patch
2012年09月01日 22:33:43alastairpcreate

AltStyle によって変換されたページ (->オリジナル) /