[Email-SIG] API thoughts
Barry Warsaw
barry at python.org
Mon Mar 7 23:15:29 CET 2011
On Mar 07, 2011, at 09:06 PM, Steffen Daode Nurpmeso wrote:
>I find the interface a bit inconsistent in respect to
>replace_header() (replaces the first header found), __delitem__()
>(drops them all), __setitem__() (appends) in any case.
>(I personally would through these __accessor__ things away, they
>taste a bit strange when used to access email payload.)
I personally like this part of the API, and I think it's held up well under
years of use. In general you don't care about header order, so using various
combinations of del, .get_all(), and __setitem__ work fine. The semantics of
message-as-dict API, header ordering, the various header methods, etc. was
thought out and discussed, and I don't have a problem with them.
>And i would provide a series of functions which can be used
>to get/set/modify header fields and bodies:
>i would check wether the argument is a list and if, it would mean
>"all bodies of a field". This is of course very hard to implement
>if it's done gracefully, i.e. with modification-detection,
>order-preservation etc.
>
>Another, easier to implement, idea would be (yet) an(other)
>iterator which supports in-place editing. Perfect: it could yield
>a (to be invented) class which offers methods like .field(),
>.bodies() (all [bodies] - maybe even as sub-iterator),
>.remove_field() etc...
>Doing it like this would offer the possibility to easily detect
>in-place editing of header bodies etc...
>
>All of these are just suggestions and my very personal point of
>view, of course.
>But one thing is true, and that's that it is currently really hard
>to remove or replace just one body of a field, especially if there
>are multiple bodies for a field.
Well, replace one header retaining original order is a bit difficult, but I've
rarely had to do that. Still, it would probably make sense to add such
functionality -- *if* it can be done without complicating the API or the
implementation. I think it could too, by adding an index argument to
.replace_header(), and using .get_all() to get an ordered list of the headers
of interest.
Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/email-sig/attachments/20110307/61daf3e0/attachment.pgp>
More information about the Email-SIG
mailing list