[PEAK] start of an error template, and a few questions

Phillip J. Eby pje at telecommunity.com
Wed Feb 11 10:35:43 EST 2004


At 12:31 AM 2/11/04 -0600, Wayne Larsen wrote:
>Here's the start of an error template to be used while debugging.  A few 
>questions I encountered:
>  * My emacs ~ files threw me for a loop for a while - ResourceDirectory 
> won't find the template with the ~ file in the directory - is there any 
> way to exclude ~ files from being seen?

What does the filename look like?  Is it with a trailing '~'?  Maybe I need 
to add a way to exclude a pattern from consideration.


>  * Is it possible to nest list domlets?

Absolutely.  But a quirk of its current implementation is that it checks 
security rights on each item, and at present tuples don't have any security 
declarations.  So, using list as it sits right now really doesn't cut it.


>The request environment is a map, how would you iterate over all items in 
>the map, separating the key and value?

Write a map DOMlet, or a tuple DOMlet.  Or do something like:

from peak.util.Struct import struct

class KeyVal(struct):
     security.allow(security.Anybody,
         key=security.Anybody,
         value=security.Anybody
     )
     __fields__ = 'key','value'


And then use map(KeyVal,env.items()) as the list you use.  This would 
probably work as a quick fix.  Indeed, for any situation where you have 
items that are tuples, this would work pretty decently.  Once there's a 
convenient way in peak.security to make declarations from *outside* a 
class, you could even do this for database results, by declaring 
permissions for the returned record type.


>Any comments on how I'm doing this would be welcome.  I'm not sure if the 
>method for accessing data from the interaction is correct.

I'm surprised you got it to work at all; I thought WebException already 
implemented IWebTraversable.  But I guess now that I think about it, it 
uses the default decorator.

Anyway, you can shorten your expressions somewhat if you use:

     context = binding.Delegate('ob')
     interaction = binding.Delegate('context')
     request = binding.Delegate('interaction')

and then you can refer to self.request instead of 
self.ob.context.interaction.request.  But yes, this is perfectly okay as a 
way to get at the stuff you're getting at.

With regards to requestURI, I'd note that what you may actually want is 
context.traversedURL, which will give you the portion of the URL that was 
successfully traversed, and you may want to provide a "remainingURL" as 
well.  I probably could/should add these to the default WebException bindings.

Anyway, I think you can see now why I say that peak.web isn't quite ready 
for prime time.  The framework is actually in pretty decent shape, but it 
lacks a *lot* of these fit and finish issues that won't be able to be 
really get cleaned up until I've done more "real work" using it.




More information about the PEAK mailing list