This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Łukasz.Kucharski
Recipients barry, r.david.murray, Łukasz.Kucharski
Date 2014-05-12.02:58:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1399863485.87.0.621460999738.issue21476@psf.upfronthosting.co.za>
In-reply-to
Content
The behaviour of the method for both classes seem to be a little different. Executing `Parser.parse(fp)` does not close the file pointer passed while Executing `BytesParser.parse` does.

I think this caused by fact that `BytesParser.parse` implementation is using `with` statement. Writing this

    fp = TextIOWrapper(file_pointer, encoding='ascii', errors='surrogateescape')
    with fp:
      return self.parser.parse(fp, headersonly)
    file_pointer.seek(0)

The original `file_pointer` gets closed and the call to `seek` fails. 

I am not sure whether such behaviour is intended, and whether, the `with` behaves badly, or the `TextIOWrapper`, or the `BytesParser`, thus I am unable to suggest or provide a patch. But I think the behaviour should be consistent and/or documented.

I attached a file that depicts the issue. The problem originated from SO:
http://stackoverflow.com/questions/23599457/how-to-parse-an-email-in-python-without-closing-the-file
I think it's a minor issue, but it did cause a code to fail with no apparent reason.
History
Date User Action Args
2014-05-12 02:58:05Łukasz.Kucharskisetrecipients: + Łukasz.Kucharski, barry, r.david.murray
2014-05-12 02:58:05Łukasz.Kucharskisetmessageid: <1399863485.87.0.621460999738.issue21476@psf.upfronthosting.co.za>
2014-05-12 02:58:05Łukasz.Kucharskilinkissue21476 messages
2014-05-12 02:58:04Łukasz.Kucharskicreate