Skip to content

codec.StreamReaderWriter: issues with interlaced read-write #56722

Closed

Description

@vstinner
BPO 12513
Nosy @malemburg, @doerwalter, @vstinner

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 2017-06-28.01:39:55.708>
created_at = <Date 2011-07-07.13:12:46.746>
labels = ['type-bug', 'library', 'expert-unicode']
title = 'codec.StreamReaderWriter: issues with interlaced read-write'
updated_at = <Date 2017-06-28.01:39:55.707>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2017-06-28.01:39:55.707>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2017-06-28.01:39:55.708>
closer = 'vstinner'
components = ['Library (Lib)', 'Unicode']
creation = <Date 2011-07-07.13:12:46.746>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 12513
keywords = []
message_count = 3.0
messages = ['139975', '222225', '297128']
nosy_count = 4.0
nosy_names = ['lemburg', 'doerwalter', 'vstinner', 'BreamoreBoy']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue12513'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

Activity

  1. vstinner commented on Jul 7, 2011

    @vstinner
    MemberAuthor

    The following test fails with an AssertionError('a' != 'b') on the first read.

    import codecs
    
    FILENAME = 'test'
    
    with open(FILENAME, 'wb') as f:
        f.write('abcd'.encode('utf-8'))
    with codecs.open(FILENAME, 'r+', encoding='utf-8') as f:
        f.write("1")
    
        pos = f.writer.tell()
        assert pos == 1, "writer pos: %s != 1" % pos
        pos = f.reader.tell()
        assert pos == 1, "reader pos: %s != 1" % pos
        pos = f.stream.tell()
        assert pos == 1, "stream pos: %s != 1" % pos
    
        # read() must call writer.flush()
        char = f.read(1)
        assert char == 'b', "%r != 'b'" % (char,)
        # write() must rewind the raw stream
        f.write('3')
        tail = f.read()
        assert tail == 'd', "%r != 'd'" % (tail,)
        f.flush()
        with open(FILENAME, 'rb') as f:
            assert f.read() == b'1b3d'

    I suppose that readline(), readlines() and __next__() have also issues.

    See also issue bpo-12215: similar issue with io.TextIOWrapper.

  2. BreamoreBoy commented on Jul 3, 2014

    BreamoreBoymannequin
    Mannequin

    Codecs gurus FYI.

  3. vstinner commented on Jun 28, 2017

    @vstinner
    MemberAuthor

    Sorry, I just lost track of this issue and so will just close it. Moreover, I also closed bpo-12215.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-unicodetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions