[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/XMLRPC - XMLRPCPublication.py:1.1.2.1 XMLRPCPublicationTraverse.py:1.1.2.1 XMLRPCTraversers.py:1.1.2.1 __init__.py:1.1.2.1 xmlrpc.zcml:1.1.2.1

Stephan Richter srichter@cbu.edu
Mon, 4 Mar 2002 00:07:09 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/XMLRPC
In directory cvs.zope.org:/tmp/cvs-serv12070/XMLRPC

Added Files:
      Tag: srichter-OFS_Formulator-branch
	XMLRPCPublication.py XMLRPCPublicationTraverse.py 
	XMLRPCTraversers.py __init__.py xmlrpc.zcml 
Log Message:
This package got a major revamp, so here is what I have done:

- reorganized the package in a way that it becomes multiple-protocol 
  firendly, like the Publisher.

- Separated generic code from Browser code

- Removed Traversers.py and PublicationTraverse.py for the above reason

- Refactor Browser{Publication|PublicationTraverse|Traversers}

- Same as above with XML-RPC


ToDo:

- Write tests.

- Update interfaces



=== Added File Zope3/lib/python/Zope/App/ZopePublication/XMLRPC/XMLRPCPublication.py ===
##############################################################################
#
# Copyright (c) 2001, 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: XMLRPCPublication.py,v 1.1.2.1 2002/03/04 05:07:08 srichter Exp $
"""
from Zope.ContextWrapper import wrapper
from Zope.App.Security.SecurityManagement import getSecurityManager
from Zope.ComponentArchitecture import getRequestView

from XMLRPCPublicationTraverse import XMLRPCPublicationTraverse
from Zope.App.ZopePublication.ZopePublication import ZopePublication 

from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher


class XMLRPCPublication(XMLRPCPublicationTraverse, ZopePublication):
    """XML-RPC publication handling."""
        

    def _parameterSetskin(self, pname, pval, request):
        request.setViewSkin(pval)
        

    def getDefaultTraversal(self, request, ob):

        r = ()

        if IXMLRPCPublisher.isImplementedBy(ob):
            r = ob.xmlrpc_default(request)
        else:
            adapter = getRequestView(ob, '_traverse', request , None)
            if adapter is not None:
                r = adapter.xmlrpc_default(request)
            else:
                return (ob, None)

        if r[0] is ob: return r
        
        wrapped = wrapper.Wrapper(r[0], ob, name=None)
        getSecurityManager().validate(None, wrapped)
        return (wrapped, r[1])


=== Added File Zope3/lib/python/Zope/App/ZopePublication/XMLRPC/XMLRPCPublicationTraverse.py ===
##############################################################################
#
# Copyright (c) 2001, 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: XMLRPCPublicationTraverse.py,v 1.1.2.1 2002/03/04 05:07:08 srichter Exp $
"""

from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from Zope.ComponentArchitecture import getRequestView
from Zope.Publisher.Exceptions import NotFound

from Zope.App.ZopePublication.HTTP.HTTPPublicationTraverse import \
     HTTPPublicationTraverse, HTTPPublicationTraverser


class XMLRPCPublicationTraverse(HTTPPublicationTraverse):
    """ """

    # XXX WE REALLY SHOULD USE INTERFACES HERE

    def getViewFromObject(self, object, name, request):
                          
        if IXMLRPCPublisher.isImplementedBy(object):
            view = object.xmlrpc_traverse(request, name)
        else:
            print request.getViewType()
            adapter = getRequestView(object, '_traverse', request,
                                     self ) # marker 

            if adapter is not self:
                view =  adapter.xmlrpc_traverse(request, name)
            else:
                raise NotFound(object, name, request)

        return view



class XMLRPCPublicationTraverser(HTTPPublicationTraverser,
                                  XMLRPCPublicationTraverse):
    """ """
    pass


=== Added File Zope3/lib/python/Zope/App/ZopePublication/XMLRPC/XMLRPCTraversers.py ===
##############################################################################
#
# Copyright (c) 2001, 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: XMLRPCTraversers.py,v 1.1.2.1 2002/03/04 05:07:08 srichter Exp $
"""

from Zope.Publisher.Exceptions import Unauthorized, NotFound, DebugError
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from Zope.ComponentArchitecture \
     import getRequestView, getRequestDefaultViewName


class DefaultTraverser:
    """
    """
    __implements__ = IXMLRPCPublisher

    def __init__(self, target):
        self.target = target


    def xmlrpc_default(self, request):
        #XXX: (hack), we really need this to be component
        # specific. 
        ob = self.target

        # if ob is not a component return 
        if not hasattr(ob, '__implements__'):
            return ob,()
        
        view_name = getRequestDefaultViewName(ob, request)

        view_uri = "%s;view" % view_name
        return ob, (view_uri,)


    def xmlrpc_traverse(self, request, name):
        """ """
        # TODO:  Look for default view
        ob = self.target
        if name.startswith('_'):
            raise Unauthorized("Name %s begins with an underscore" % `name`)
        if name.endswith(';view'):
            return getRequestView( ob, name[:-5], request)
        if hasattr(ob, name):
            subob = getattr(ob, name)
        else:
            try:
                subob = ob[name]
            except (KeyError, IndexError,
                    TypeError, AttributeError):
                raise NotFound(ob, name, request)

        return subob



=== Added File Zope3/lib/python/Zope/App/ZopePublication/XMLRPC/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 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
# 
##############################################################################
"""
Zope publication package.

$Id: __init__.py,v 1.1.2.1 2002/03/04 05:07:08 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/App/ZopePublication/XMLRPC/xmlrpc.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'
>

  <xmlrpc:view name="_traverse" 
    factory="Zope.App.ZopePublication.XMLRPC.XMLRPCTraversers.DefaultTraverser." />


</zopeConfigure>