urllib2.Request's RFC 2822 API inconsistent with email.Message's

Stephen Waterbury golux at comcast.net
Thu Feb 26 10:55:23 EST 2004


I'm creating an HTTP client file-upload function
and noticed that there seems to be no nice way of
using urllib2.Request and email.MIMEMultipart together,
due to their inconsistent representations of RFC 2822
headers.

My naive hope was to inherit from both:

class UploadRequest(urllib2.Request, email.MIMEMultipart)

... but they don't play nice together.
They both have 'add_header' methods, but in Request,
add_header's internal effect is to add the header as a
key,value pair to self.headers (a dictionary), whereas
in Message, add_header has more semantics to deal with,
but basically appends the header to self._headers
(a list of headers represented as tuples).

Ultimately it might be nice if both implemented an
interface for this (maybe RFC2822thingy ... okay,
something serious then :).  In the meantime, it
might be possible for them to be made consistent
by making both self.headers and self._headers
properties whose underlying representation is
self.__headers.  If one of them has to win, my
guess is that changing urllib2 would break fewer
applications.

Cheers,
Steve





More information about the Python-list mailing list