Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 12a4f6a
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2011 Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
|
||
from zope.browser.interfaces import ISystemErrorView | ||
from zope.interface import implements | ||
from zope.publisher.interfaces.http import IHTTPException | ||
|
||
class SystemErrorViewMixin(object): | ||
|
||
implements(ISystemErrorView) | ||
|
||
def isSystemError(self): | ||
return True | ||
|
||
class ExceptionViewBase(object): | ||
|
||
implements(IHTTPException) | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
|
||
def update(self): | ||
self.request.response.setStatus(500) | ||
|
||
def render(self): | ||
return u'' | ||
|
||
def __call__(self): | ||
self.update() | ||
return self.render() | ||
|
||
def __str__(self): | ||
return self() | ||
|
||
class ExceptionView(ExceptionViewBase, SystemErrorViewMixin): | ||
pass | ||
|
||
class TraversalExceptionView(ExceptionViewBase): | ||
|
||
def update(self): | ||
if self.request.method =='MKCOL' and self.request.getTraversalStack(): | ||
# MKCOL with non-existing parent. | ||
self.request.response.setStatus(409) | ||
else: | ||
self.request.response.setStatus(404) | ||
|
||
class UnauthorizedView(ExceptionViewBase): | ||
|
||
def update(self): | ||
self.request.unauthorized('basic realm="Zope"') | ||
self.request.response.setStatus(401) | ||
|
||
class MethodNotAllowedView(ExceptionViewBase): | ||
|
||
# XXX define an interface for MethodNotAllowedView components. | ||
|
||
def allowed(self): | ||
# XXX how to determine the allowed HTTP methods? XXX we need | ||
# a safe way to determine the allow HTTP methods. Or should we | ||
# let the application handle it? | ||
return [] | ||
|
||
def update(self): | ||
allow = self.allowed() | ||
self.request.response.setStatus(405) | ||
self.request.response.setHeader('Allow', ', '.join(allow)) |