[Zope-Checkins] CVS: Zope/lib/python/ZPublisher/Browser - __init__.py:1.1.2.1 attrpub.py:1.1.2.1 browser.py:1.1.2.1

Jim Fulton jim@zope.com
Thu, 25 Oct 2001 12:34:47 -0400


Update of /cvs-repository/Zope/lib/python/ZPublisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv28851/lib/python/ZPublisher/Browser

Added Files:
      Tag: ComponentArchitecture-branch
	__init__.py attrpub.py browser.py 
Log Message:
Various changes (in progress) to reflect tutorial.
Checking in to sync with Shane.



=== Added File Zope/lib/python/ZPublisher/Browser/__init__.py ===
from browser import HTTPException, NotFound, IBrowserPublish
BrowserPublish = IBrowserPublish
from browser import LeafContentBrowserPublish
from attrpub import AttributePublisher


=== Added File Zope/lib/python/ZPublisher/Browser/attrpub.py ===
from browser import IBrowserPublisher

class AttributePublisher:

    __implements__ = IBrowserPublisher

    def browser_traverse(self, request, name):
        if name[:1] == '_':
            raise 'NotFound'
        return getattr(self, name)

    def browser_default(self, request):
        return "view"
    


=== Added File Zope/lib/python/ZPublisher/Browser/browser.py ===


import Interface
import ComponentArchitecture
from ComponentArchitecture.Content import LeafContent


class HTTPException (Exception):
    status = 500
    description = 'Internal Server Error'


class NotFound (Exception):
    status = 404
    description = 'Not found'


class IBrowserPublish (Interface.Base):

    def _browser_traverse(request, name):
        """
        """

    def _browser_default(request):
        """
        """


class LeafContentBrowserPublish:
    """
    Adapter for content without items.
    """

    __implements__ = BrowserPublish

    def __init__(self, content):
        self._content = content

    def _browser_traverse(self, request, name):
        if name[:3] == '(p)':
            return ComponentArchitecture.getPresentation(
                self._content, name[3:], BrowserPublish)
        else:
            # Can't traverse beyond leaf content.
            raise NotFound, name

    def _browser_default(self, request):
        p = ComponentArchitecture.getPresentation(
            self._content, '', BrowserPublish)
        return p._browser_default(request)


ComponentArchitecture.providePresentation(
    LeafContent, '_default', BrowserPublish, LeafContentBrowserPublish)