On Oct 8, 2009, at 5:18 AM, Oleg Broytman wrote:
Are you going to parse any garbage and create a Message (probably an empty Message) with one defect "cannot parse it at all"?
Yes, although the most pathological stream of bytes will probably produce a message with no headers and an undecodeable body of gibberish bytes, with a .defects list possible one or two items long.
What I disagree with is that if a parser cannot parse input garbage at all it must raise an exception. And if a parser can raise an exception anycalling program must be prepared to catch such exceptions.
Python 2.6.3 (r263:75183, Oct 4 2009, 19:57:34)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from email import message_from_string
>>> with open('/dev/urandom') as wire:
... data = wire.read(1024)
...
>>> msg = message_from_string(data)
>>> # number of headers
... len(msg)
0
>>> len(msg.get_payload())
1024
>>> msg.defects
[]
This actually makes perfect sense. A message with no headers and a
mass of 1024 bytes in its payload is RFC valid!
-Barry
PGP.sig
Description: This is a digitally signed message part
_______________________________________________ Email-SIG mailing list [email protected] Your options: http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com
