[New-bugs-announce] [issue21476] Inconsitent behaviour between BytesParser.parse and Parser.parse

Łukasz Kucharski report at bugs.python.org
Mon May 12 04:58:05 CEST 2014

New submission from Łukasz Kucharski:

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)

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:
I think it's a minor issue, but it did cause a code to fail with no apparent reason.

components: email
files: mail_test.py
messages: 218309
nosy: barry, r.david.murray, Łukasz.Kucharski
priority: normal
severity: normal
status: open
title: Inconsitent behaviour between BytesParser.parse and Parser.parse
type: behavior
versions: Python 3.3, Python 3.4
Added file: http://bugs.python.org/file35220/mail_test.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list