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

S

Stephen Waterbury

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top