Re: API thoughts
Barry Warsaw <[email protected]> Mon, 7 Mar 2011 17:15:29 -0500
| Newsgroups | gmane.comp.python.mime.devel |
|---|---|
| Organization | Damn Crazy Followers of the Horn |
| Message-ID | <[email protected]> |
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
signature.asc
(application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBCAAGBQJNdVkCAAoJEBJutWOnSwa/JuQQAKqlmoJTFeQGVhpmIPPXUCDj fVxK9hUWOFDZcVN7+MtHr5zcWNU63oa5KEbL4bPKrrr0nNBlngFlr8sVakEERny3 6K726xZRCsgHq3SN2hL3Le2QBsnNel+Iy69RJJlgs2qbJ217A7DFdC6s6gXK6mZw 5xRVFBrixif+G1bVWR53O26KCUsx9/8fcMHKuj3tEIiORrhw0DUwWXMlogDylR6j OQz6CXpGMZpfFv4zJGvZ7DXPHLM0L/ynRg7c0TqIrUGNTg2rBTw4x6x046HM4q7a of4QN5KbbpvBSAYU/U2uChN6fkwks9PxGN3lRGS8AGPB5y+OBWhSgiyo7GFzMBPL AjFcgF0gE8nBPG434kz6NU6+SIC96k8hmRxIdEOPvF/jretPEiZ+kV5oK5hLzVlH f3DVydqS2f9pjbVnzFxkQFiaftv2ACQ2tIXKvPxjwUEsEnxsbNr0eHi5LFEGyTMr CchPt5ZX76gVE+eUZIrhiVI67BrHttZGeMdEI6NeBfYiEkth5rSWPqcMfTdPqA93 Z8AgllaOKGTdmEmZdOxHH7JjxymfKJVc0rGJG/ntqn45Qs96dQ1tlJc5HGV3TaJo R0jz9rfp78E6zyjQTczbC/BXwahAUhlTZwubRqcGuUw8hkpSb6ImkWbYiwaEo0NH OeGgaieFfI+mPrSWvVkS =KLnu -----END PGP SIGNATURE-----