durusmail: quixote-users: Request subclassing
Request subclassing
2005-11-09
2005-11-09
2005-11-10
2005-11-10
2005-11-10
2005-11-10
Matt Patterson (3 parts)
2005-11-11
Matt Patterson (2 parts)
2005-11-11
2005-11-11
Request subclassing
David Binger
2005-11-10
On Nov 10, 2005, at 6:08 AM, Matt Patterson wrote:

>>
>>     def process_request(self, request):
>>         request.__class__ = MyHTTPRequest
>>      return Publisher.process_request(self, request)
>
> Unless I'm being dense (and hey, that's not unknown...) doing this
> means that you miss the opportunity to do something with the
> Request's __init__ method, which seems like a fairly major loss to me.
>
> So, I think that my proposal provides a better separated way to do
> something I think is important. The keyword option allows people to
> use a different Request without subclassing Publisher, and I'm not
> convinced that that's essential.
>
> I'd be perfectly happy to force people to subclass Publisher to
> make it happen and just add create_request() as a method.

If people are going to the trouble to subclass HTTPRequest, then I
don't think
subclassing Publisher too will present any significant obstacle.  It
seems
better to me to leave the keyword option out.

If the Publisher is be the authority request instance construction,
maybe
it also be the caller of the request constructor.

     def process(self, stdin, env):
         request = HTTPRequest(stdin, env)
         return self.process_request(request)

Wouldn't this simplify the responsibilities of the driver scripts?
(And you could override process to get your customized requests.)


reply