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

codecs: readline() followed by readlines() returns trunkated results #60840

Closed
laurynas mannequin opened this issue Dec 7, 2012 · 3 comments
Closed

codecs: readline() followed by readlines() returns trunkated results #60840

laurynas mannequin opened this issue Dec 7, 2012 · 3 comments
Labels
topic-IO topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@laurynas
Copy link
Mannequin

laurynas mannequin commented Dec 7, 2012

BPO 16636
Nosy @ezio-melotti, @serhiy-storchaka
Superseder
  • bpo-8260: When I use codecs.open(...) and f.readline() follow up by f.read() return bad result
  • Files
  • sample_text.txt: Sample text file that breaks codecs.readlines()
  • 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:53.193>
    created_at = <Date 2012-12-07.17:01:38.760>
    labels = ['type-bug', 'expert-unicode', 'expert-IO']
    title = 'codecs: readline() followed by readlines() returns trunkated results'
    updated_at = <Date 2012-12-07.20:03:53.193>
    user = 'https://bugs.python.org/laurynas'

    bugs.python.org fields:

    activity = <Date 2012-12-07.20:03:53.193>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-12-07.20:03:53.193>
    closer = 'serhiy.storchaka'
    components = ['Unicode', 'IO']
    creation = <Date 2012-12-07.17:01:38.760>
    creator = 'laurynas'
    dependencies = []
    files = ['28242']
    hgrepos = []
    issue_num = 16636
    keywords = []
    message_count = 3.0
    messages = ['177098', '177102', '177111']
    nosy_count = 3.0
    nosy_names = ['ezio.melotti', 'serhiy.storchaka', 'laurynas']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '8260'
    type = 'behavior'
    url = 'https://bugs.python.org/issue16636'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @laurynas
    Copy link
    Mannequin Author

    laurynas mannequin commented Dec 7, 2012

    codecs.readlines() does not read to the end of the file if called after codecs.readline().

    Skimmed through tasks containing codecs in title and could not find a candidate that sounded identical.

    Repro follows:

    $ cat sample_text.txt
    Subject: Incorrect email address
     
    RATER EMAIL rejected an invitation from SUBJECT NAME <SUBJECT EMAIL> in
    the PROJECT TITLE project.  Notification was sent to <RECIPIENT EMAIL>,
    but the email address was no longer valid.
    $ python
    Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
    [GCC 4.7.2] on linux2
    >>>
    >>> import codecs
    >>>
    >>> # No problem if readlines() are run at the beginning:
    >>>
    >>> f_in = codecs.open('sample_text.txt', 'rb', 'utf-8')
    >>> f_in.readlines()
    [u'Subject: Incorrect email address\n', u'\n', u'RATER EMAIL rejected an invitation from SUBJECT NAME <SUBJECT EMAIL> in\n', u'the PROJECT TITLE project.  Notification was sent to <RECIPIENT EMAIL>,\n', u'but the email address was no longer valid.']
    >>> f_in.close()
    >>>
    >>> # Let us try to read the first line separately,
    >>> # and then read the remainder of the file:
    >>>
    >>> f_in = codecs.open('sample_text.txt', 'rb', 'utf-8')
    >>> f_in.readline()
    u'Subject: Incorrect email address\n'
    >>> f_in.readlines()
    [u'\n', u'RATER EMAIL rejected an invitation fro']

    The first readlines() does not read to the end. Subsequent readlines() returns what's left to read.

    sample_text.txt attached.

    @laurynas laurynas mannequin added the type-bug An unexpected behavior, bug, or error label Dec 7, 2012
    @serhiy-storchaka
    Copy link
    Member

    Confirm for 3.x.

    See also bpo-8260, bpo-12446, and bpo-14475.

    @laurynas
    Copy link
    Mannequin Author

    laurynas mannequin commented Dec 7, 2012

    Thank you! This is indeed a duplicate of issues bpo-8260, bpo-12446.

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

    No branches or pull requests

    1 participant