Skip to content

Commit

Permalink
newstyle class of course
Browse files Browse the repository at this point in the history
  • Loading branch information
janwijbrand committed Jan 19, 2011
0 parents commit 12a4f6a
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/zope/errorview/http.py
@@ -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))

0 comments on commit 12a4f6a

Please sign in to comment.