[PEAK] peak.web bugs

Phillip J. Eby pje at telecommunity.com
Thu Dec 4 14:37:43 EST 2003


At 05:30 PM 12/4/03 +0100, Radek Kanovsky wrote:
>Hi,
>
>I have found two small bugs in peak.web:
>
>[patch snipped]

Thanks.


>Another problem is exception handling. When some Traversable.traverseTo
>raises IWebException (NotFound, NotAllowed, ...), I get 500 - internal
>server error and not 4XX response from server:
>
>     Status: 500 The engines can't take any more, Jim!
>     Content-Length: 0
>     X-Powered-By: Zope (www.zope.org), Python (www.python.org)
>
>     Traceback (most recent call last):
>       File "/www/wm4/wm4.cgi", line 106, in ?
>         publisher.runCGI(sys.stdin, sys.stdout, sys.stderr, os.environ)
>       File "./publish.py", line 432, in runCGI
>       File "./zope/publisher/publish.py", line 146, in publish
>       File "./publish.py", line 266, in handleException
>       File "./errors.py", line 71, in handleException
>       File "./errors.py", line 50, in renderingContext
>     AttributeError: 'Skin' object has no attribute 'subcontext'
>
>Or:
>
>     Status: 500 The engines can't take any more, Jim!
>     Content-Length: 0
>     X-Powered-By: Zope (www.zope.org), Python (www.python.org)
>
>     Traceback (most recent call last):
>       File "/www/wm4/wm4.cgi", line 106, in ?
>         publisher.runCGI(sys.stdin, sys.stdout, sys.stderr, os.environ)
>       File "./publish.py", line 432, in runCGI
>       File "./zope/publisher/publish.py", line 146, in publish
>       File "./publish.py", line 266, in handleException
>       File "./errors.py", line 72, in handleException
>       File "./places.py", line 95, in contextFor
>       File "./places.py", line 245, in traverseTo
>       File "./places.py", line 180, in traverseTo
>       File "./binding/once.py", line 420, in __get__
>       File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 112,
>                 in _once.BaseDescriptor.__get__
>       File "C:\cygwin\home\pje\PEAK\src/peak/binding/_once.pyx", line 100,
>                 in _once.__get__
>       File "./binding/once.py", line 498, in <lambda>
>       File "./errors.py", line 33, in template
>       File "./skins.py", line 95, in getResource
>       File "./publish.py", line 64, in traverse
>       File "./places.py", line 95, in contextFor
>       File "./places.py", line 318, in traverseTo
>     peak.web.errors.NotFound
>
>It seems to me that exception handling system relies on some templates
>that are not available. I don't understand Resources and Skins yet so I
>am guessing.

Your guess is correct; if you look at the master TODO.txt you'll see an 
item there for that.  Basically, there needs to be a resource 
'peak.web/standard_error'.  This can be defined by creating a 
standard_error.xml in the 'peak.web' package.  If you come up with a good 
one, let me know, since I need to put one in for the default.  :)

Any of the allowed attributes of the WebException class can be rendered in 
the template.  If you want custom templates for e.g. NotFound, then you 
need to define a 'peak.web/error_404' resource.

Resources are usually files in a package; this behavior is supplied by the 
DefaultLayer of a Skin.  However, you can also use a ResourceDirectory to 
store resources, in which case you should literally have a subdirectory in 
that directory named 'peak.web', in which you will put any resource files 
for the 'peak.web' package.

In the same way, for any package you create, you can put default resources 
in the package itself, but it can be overridden by a ResourceDirectory in 
the skin containing directories named like 'my.package/'.  This makes it 
easy to supply a ready-to-use package complete with basic UI, but still 
allowing it to be overridden by a user.

Anyway, this would get you past the second error you listed above.  The 
first one, however, looks like some kind of actual error, and is unrelated 
to the resource issue.  It looks like maybe something is creating a 
WebException (or subclass) with a 'context' whose parent is the skin, 
rather than a traversal context.  I'll have to dig around a little and see 
if I can figure out how that happens.




More information about the PEAK mailing list