[Zope3-checkins] CVS: zopeproducts/friendlyfolder - __init__.py:1.1 __init__.pyc:1.1 __init__.py~:1.1 configure.zcml:1.1 configure.zcml~:1.1 interfaces.py:1.1 interfaces.pyc:1.1 interfaces.py~:1.1

Vincenzo Di Somma vincenzo@reflab.it
Mon, 23 Jun 2003 13:32:26 -0400


Update of /cvs-repository/zopeproducts/friendlyfolder
In directory cvs.zope.org:/tmp/cvs-serv16736

Added Files:
	__init__.py __init__.pyc __init__.py~ configure.zcml 
	configure.zcml~ interfaces.py interfaces.pyc interfaces.py~ 
Log Message:
Initial import

=== Added File zopeproducts/friendlyfolder/__init__.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################

"""Friendly Folders Traverser
$Id: __init__.py,v 1.1 2003/06/23 17:32:25 vds Exp $
"""

from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.app.interfaces.container import ISimpleReadContainer, IItemContainer
from zope.publisher.interfaces import NotFound
from zope.component import queryView
from zope.component.interfaces import IFactory
from zope.interface import implements, directlyProvides, directlyProvidedBy
from zope.interface import implementedBy
from zope.app.content.folder import Folder
from zopeproducts.friendlyfolder.interfaces import ICaseInsensitiveFolder
from zopeproducts.friendlyfolder.interfaces import IFriendlyContainerTraverser

__metaclass__ = type

class CaseInsensitiveContainerTraverser:
    """ This adapter allows users to traverse objects in a case insensitive
    way"""

    implements(IBrowserPublisher, IXMLRPCPublisher, IFriendlyContainerTraverser)
    __used_for__ = ISimpleReadContainer

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

    def publishTraverse(self, request, name):
        c = self.context

        subob = c.get(name, None)

        if subob is None:

            view = queryView(c, name, request)
            if view is not None:
                return view

            subob = self.guessTraverse(request, name) 
            
            if subob is None:
                raise NotFound(c, name, request)
         
        return subob

    def guessTraverse(self, request, name):

        c = self.context

        for key in c.keys():
            if key.lower() == name.lower():
                return c[key]
        return None

    def browserDefault(self, request):
        c = self.context
        view_name = getDefaultViewName(c, request)
        view_uri = "@@%s" % view_name
        return c, (view_uri,)


class CaseInsensitiveFolderFactory:
    implements(IFactory)

    def __call__(self):
        """create a folder and mark it as case insensitive"""
        folder = Folder()
        directlyProvides(folder, directlyProvidedBy(folder), ICaseInsensitiveFolder)
        return folder
    
    def getInterfaces(self):
        """see IFactory"""
        return implementedBy(Folder) + ICaseInsensitiveFolder

caseInsensitiveFolderFactory = CaseInsensitiveFolderFactory()


=== Added File zopeproducts/friendlyfolder/__init__.pyc ===
  <Binary-ish file>

=== Added File zopeproducts/friendlyfolder/__init__.py~ ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################

"""Friendly Folders Traverser
$Id: __init__.py~,v 1.1 2003/06/23 17:32:25 vds Exp $
"""

from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.app.interfaces.container import ISimpleReadContainer, IItemContainer
from zope.publisher.interfaces import NotFound
from zope.component import queryView
from zope.interface import implements


class CaseInsensitiveContainerTraverser:
    """ This adapter allows users to traverse objects in a case insensitive
    way"""

    implements(IBrowserPublisher, IXMLRPCPublisher)
    __used_for__ = ISimpleReadContainer

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

    def publishTraverse(self, request, name):
        c = self.context

        subob = c.get(name, None)

        if subob is None:

            view = queryView(c, name, request)
            if view is not None:
                return view

            subob = self.guessTraverse(request, name) 
            
            if not subob:
                raise NotFound(c, name, request)
         
        return subob

    def guessTraverse(self, request, name):

        c = self.context

        for key in c.keys():
            if key.lower() == name.lower():
                return c[key]
        return None
            
    

    def browserDefault(self, request):
        c = self.context
        view_name = getDefaultViewName(c, request)
        view_uri = "@@%s" % view_name
        return c, (view_uri,)



=== Added File zopeproducts/friendlyfolder/configure.zcml ===
<zopeConfigure xmlns="http://namespaces.zope.org/zope">

<!--
<content class=".CaseInsensitiveFolder">

  <implements interface="zope.app.interfaces.container.IContentContainer" />

  <implements
     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
     />

  <factory
      id="CaseInsensitiveFolder"
      permission="zope.ManageContent"
      title="Case insensitive folder"
      description="Case insensitive folder" 
      />

  <allow
      interface="zope.app.interfaces.services.service.Read"
      />

  <require
      permission="zope.ManageServices"
      interface="zope.app.interfaces.services.service.Write"
      />

  <require
      permission="zope.View"
      interface="zope.app.interfaces.container.IReadContainer" 
      />

  <require
      permission="zope.ManageContent"
      interface="zope.app.interfaces.container.IWriteContainer"
      />
</content>

-->

  <factory
      id="CaseInsensitiveFolder"
      permission="zope.ManageContent"
      component=".caseInsensitiveFolderFactory"
      />


<include package=".browser"/>

</zopeConfigure>

=== Added File zopeproducts/friendlyfolder/configure.zcml~ ===
<zopeConfigure xmlns="http://namespaces.zope.org/zope">
<content class=".CaseInsensitiveFolder">

  <implements interface="zope.app.interfaces.container.IContentContainer" />

  <implements
     interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
     />

  <factory
      id="CaseInsensitiveFolder"
      permission="zope.ManageContent"
      title="Case insensitive folder"
      description="Case insensitive folder" 
      />

  <allow
      interface="zope.app.interfaces.services.service.Read"
      />

  <require
      permission="zope.ManageServices"
      interface="zope.app.interfaces.services.service.Write"
      />

  <require
      permission="zope.View"
      interface="zope.app.interfaces.container.IReadContainer" 
      />

  <require
      permission="zope.ManageContent"
      interface="zope.app.interfaces.container.IWriteContainer"
      />
</content>
<include package=".browser"/>

</zopeConfigure>

=== Added File zopeproducts/friendlyfolder/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Friendly Folder Interfaces

XXX longer description goes here.

$Id: interfaces.py,v 1.1 2003/06/23 17:32:25 vds Exp $
"""
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.app.interfaces.content.folder import IFolder

class IFriendlyContainerTraverser(IBrowserPublisher, IXMLRPCPublisher):
    """Friendly Traverser"""

    def guessTraverse(name):
        """Try to travers 'name' using a case insensitive match"""

class ICaseInsensitiveFolder(IFolder):
    """Case Insensitive Folder """
        


=== Added File zopeproducts/friendlyfolder/interfaces.pyc ===
  <Binary-ish file>

=== Added File zopeproducts/friendlyfolder/interfaces.py~ ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Friendly Folder Interfaces

XXX longer description goes here.

$Id: interfaces.py~,v 1.1 2003/06/23 17:32:25 vds Exp $
"""
zope.app.interfaces.content.folder import IFolder

class IFriendlyContainerTraverser(IContainerTraverser):
    """Friendly Traverser"""

    def guessTraverse(name):
        """Try to travers 'name' using a case insensitive match"""

class ICaseInsensitiveFolder(IFolder):
    """Case Insensitive Folder """