[Zope3-checkins] CVS: Zope3/src/zope/app/demo/insensitivefolder - MAINTAINER.txt:1.1 __init__.py:1.1 cifolder_icon.png:1.1 configure.zcml:1.1 ftests.py:1.1 tests.py:1.1

Philipp von Weitershausen philikon at philikon.de
Fri Feb 27 09:50:31 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/demo/insensitivefolder
In directory cvs.zope.org:/tmp/cvs-serv820/app/demo/insensitivefolder

Added Files:
	MAINTAINER.txt __init__.py cifolder_icon.png configure.zcml 
	ftests.py tests.py 
Log Message:
Moved the demo package to zope.app.


=== Added File Zope3/src/zope/app/demo/insensitivefolder/MAINTAINER.txt ===
Stephan Richter

  Email: stephan.richter at tufts.edu

  IRC nick: srichter

=== Added File Zope3/src/zope/app/demo/insensitivefolder/__init__.py ===
##############################################################################
#
# Copyright (c) 2003, 2004 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.
#
##############################################################################
"""Case-Insensitive Traverser and Folder

$Id: __init__.py,v 1.1 2004/02/27 14:50:22 philikon Exp $
"""
from zope.app import zapi
from zope.app.folder import Folder
from zope.app.folder.interfaces import IFolder
from zope.app.container.traversal import ContainerTraverser
from zope.app.interfaces.container import IReadContainer
from zope.component.interfaces import IFactory
from zope.interface import \
     implements, implementedBy, directlyProvides, directlyProvidedBy 
from zope.publisher.interfaces import NotFound


class CaseInsensitiveContainerTraverser(ContainerTraverser):

    __used_for__ = IReadContainer

    def publishTraverse(self, request, name):
        """See zope.publisher.interfaces.browser.IBrowserPublisher"""
        subob = self._guessTraverse(name) 
        if subob is None:
            view = zapi.queryView(self.context, name, request)
            if view is not None:
                return view

            raise NotFound(self.context, name, request)
         
        return subob

    def _guessTraverse(self, name):
        for key in self.context.keys():
            if key.lower() == name.lower():
                return self.context[key]
        return None


class ICaseInsensitiveFolder(IFolder):
    """Marker for folders whose contained items keys are case insensitive.

    When traversing in this folder, all names will be converted to lower
    case. For example, if the traverser requests an item called 'Foo', in
    reality the first item matching 'foo' or any upper-and-lowercase variants
    are looked up in the container."""

class CaseInsensitiveFolderFactory(object):
    """A Factory that creates case-insensitive Folders."""
    implements(IFactory)

    def __call__(self):
        """See zope.component.interfaces.IFactory

        Create a folder and mark it as case insensitive.
        """
        folder = Folder()
        directlyProvides(folder, directlyProvidedBy(folder),
                         ICaseInsensitiveFolder)
        return folder
    
    def getInterfaces(self):
        """See zope.component.interfaces.IFactory"""
        return implementedBy(Folder) + ICaseInsensitiveFolder

caseInsensitiveFolderFactory = CaseInsensitiveFolderFactory()


=== Added File Zope3/src/zope/app/demo/insensitivefolder/cifolder_icon.png ===
  <Binary-ish file>

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


<!-- Register the Traverser -->
<browser:page
    name="_traverse"
    for=".ICaseInsensitiveFolder"
    class=".CaseInsensitiveContainerTraverser"
    permission="zope.Public"
    />

<!-- Case-insensitive Folder Registration -->
<factory
    id="zope.CaseInsensitiveFolder"
    permission="zope.Public"
    component=".caseInsensitiveFolderFactory"
    />

<browser:addMenuItem
    factory="zope.CaseInsensitiveFolder"
    title="Case insensitive Folder" 
    description="A simple case insensitive Folder." 
    permission="zope.ManageContent"
    />

<browser:icon
    name="zmi_icon"
    for=".ICaseInsensitiveFolder"
    file="cifolder_icon.png"
    />

</configure>

=== Added File Zope3/src/zope/app/demo/insensitivefolder/ftests.py ===
##############################################################################
#
# Copyright (c) 2003, 2004 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.
#
##############################################################################
"""Functional tests for the case-insensitive traverser and folder.

$Id: ftests.py,v 1.1 2004/02/27 14:50:22 philikon Exp $
"""
import unittest
from zope.testing.functional import BrowserTestCase
from zope.publisher.interfaces import NotFound

class TestCaseInsensitiveFolder(BrowserTestCase):

    def testAddCaseInsensitiveFolder(self):
        # Step 1: add the case insensitive folder
        response = self.publish(
            '/+/action.html',
            basic='mgr:mgrpw',
            form={'type_name': u'zope.CaseInsensitiveFolder',
                  'id': u'cisf'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/@@contents.html')
        # Step 2: add the file
        response = self.publish('/cisf/+/action.html',
                                basic='mgr:mgrpw',
                                form={'type_name': u'File', 'id': u'foo'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/cisf/@@contents.html')
        # Step 3: check that the file is traversed
        response = self.publish('/cisf/foo')
        self.assertEqual(response.getStatus(), 200)
        response = self.publish('/cisf/foO')
        self.assertEqual(response.getStatus(), 200)
        self.assertRaises(NotFound, self.publish, '/cisf/bar')
                          

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(TestCaseInsensitiveFolder),
        ))

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/demo/insensitivefolder/tests.py ===
##############################################################################
#
# Copyright (c) 2003, 2004 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.
#
##############################################################################
"""Tests for the case-insensitive Folder.

$Id: tests.py,v 1.1 2004/02/27 14:50:22 philikon Exp $
"""
import unittest
from zope.app.container.tests import test_containertraverser  
from zope.app.demo.insensitivefolder import CaseInsensitiveContainerTraverser

class Container(test_containertraverser.TestContainer):

    def keys(self):
        return self.__dict__.keys()

    def __getitem__(self, name):
        return self.__dict__[name]


class InsensitiveCaseTraverserTest(test_containertraverser.TraverserTest):

    def _getTraverser(self, context, request):
        return CaseInsensitiveContainerTraverser(context, request)

    def _getContainer(self, **kw):
        return Container(**kw)
        
    def test_allLowerCaseItemTraversal(self):
        self.assertEquals(
            self.traverser.publishTraverse(self.request, 'foo'),
            self.foo)
        self.assertEquals(
            self.traverser.publishTraverse(self.request, 'foO'),
            self.foo)


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(InsensitiveCaseTraverserTest),
        ))

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list