[Fwd: Re: [Repoze-dev] obob example...]

Chris McDonough chrism at plope.com
Wed Sep 12 03:40:20 UTC 2007


On Sep 11, 2007, at 11:17 PM, Mike Naberezny wrote:

> Chris McDonough wrote:
>> Any method can return a Python structure and if we can serialize  
>> to something we'll try to based on metadata in the request (as  
>> opposed to traversing to a separate method).
>
> OK, that's what I originally understood also, just checking.

Yep.  Things like DAV are going to need some cooperation from the  
application (what is a container?  what is a resource?  how do i ask  
a container for all of its resources?) but alternate serializations  
of fundamental Python data structures from method return values is  
very easy.

>> I'll try to investigate a little.  It'd be trivial to add json  
>> serialization to obob if we could figure out how to decide when to  
>> do it.
>
> I don't have any particular interest in JSON, that was just an  
> example.

Right, sorry to get off track. ;-)

>   If you do get into implementing it...
>
>             if (fs.headers.has_key('content-type') and
>                 'text/xml' in fs.headers['content-type'] and
>                 method == 'POST'):
>                 # Ye haaa, XML-RPC!
>
> Maybe some of the coupling such as this stuff from  
> HTTPRequest#processInputs could be factored out so the request is  
> processed with an intercepting filter pattern.
>
> Each member of the chain would be given an opportunity to analyze  
> the request, and the first one to halt the chain handles the  
> marshaling.  This way we could plug in JSON or whatever else comes  
> along by registering a new one with obob.

That's a good idea.  Maybe something like:

result = lastobject()
serializer = get_serializer(result, request)
return serializer()

You'd be able to register alternate serializers as necessary.

It's tempting to make use of Zope interfaces (http:// 
griddlenoise.blogspot.com/2005/12/zope-component-architecture- 
interfaces.html) to do dispatching like this because it gets us out  
of the business of creating a hardcoded dispatch table or inventing a  
new registry syntax.  But I think it's important that we don't make  
consumers of obob buy into Zope interfaces in order to do their job.   
That said, duck typing is DWIM. ;-)

- C

_______________________________________________
Repoze-dev mailing list
Repoze-dev at lists.repoze.org
http://lists.repoze.org/mailman/listinfo/repoze-dev



More information about the Repoze-dev mailing list