[Email-SIG] fixing the current email module
Barry Warsaw
barry at python.org
Thu Oct 8 15:30:12 CEST 2009
On Oct 8, 2009, at 8:31 AM, Oleg Broytman wrote:
> Not exactly. One can see an AttributeError, but what was the
> cause? why
> a 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_image
and 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_bytes
to 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
> Message
> of some kind? No headers, a single unparsed body?..
Sure, why not? It's valid RFC 822 :)
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 832 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/email-sig/attachments/20091008/f600a009/attachment.pgp>
More information about the Email-SIG
mailing list