I have solely focused on a routes-based app, so I don't know how much
changes are involved when using traversal.

But the proposed changes really clean up that part of the API.

IMHO the needed changes are mostly "superficial" in that one has to
change the signature of functions and maybe some ZCML.
The underlying logic remains the same.
As long as they are not fault silent it should be straight forward.

I would also like to throw in my suggestion for a function signature
(based on Chris Rossi's):

def context_factory(request, routes_match=None):
    environ = request.environ
    # blah blah blah that uses environ

The benefit would be that the same signature works for traversal and
URL dispatch. By using this signature:

def context_factory(request, routes_match):
    environ = request.environ
    # blah blah blah that uses environ

one could immediately indicate that this is a routes based context factory.

In any case, if/when this moves forward I can make time to test and/or
implement stuff.

         -- Stephan

Chris McDonough wrote:
> On 6/5/09 12:37 PM, Chris Rossi wrote:
>> On Fri, Jun 5, 2009 at 12:01 PM, Tres Seaver <tsea...@palladion.com
>> <mailto:tsea...@palladion.com>> wrote:
>>        I'm assuming that we would fix anything in our repository;  it
>>     should even be possible to do so in a BBB-compatible way, e.g.::
>>        def context_factory(environ=None, **kw):
>>            match_dict = kw.copy()
>>            if environ is not None: # called as "root factory"
>>               match_dict.update(environ['repoze.bfg.matchdict'])
>> Ah, right.  Cool.  Making environ a kw arg preserves backwards
>> compatability for context factories.  So tweaking my suggestion a little
>> bit:
>> class UnifiedFactory(Interface):
>>      def __call__(self, environ=None, **routes_match):
>> """
>>          Replaces concepts of root factory used for traversal and context
>>          factory used for routes, into a single concept.  environ is the
>>          WSGI environment, and the match dict from routes matching, if
>>          applicable, is passed in as kw args.
>> """
>> I'm sure Chris M will come up with something completely different.
> FWIW, the original **kw interface for passing names into a context factory is 
> a 
> little awkward already.  For instance, routes match dicts have unicode 
> *keys*. 
> This is because the names matched in the PATH_INFO by a pattern might 
> actually 
> be themselves encoded; I didn't understand that this was by design until 
> recently.  Currently the urldispatch code encodes the keys from Unicode to 
> UTF-8 
> just so they can be passed as **kw to the context factory (using Unicode keys 
> doesn't work when using **kw as function args).  If I had understood that the 
> keys were *supposed* to be Unicode from the beginning (instead of strings), 
> context factories would have had an interface that looked like this:
> def context_factory(match_dict).
>      ...
> ... which isn't really too far off from:
> def context_factory(environ):
>      match_dict = environ['wgsiorg.routing_args'][1]
> What I *should* have done from the very start was to pass the request object 
> in 
> to both root factories and context factories.  But it's too late for that 
> now; 
> we'd break too many people's apps.
> Anyway, I don't really mind changing the urldispatch stuff radically at this 
> point; I'll fix the docs and our code and help anyone who needs it change 
> their 
> stuff.   If I can make it bwcompat, great, but I'd rather break it now than 
> have 
> to live with it "forever".
> - C

Repoze-dev mailing list

Reply via email to