On Oct 8, 2009, at 8:31 AM, Oleg Broytman wrote:
Not exactly. One can see an AttributeError, but what was the cause? whya parser has created a broken object? AttributeError doesn't preserve information from parser.
But if you got the AttributeError, you'd still have the original object around to ask more detailed questions about.
On first blush, what I think I like about this is that it fits in with an interesting generic API design. For example, if you have a message instance (and remember, parts-is-parts-is-messages) that you think is an image, you might just do something like:
>>> image = msg.decoded_imageand then 'image' is the png that its Content-Type: image/png implies. If the data wasn't actually parseable as a png, this would raise an AttributeError and you'd then have to do:
>>> bytes = msg.raw_bytesto get the raw data, but you'd still have the msg object around to do that with.
The one possible problem is that Message may have to implement a __getattribute__() to handle this, since you can't know when the class is written whether the data its instances will contain will be valid or not.
I can think of no input for which the parser should *ever* throw an exception.Are you saying that even a random garbage would be parsed to a Messageof some kind? No headers, a single unparsed body?..
Sure, why not? It's valid RFC 822 :) -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
