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

StreamReader Readlines behavior odd #56655

Closed
ThomasBarnet-Lamb mannequin opened this issue Jun 30, 2011 · 3 comments
Closed

StreamReader Readlines behavior odd #56655

ThomasBarnet-Lamb mannequin opened this issue Jun 30, 2011 · 3 comments
Labels
topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@ThomasBarnet-Lamb
Copy link
Mannequin

ThomasBarnet-Lamb mannequin commented Jun 30, 2011

BPO 12446
Nosy @malemburg, @vstinner, @serhiy-storchaka
Superseder
  • bpo-8260: When I use codecs.open(...) and f.readline() follow up by f.read() return bad result
  • 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 2012-12-07.20:03:22.658>
    created_at = <Date 2011-06-30.01:43:25.689>
    labels = ['type-bug', 'expert-unicode']
    title = 'StreamReader Readlines behavior odd'
    updated_at = <Date 2012-12-07.20:03:22.656>
    user = 'https://bugs.python.org/ThomasBarnet-Lamb'

    bugs.python.org fields:

    activity = <Date 2012-12-07.20:03:22.656>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-12-07.20:03:22.658>
    closer = 'serhiy.storchaka'
    components = ['Unicode']
    creation = <Date 2011-06-30.01:43:25.689>
    creator = 'Thomas.Barnet-Lamb'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12446
    keywords = []
    message_count = 3.0
    messages = ['139457', '139464', '177121']
    nosy_count = 4.0
    nosy_names = ['lemburg', 'vstinner', 'Thomas.Barnet-Lamb', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '8260'
    type = 'behavior'
    url = 'https://bugs.python.org/issue12446'
    versions = ['Python 2.7']

    @ThomasBarnet-Lamb
    Copy link
    Mannequin Author

    ThomasBarnet-Lamb mannequin commented Jun 30, 2011

    It appears that StreamReader's readlines method behaves in a strange manner if the StreamReader has, in a previous read operation, decoded more characters than the user asked for; this happens when both the chars and size parameters are used, but only in some circumstances.

    See the following:

    Python 2.7.2 (default, Jun 26 2011, 02:56:25) 
    [GCC 4.0.1 (Apple Inc. build 5490)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import codecs
    >>> 
    >>> ## First make a file
    ... with codecs.open('temp.tmp','wb', encoding='utf8') as f:
    ...     f.write(u'This\u00ab is a test line\nThis is another test line\n')
    ... 
    >>> 
    >>> ## Now open it for reading 
    ... UTF8Reader = codecs.getreader('utf-8')
    >>> with UTF8Reader(codecs.open('temp.tmp','rb')) as f:
    ...     print(repr(f.read(size=5, chars=5)))
    ...     print(f.readlines())
    ... 
    u'This\xab'
    [u' is ']
    # The expected output is 
    # u'This\xab'
    # [u' is a test line\n', u'This is another test line\n']

    I believe the culprit is codecs.py, line 466-467 (the two starred lines below). I think they ought to be replaced with 'pass'.

                if chars < 0:
                    if size < 0:
    *                   if self.charbuffer:
    *                       break      
                    elif len(self.charbuffer) >= size:
                        break

    Best wishes,
    Thomas

    PS - I will apologize in advance for any oversights or mistakes in the formatting etc. of this bug report---this is my first time!

    @ThomasBarnet-Lamb ThomasBarnet-Lamb mannequin added topic-unicode type-bug An unexpected behavior, bug, or error labels Jun 30, 2011
    @ThomasBarnet-Lamb ThomasBarnet-Lamb mannequin changed the title StreamReader Readlines StreamReader Readlines behavior odd Jun 30, 2011
    @vstinner
    Copy link
    Member

    See also bpo-8260.

    @serhiy-storchaka
    Copy link
    Member

    Yes, this is obviously a duplicate of bpo-8260.

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

    No branches or pull requests

    2 participants