Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue21075

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:fileinput should use stdin.buffer for "rb" mode
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.3, Python 3.4
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: brandon-rhodes, josh.r, python-dev, sam.kimbrel, serhiy.storchaka, vstinner
Priority:normalKeywords:patch

Created on2014-03-27 13:42 bybrandon-rhodes, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
21075-fileinput-stdin.diffsam.kimbrel,2014-04-15 16:37review
Messages (6)
msg214952 -(view)Author: Brandon Rhodes (brandon-rhodes)*Date: 2014-03-27 13:42
In Python 3, fileinput.input() returns str lines whether the data iscoming from stdin or from a list of files on the command line. But ifinput(mode='rb') is specified, then its behavior becomes inconsistent:lines from stdin are delivered as already-decoded strings, but datafrom files is delivered (correctly) as bytes.The solution may be that, if a "b" is anywhere in the mode, then input()should read from the bytes stdin.buffer data source instead of fromstdin.Otherwise the "rb" mode is rather useless since you can windup getting text from it anyway depending on how you are invoked.
msg215001 -(view)Author: Josh Rosenberg (josh.r)*(Python triager)Date: 2014-03-27 23:26
There is a similar, (unfixed?) bug,#14156, in argparse as well. Seems like a common failing in the move to Python 3; std*.buffer was introduced, but none of the places that use it were updated, so they all became str only.
msg216331 -(view)Author: Sam Kimbrel (sam.kimbrel)*Date: 2014-04-15 16:37
Patch attached that checks for 'b' in self._mode and sets self._file to sys.stdin.buffer as appropriate.
msg218558 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-05-14 18:12
New changeset7e640fefc9c1 by Serhiy Storchaka in branch '3.4':Issue#21075: fileinput.FileInput now reads bytes from standard stream ifhttp://hg.python.org/cpython/rev/7e640fefc9c1New changeset4041d4077a85 by Serhiy Storchaka in branch 'default':Issue#21075: fileinput.FileInput now reads bytes from standard stream ifhttp://hg.python.org/cpython/rev/4041d4077a85
msg218559 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2014-05-14 18:17
Thank you Sam for your contribution.
msg257362 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2016-01-02 20:45
New changesetded1336bff49 by R David Murray in branch '3.5':#22709: Use stdin as-is if it does not have a buffer attribute.https://hg.python.org/cpython/rev/ded1336bff49
History
DateUserActionArgs
2022-04-11 14:58:00adminsetgithub: 65274
2016-01-02 20:45:09python-devsetmessages: +msg257362
2014-05-14 18:17:41serhiy.storchakasetstatus: open -> closed
versions: + Python 3.3
messages: +msg218559

resolution: fixed
stage: resolved
2014-05-14 18:12:34python-devsetnosy: +python-dev
messages: +msg218558
2014-05-14 17:27:41serhiy.storchakasetassignee:serhiy.storchaka

nosy: +serhiy.storchaka
2014-04-16 06:44:30vstinnersetnosy: +vstinner
2014-04-15 16:37:44sam.kimbrelsetfiles: +21075-fileinput-stdin.diff

nosy: +sam.kimbrel
messages: +msg216331

keywords: +patch
2014-03-27 23:26:29josh.rsetnosy: +josh.r
messages: +msg215001
2014-03-27 13:42:43brandon-rhodescreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp