[ python-Bugs-1721862 ] email.FeedParser.BufferedSubFile improperly handles "\r\n"

SourceForge.net noreply at sourceforge.net
Sat May 19 18:06:25 CEST 2007


Bugs item #1721862, was opened at 2007-05-19 11:06
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721862&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Sye van der Veen (syeberman)
Assigned to: Nobody/Anonymous (nobody)
Summary: email.FeedParser.BufferedSubFile improperly handles "\r\n"

Initial Comment:
When email.FeedParser.BufferedSubFile sees "\r" at the end of the pushed-in data, it assumes that it is a Macintosh-style line terminator.  Instead, it should request more data, to ensure that the next character is not "\n", which would make it a Windows-style line terminator.  This affects email.message_from_file, which reads in the data in 8192 byte chunks.  The following code demonstrates this:

====================================
from StringIO import StringIO
from email.FeedParser import \
    BufferedSubFile, NeedMoreData

fp = StringIO( "1\r\n10\r\n100\r\n"
               "1000\r\n10000\r\n" )
bsf = BufferedSubFile( )
while True:
    data = fp.read( 3 )
    if not data:
        break
    bsf.push( data )
    for line in bsf:
        if line is NeedMoreData:
            break
        print repr( line )
bsf.close()
====================================

The output is:
====================================
'1\r\n'
'10\r'
'\n'
'100\r\n'
'1000\r\n'
'10000\r'
'\n'
====================================




----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1721862&group_id=5470


More information about the Python-bugs-list mailing list