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

A binary file should show "b" in its mode #48636

Closed
amauryfa opened this issue Nov 22, 2008 · 2 comments
Closed

A binary file should show "b" in its mode #48636

amauryfa opened this issue Nov 22, 2008 · 2 comments
Assignees
Labels
release-blocker type-bug An unexpected behavior, bug, or error

Comments

@amauryfa
Copy link
Member

BPO 4386
Nosy @amauryfa, @benjaminp
Files
  • fileio_mode.patch
  • 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/benjaminp'
    closed_at = <Date 2008-11-22.00:42:13.333>
    created_at = <Date 2008-11-22.00:13:18.187>
    labels = ['type-bug', 'release-blocker']
    title = 'A binary file should show "b" in its mode'
    updated_at = <Date 2008-11-22.00:42:13.332>
    user = 'https://github.com/amauryfa'

    bugs.python.org fields:

    activity = <Date 2008-11-22.00:42:13.332>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-11-22.00:42:13.333>
    closer = 'benjamin.peterson'
    components = []
    creation = <Date 2008-11-22.00:13:18.187>
    creator = 'amaury.forgeotdarc'
    dependencies = []
    files = ['12104']
    hgrepos = []
    issue_num = 4386
    keywords = ['patch', 'needs review']
    message_count = 2.0
    messages = ['76225', '76227']
    nosy_count = 2.0
    nosy_names = ['amaury.forgeotdarc', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'accepted'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4386'
    versions = ['Python 3.0']

    @amauryfa
    Copy link
    Member Author

    The changes following r67300 introduced the .mode and .name attributes on all
    the file-like objects returned by the open() function.

    This also changed the mode returned by a file opened in binary mode: it was
    "rb", now it is "r". The fact that the mode does not "round-trip" (i.e: open(f,
    mode).mode != mode) was considered not important.

    But now it is difficult to see if some opened file was opened in text or binary
    mode; in test_gzip.py, a test had to be changed, and now it does not test
    anything at all: the intent of the test is just to verify that a zip file is
    always opened in binary mode.

    Benjamin suggested to change the mode returned by FileIO objects, so that they
    always contain a 'b'. They also accept an extra 'b' on creation: it is just
    ignored.

    Now, for a file opened in text mode:
    >>> f = open('filename')
    >>> assert f.mode            == 'r'
    >>> assert f.buffer.mode     == 'rb'
    >>> assert f.buffer.raw.mode == 'rb'

    The mode attribute is now always consistent with the one passed to the open()
    function. This also avoid gratuitous breakage with python2.x.

    Patch attached. All tests pass.

    @amauryfa amauryfa added the type-bug An unexpected behavior, bug, or error label Nov 22, 2008
    @benjaminp
    Copy link
    Contributor

    Amaury, thanks for getting the tests to pass. Applied in r67325.

    @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
    release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants