[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing - GetResource.py:1.1 PresentationNamespaces.py:1.3

Jim Fulton jim@zope.com
Thu, 13 Jun 2002 19:16:15 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing
In directory cvs.zope.org:/tmp/cvs-serv10697/lib/python/Zope/App/Traversing

Modified Files:
	PresentationNamespaces.py 
Added Files:
	GetResource.py 
Log Message:
Got icons working, and, along the way:

- Implemented the icon directive

- Implemented
  http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/ResourcesProposal

- Added a special view, named '', for service manager containers that
  allows resources to have URLs like:

  http://foo.com/@@/resourcename

- Fixed some server code that caused HTTP response data to get
  promoted to unicode

- Updated the folder contents page to display icons.

- Ported icons for folder, file, image, and zptpage. Many more icons
  need to be ported or created.



=== Added File Zope3/lib/python/Zope/App/Traversing/GetResource.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.
# 
##############################################################################
"""

$Id: GetResource.py,v 1.1 2002/06/13 23:15:44 jim Exp $
"""

from Zope.ComponentArchitecture import getService
from Zope.Exceptions import NotFoundError
from Zope.Proxy.ContextWrapper import ContextWrapper

def getResource(ob, name, request):
    resource = queryResource(ob, name, request)
    if resource is None:
        raise NotFoundError(ob, name)
    return resource

def queryResource(ob, name, request, default=None):
    resource_service = getService(ob, 'Resources')
    resource = resource_service.queryResource(ob, name, request)
    if resource is None:
        return default
    return ContextWrapper(resource, resource_service, name=name)
    



=== Zope3/lib/python/Zope/App/Traversing/PresentationNamespaces.py 1.2 => 1.3 ===
 """
 
-from Zope.ComponentArchitecture import getView, getResource
+from Zope.ComponentArchitecture import getView
 from Namespaces import provideNamespaceHandler
 from Exceptions import UnexpectedParameters
 from Zope.Exceptions import NotFoundError
+from Zope.Proxy.ContextWrapper import ContextWrapper
+from GetResource import queryResource
 
 class NoRequest(NotFoundError):
     """Atempt to access a presentation component outside of a request context
@@ -39,7 +41,12 @@
         raise UnexpectedParameters(parameters)
     if not request:
         raise NoRequest(pname)
-    return getResource(ob, name, request)
+
+    resource = queryResource(ob, name, request)
+    if resource is None:
+        raise NotFoundError(ob, pname)
+
+    return resource
 
 provideNamespaceHandler('resource', resource)