[Zope3-checkins] CVS: Zope3/src/zope/app/browser/exception - __init__.py:1.1 configure.zcml:1.1 unauthorized.pt:1.1 unauthorized.py:1.1

Steve Alexander steve@cat-box.net
Wed, 5 Feb 2003 06:34:56 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/exception
In directory cvs.zope.org:/tmp/cvs-serv15275/src/zope/app/browser/exception

Added Files:
	__init__.py configure.zcml unauthorized.pt unauthorized.py 
Log Message:
added view on Unauthorized


=== Added File Zope3/src/zope/app/browser/exception/__init__.py ===
# empty __init__.py file to make this directory into a package


=== Added File Zope3/src/zope/app/browser/exception/configure.zcml ===
<zopeConfigure xmlns="http://namespaces.zope.org/browser">

<defaultView 
    for="zope.exceptions.IUnauthorized"
    name="exception"
    />

<page
    for="zope.exceptions.IUnauthorized"
    name="exception"
    permission="zope.Public"
    template="unauthorized.pt"
    class=".unauthorized.Unauthorized"
    />

</zopeConfigure>


=== Added File Zope3/src/zope/app/browser/exception/unauthorized.pt ===
<html>
<body>
<tal:tag condition="view/issueChallenge" />
<h1>Unauthorized</h1>
<p>You're not allowed in here. Here's a traceback.</p>
<tal:tag replace="structure view/traceback" />
</body>
</html>


=== Added File Zope3/src/zope/app/browser/exception/unauthorized.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""

$Id: unauthorized.py,v 1.1 2003/02/05 11:34:53 stevea Exp $
"""
__metaclass__ = type
import sys
from zope.exceptions.exceptionformatter import format_exception
from zope.app.traversing import getParent
from zope.app.interfaces.security import IAuthenticationService

class Unauthorized:

    def __init__(self, context, request):
        self.context = context
        self.request = request

        t, v, tb = sys.exc_info()
        try:
            self.traceback = ''.join(format_exception(t, v, tb, as_html=1))
        finally:
            tb = None

    def issueChallenge(self):
        principal = self.request.user
        prinreg = getParent(principal)
        assert IAuthenticationService.isImplementedBy(prinreg)
        prinreg.unauthorized(principal.getId(), self.request)