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

Write mode option for fileinput module. #44329

Closed
antroy mannequin opened this issue Dec 11, 2006 · 6 comments
Closed

Write mode option for fileinput module. #44329

antroy mannequin opened this issue Dec 11, 2006 · 6 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@antroy
Copy link
Mannequin

antroy mannequin commented Dec 11, 2006

BPO 1613500
Nosy @bitdancer, @berkerpeksag
PRs
  • bpo-1613500: Don't hardcode output file mode in fileinput.FileInput #12986
  • Files
  • fileinput_lib_doc_test.diff: Diff file of the changes described above.
  • 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 = None
    closed_at = <Date 2019-04-29.14:56:18.952>
    created_at = <Date 2006-12-11.21:16:56.000>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Write mode option for fileinput module.'
    updated_at = <Date 2019-04-29.14:56:18.947>
    user = 'https://bugs.python.org/antroy'

    bugs.python.org fields:

    activity = <Date 2019-04-29.14:56:18.947>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-04-29.14:56:18.952>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2006-12-11.21:16:56.000>
    creator = 'antroy'
    dependencies = []
    files = ['7651']
    hgrepos = []
    issue_num = 1613500
    keywords = ['patch']
    message_count = 6.0
    messages = ['51510', '51511', '51512', '110506', '182899', '341089']
    nosy_count = 4.0
    nosy_names = ['mkam', 'antroy', 'r.david.murray', 'berker.peksag']
    pr_nums = ['12986']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1613500'
    versions = ['Python 3.8']

    @antroy
    Copy link
    Mannequin Author

    antroy mannequin commented Dec 11, 2006

    The current implementation of the fileinput module allows an optional 'mode' keyword argumant to the FileInput initializer and the input() convenience function.

    The attached patch provides a similar write_mode keyword argument with which to specify the write mode when the 'inplace' option is used.

    Included in the patch file are:

    1. Changes to the fileinput module to accomodate the optional write mode option

    2. Additions to the fileinput tex documentation.

    3. A refactored test module, where the tests have been reorganised into TestCase subclasses, and new tests added for the new functionality.

    @antroy antroy mannequin added stdlib Python modules in the Lib dir labels Dec 11, 2006
    @mkam
    Copy link
    Mannequin

    mkam mannequin commented Dec 15, 2006

    The restriction that you cannot use inplace and openhook together seems somewhat
    arbitrary to me. Have you considered lifting it? From looking at the source it
    seems not too hard to do. There are uses for e.g. inplace editing compressed files.
    This would fit nicely with your patch.

    @antroy
    Copy link
    Mannequin Author

    antroy mannequin commented Dec 18, 2006

    The restriction isn't entirely arbitrary as far as I can see. If you allow the combination of inplace and openhook, then you will also need a writehook option, or the ability to specify a pair of hook function for the openhook. For example, there is a function provided for opening a compressed file for reading. In order to do an inplace edit, you would need to provide a write hook to compress the data on the way back in.

    I think that the implementation of such a change would be open for discussion, and is beyond the scope of a minor change as suggested in this patch. (Perhaps the topic for a future PEP).

    @devdanzin devdanzin mannequin added type-feature A feature request or enhancement labels Mar 30, 2009
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 16, 2010

    This looks like a sizeable patch but the bulk of the changes are to test_fileinput.py. Assigning to myself to take forward, I've got to start sometime. Before I really start moving are there any basic objections to either the original proposal or me having a bash?

    @BreamoreBoy BreamoreBoy mannequin assigned BreamoreBoy Jul 16, 2010
    @bitdancer
    Copy link
    Member

    As far as I can see from a quick look, the problem this patch addresses still exists in Python3, and in Python3 it be (more of?) a bug. That is, the output file is opened in text mode, regardless of whether the input mode was text or bytes. I'm not sure about the solution; it seems like it makes more sense to deduce the output mode from the input mode.

    The test changes, though, are obsolete.

    @berkerpeksag
    Copy link
    Member

    New changeset be6dbfb by Berker Peksag in branch 'master':
    bpo-1613500: Don't hardcode output file mode in fileinput.FileInput (GH-12986)
    be6dbfb

    @berkerpeksag berkerpeksag added the 3.8 only security fixes label Apr 29, 2019
    @berkerpeksag berkerpeksag added the 3.8 only security fixes label Apr 29, 2019
    @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
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants