[Zope-Checkins] CVS: Zope/lib/python/ComponentArchitecture - Adapter.py:1.1.4.1 Component.py:1.1.4.1 Content.py:1.1.4.1 Errors.py:1.1.4.1 FactoryComponents.py:1.1.4.1 InputToName.py:1.1.4.1 InterfaceComponents.py:1.1.4.1 NameProvider.py:1.1.4.1 Package.py:1.1.4.1 Presentation.py:1.1.4.1 Publisher.py:1.1.4.1 Service.py:1.1.4.1 ServiceManager.py:1.1.4.1 __init__.py:1.1.4.1

Shane Hathaway shane@digicool.com
Wed, 22 Aug 2001 15:18:31 -0400


Update of /cvs-repository/Zope/lib/python/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv14914/ComponentArchitecture

Added Files:
      Tag: ComponentArchitecture-branch
	Adapter.py Component.py Content.py Errors.py 
	FactoryComponents.py InputToName.py InterfaceComponents.py 
	NameProvider.py Package.py Presentation.py Publisher.py 
	Service.py ServiceManager.py __init__.py 
Log Message:
Moved from NR-branch.


=== Added File Zope/lib/python/ComponentArchitecture/Adapter.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
"""(simple) Adapter management

If an adapter provides an output for an input:

  - It provides bases of the output for the input.

  - It provides the output (and bases of the output)
    for interfaces that extend the
    input.

"""

from types import TupleType

import Errors

_marker = []  # Create a new marker object.

class GlobalAdapterRegistry:
    
    def __init__(self):
        self._adapters = {}

    def _provideAdapters(self, input, output, adapter, base_output):
        '''
        Registers an adapter using base_output as a key.
        Also registers base interfaces of base_output unless
        the current registry has something more general than
        the new adapter.
        '''
        old = self._adapters.get((input, base_output), None)
        if old is not None:
            oldoutput = old[0]
            if oldoutput is not output:
                if not oldoutput.extends(output):
                    # The new output is not more general, so don't
                    # replace the adapter.
                    # We want to provide the most specific adapter
                    # possible but we don't want more specific
                    # adapters to accidentally override
                    # general adapters.
                    return
        self._adapters[(input, base_output)] = output, adapter
        for b in base_output.__bases__:
            self._provideAdapters(input, output, adapter, b)

    def provideAdapter(self, input, output, adapter):
        '''
        Registers an adapter.
        '''
        self._provideAdapters(input, output, adapter, output)

    def _getAdapter(self, input, output):
        '''
        Finds a registered adapter given two interfaces.
        '''
        a = self._adapters.get((input, output), None)
        if a is not None:
            return a[1]
        bases = getattr(input, '__bases__', ())
        if bases:
            for base in bases:
                a = self._getAdapter(base, output)
                if a is not None:
                    return a
        return None

    def _getAdapterForInterfaces(self, inputs, output):
        '''
        Finds a registered adapter given a hierarchy of input interfaces
        and an output interface.
        '''
        if type(inputs) is TupleType:
            for input in inputs:
                a = self._getAdapterForInterfaces(input, output)
                if a is not None:
                    return a
        else:
            # inputs is an interface object.
            return self._getAdapter(inputs, output)

    def getAdapter(self, object, output, default=_marker):
        '''
        Finds an adapter for an object by examining what it implements.
        '''
        if output.isImplementedBy(object): return object

        inputs = getattr(object, '__implements__', _marker)
        if inputs is not _marker:
            a = self._getAdapterForInterfaces(inputs, output)
        else:
            # No input interfaces known.
            a = self._getAdapter(None, output)

        if a is None:
            if default is not _marker:
                return default
            else:
                raise Errors.AdapterNotFound(object, output)
        # assert output.isImplementedBy(a(object))
        return a(object)



=== Added File Zope/lib/python/ComponentArchitecture/Component.py ===

import Interface


class Component (Interface.Base):
    '''
    '''
    def getId():
        '''
        '''

    def isEnabled():
        '''
        '''



=== Added File Zope/lib/python/ComponentArchitecture/Content.py ===


import Interface
from InterfaceComponents import provideInterface


class Content (Interface.Base):
    '''
    '''


class ContentContainer (Content):
    '''
    '''


provideInterface(Content)
provideInterface(ContentContainer)


=== Added File Zope/lib/python/ComponentArchitecture/Errors.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
''' '''

class AdapterNotFound (Exception):
    """Could not find the necessary adapter for a component"""

    def __init__(self, object, output):
        self.object = object
        self.output = output

    def __str__(self):
        return 'Object: %s, output interface: %s' % (`self.object`,
                                                     `self.output`)


class ObjectAndNameException (Exception):
    def __init__(self, object, name):
        self.object = object
        self.name = name

    def __str__(self):
        return 'Object: %s, name: %s' % (`self.object`,
                                         `self.name`)


class ServiceNotFound (ObjectAndNameException):
    """Could not find a service"""


class PresentationNotFound (ObjectAndNameException):
    """Could not find the necessary presentation for a component"""


class InterfaceNotFound (ObjectAndNameException):
    """Could not find an interface"""


class FactoryNotFound (ObjectAndNameException):
    """Could not find a factory"""



=== Added File Zope/lib/python/ComponentArchitecture/FactoryComponents.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
"""Factory component management
"""

import Errors
import Interface
from InputToName import InputToNameService, InputToNameComponent, \
     GlobalInputToNameRegistry, getRealization, listComponentNames
from Content import ContentContainer
import Acquisition


FACTORY_SERVICE_NAME = 'factories'

class FactoryService (InputToNameService):
    '''
    '''


class FactoryComponent (InputToNameComponent):
    '''
    '''
    def construct():
        '''
        '''


global_reg = GlobalInputToNameRegistry()


_marker = []  # Create a new marker object.

def getFactory(object, name, default=_marker):
    '''
    Finds a factory for children of an object by examining what the
    parent implements.  Searches in services then the global registry.
    '''
    r = getRealization(FACTORY_SERVICE_NAME, global_reg, object, name)
    if r is None:
        if default is not _marker:
            return default
        else:
            raise Errors.FactoryNotFound(object, name)
    return r(object)

def listFactoryNames(object, inputs=None):
    return listComponentNames(FACTORY_SERVICE_NAME, global_reg,
                              object, inputs)


class SimpleFactory (Acquisition.Explicit):

    __implements__ = FactoryComponent

    def __init__(self, fullname, ui_name, inputs, constructor):
        self.fullname = fullname
        self.ui_name = ui_name
        self.inputs = inputs
        self.__dict__['constructor'] = constructor  # Careful not to bind

    def getInputs(self):
        return self.inputs

    def getNames(self):
        return (self.fullname,)

    def getId(self):
        return self.fullname

    def isEnabled(self):
        return 1

    def construct(self):
        return self.__dict__['constructor']()


def provideSimpleFactory(klass, ui_name=None, inputs=(ContentContainer,)):
    fullname = '%s.%s' % (klass.__module__, klass.__name__)
    if ui_name is None:
        ui_name = fullname
    sf = SimpleFactory(fullname, ui_name, inputs, klass)
    for input in inputs:
        global_reg.provideRealization(input, fullname, sf.__of__)



=== Added File Zope/lib/python/ComponentArchitecture/InputToName.py ===

'''
Common interfaces and utilities for components that require an interface
and provide a name.
'''

from types import ListType

from Acquisition import aq_acquire
import Interface
from Service import Service, SERVICE_MANAGER_NAME
from InterfaceComponents import objectImplements
from Package import PackageAwareComponent


class InputToNameService (Service):
    '''
    '''
    def getRealization(inputs, name):
        '''
        Returns a realization of the located component.
        '''

    def listComponentNames(inputs):
        '''
        Returns a list of component names.
        '''


class InputToNameContainer (Interface.Base):
    '''
    '''
    def getRealizationForInput(input, name):
        '''
        Returns a realization of a component.  Returns None if not found.
        Note that this method is passed only one input.  It should
        not look at input.__bases__.
        '''

    def beforeChangeComponent(component, inputs, names):
        '''
        '''

    def beforeRemoveComponent(id):
        '''
        '''

    def listComponents():
        '''
        '''


class InputToNameComponent (PackageAwareComponent):
    '''
    A component that requires some set of interfaces and provides
    a name.
    '''
    def getInputs():
        '''
        '''

    def getNames():
        '''
        '''


class GlobalInputToNameRegistry:
    
    def __init__(self):
        self._comprlz = {}  # {(input, name) -> realization}

    def provideRealization(self, input, name, r):
        '''
        Registers a realization of a component.
        '''
        self._comprlz[(input, name)] = r

    def _getRealization(self, input, name):
        '''
        Finds a registered component realization given an interface
        and a name.
        '''
        r = self._comprlz.get((input, name), None)
        if r is not None:
            return r
        bases = getattr(input, '__bases__', ())
        if bases:
            for base in bases:
                r = self._getRealization(base, name)
                if r is not None:
                    return r
        return None

    def _getRealizationForInterfaces(self, inputs, name):
        '''
        Finds a registered binder given a hierarchy of input interfaces
        and a name.
        '''
        if type(inputs) is TupleType:
            for input in inputs:
                r = self._getRealizationForInterfaces(input, name)
                if r is not None:
                    return r
        else:
            # inputs is an interface object.
            return self._getRealization(inputs, name)

    def getRealization(self, inputs, name):
        if inputs:
            r = self._getRealizationForInterfaces(inputs, name)
        else:
            # No input interfaces known.
            r = self._getRealization(None, name)
        return r

    def listComponentNames(self, inputs):
        '''
        Find the names of everything that can operate on
        any of the given inputs.
        '''
        # inputs is assumed to be a flat list.
        res = []
        for base_input, name in self._comprlz.keys():
            for i in inputs:
                if i == base_input or i.extends(base_input):
                    res.append(name)
        return res


def _findRealization(x_orig, x_ob, x_name, sm, (service_name,
                                           inputs, name, result)):
    '''
    This is an acquisition filter callback.
    '''
    s = sm.getService(service_name, None)
    if s is not None:
        r = s.getRealization(inputs, name)
        if r is not None:
            result.append(r)
            return 1
    return 0        

def getRealization(service_name, global_reg, object, name):
    '''
    Finds a component to apply to an object by examining what it
    implements.  Searches in services then the global registry.
    Returns None if not found.
    '''
    inputs = tuple(objectImplements(object))
    result = []
    try:
        aq_acquire(object, SERVICE_MANAGER_NAME, _findRealization,
                   (service_name, inputs, name, result), 1, None, 1)
    except AttributeError:
        pass
    if result:
        r = result[0]
    else:
        r = global_reg.getRealization(inputs, name)
    return r

def _listNames(x_orig, x_ob, x_name, sm, (service_name, inputs, result)):
    '''
    This is an acquisition filter callback.
    '''
    s = sm.getService(service_name, None)
    if s is not None:
        lst = s.listComponentNames(inputs)
        if lst:
            if type(lst) is not ListType:
                lst = list(lst)
            result.extend(lst)
    return 0

def listComponentNames(service_name, global_reg, object, inputs=None):
    '''
    '''
    if inputs is None:
        inputs = tuple(objectImplements(object))
    result = []
    try:
        aq_acquire(object, SERVICE_MANAGER_NAME, _listNames,
                   (service_name, inputs, result), 1, None, 1)
    except AttributeError:
        pass
    lst = global_reg.listComponentNames(inputs)
    if lst:
        if type(lst) is not ListType:
            lst = list(lst)
        result.extend(lst)
    return result



=== Added File Zope/lib/python/ComponentArchitecture/InterfaceComponents.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
"""Interface component management
"""

import Errors
import Interface
from Interface import CLASS_INTERFACES
from NameProvider import NameProviderService, NameProviderComponent, \
     GlobalNameRegistry, getRealization, listComponentNames


INTERFACES_SERVICE_NAME = 'interfaces'

class InterfacesService (NameProviderService):
    '''
    '''


class InterfaceComponent (NameProviderComponent):
    '''
    '''


class LabelInterface (Interface.Base):
    '''
    A marker interface that is identifiable purely by name.
    '''


global_reg = GlobalNameRegistry()

_marker = []  # Create a new marker object.

def getInterface(object, name, default=_marker):
    i = getRealization(INTERFACES_SERVICE_NAME, global_reg, object, name)
    if i is None:
        if default is not _marker:
            return default
        else:
            raise Errors.InterfaceNotFound(object, name)
    return i

def listInterfaceNames(object):
    return listComponentNames(INTERFACES_SERVICE_NAME, global_reg, object)

def provideInterface(i, name=None):
    if name is None:
        name = i.getName()
    global_reg.provideRealization(name, i)

def objectImplements(object):
    '''
    Dereferences labels.
    '''
    return Interface.objectImplements(object, getInterface=getInterface)



=== Added File Zope/lib/python/ComponentArchitecture/NameProvider.py ===

'''
Common interfaces and utilities for components that simply provide a name.
'''

from types import ListType

from Acquisition import aq_acquire
import Interface
from Service import Service, SERVICE_MANAGER_NAME
from Package import PackageAwareComponent


class NameProviderService (Service):
    '''
    '''
    def getRealization(name):
        '''
        Returns a realization of the named component.
        '''

    def listComponentNames():
        '''
        Returns a list of component names.
        '''


class NameProviderComponent (PackageAwareComponent):
    '''
    A component that provides names.
    '''
    def getNames():
        '''
        '''


class GlobalNameRegistry:
    
    def __init__(self):
        self._comprlz = {}

    def provideRealization(self, name, r):
        '''
        Registers a component realization.
        '''
        self._comprlz[name] = r

    def getRealization(self, name):
        '''
        Finds a registered component given a name, or None.
        '''
        return self._comprlz.get(name, None)

    def listComponentNames(self):
        '''
        '''
        return self._comprlz.keys()


def _findRealization(x_orig, x_ob, x_name, sm, (service_name, name, result)):
    '''
    This is an acquisition filter callback.
    '''
    s = sm.getService(service_name, None)
    if s is not None:
        r = s.getRealization(name)
        if r is not None:
            result.append(r)
            return 1
    return 0        

def getRealization(service_name, global_reg, object, name):
    '''
    Finds a component.  Searches in services then the global registry.
    Returns None if not found.
    '''
    result = []
    try:
        aq_acquire(object, SERVICE_MANAGER_NAME, _findRealization,
                   (service_name, name, result), 1, None, 1)
    except AttributeError:
        pass
    if result:
        r = result[0]
    else:
        r = global_reg.getRealization(name)
    return r

def _listNames(x_orig, x_ob, x_name, sm, (service_name, result)):
    '''
    This is an acquisition filter callback.
    '''
    s = sm.getService(service_name, None)
    if s is not None:
        lst = s.listComponentNames()
        if lst:
            if type(lst) is not ListType:
                lst = list(lst)
            result.extend(lst)
    return 0        

def listComponentNames(service_name, global_reg, object):
    '''
    '''
    result = []
    try:
        aq_acquire(object, SERVICE_MANAGER_NAME, _listNames,
                   (service_name, result), 1, None, 1)
    except AttributeError:
        pass
    lst = global_reg.listComponentNames()
    if lst:
        if type(lst) is not ListType:
            lst = list(lst)
        result.extend(lst)
    return result



=== Added File Zope/lib/python/ComponentArchitecture/Package.py ===


import Interface
from Service import Service
from Component import Component

PACKAGE_SERVICE_NAME = 'packages'


class PackageService (Service):
    '''
    '''
    def getPackage(name, default=None):
        '''
        '''


class Package (Interface.Base):
    '''
    '''


class PackageAwareComponent (Component):
    '''
    '''
    def getPackageRef():
        '''
        Should return an acquisition wrapper.
        '''

    def setPackageRef(r):
        '''
        '''

    def delPackageRef():
        '''
        '''




=== Added File Zope/lib/python/ComponentArchitecture/Presentation.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
"""(simple) Presentation component management
"""

import Errors
import Interface
from InputToName import InputToNameService, InputToNameComponent, \
     GlobalInputToNameRegistry, getRealization


PRESENTATION_SERVICE_NAME = 'presentation'

class PresentationService (InputToNameService):
    '''
    '''


class PresentationComponent (InputToNameComponent):
    '''
    '''


global_reg = GlobalInputToNameRegistry()


_marker = []  # Create a new marker object.

def getPresentation(object, name, default=_marker):
    '''
    Finds a presentation for an object by examining what it implements.
    Searches in services then the global registry.
    '''
    r = getRealization(PRESENTATION_SERVICE_NAME, global_reg, object, name)
    if r is None:
        if default is not _marker:
            return default
        else:
            raise Errors.PresentationNotFound(object, name)
    return r(object)


=== Added File Zope/lib/python/ComponentArchitecture/Publisher.py ===

import Interface

class BrowserPublish (Interface.Base):
    '''
    '''

    def __bobo_traverse__(request, name, fallback=1):
        '''
        Traverses to the next object.
        If fallback argument is set to a false value then the adapter
        should not look for a __bobo_traverse__ attribute of the object.
        '''

    def __browser_default__(request):
        '''
        Allows for a default presentation of content.
        Returns a tuple containing a sequence of names and the object to
        traverse.
        '''


=== Added File Zope/lib/python/ComponentArchitecture/Service.py ===

from Acquisition import aq_acquire
import Errors
import Interface


SERVICE_MANAGER_NAME = '_service_manager'


class Service (Interface.Base):
    '''
    Interface for all Services.
    '''
    def getServiceName(self):
        '''
        '''


def _findService(x_orig, x_ob, x_name, sm, (service_name, result)):
    '''
    This is an acquisition filter callback.
    '''
    s = sm.getService(service_name, None)
    if s is not None:
        result.append(s)
        return 1
    return 0        


_marker = []  # Create a new marker object.

def getService(object, service_name, default=_marker):
    '''
    Finds one implementation of a service in a place.
    '''
    result = []
    try:
        aq_acquire(object, SERVICE_MANAGER_NAME, _findService,
                   (service_name, result), 1, None, 1)
    except AttributeError:
        pass
    if result:
        return result[0]
    else:
        if default is _marker:
            raise Errors.ServiceNotFound(object, service_name)
        else:
            return default


=== Added File Zope/lib/python/ComponentArchitecture/ServiceManager.py ===

import Interface


class ServiceManager (Interface.Base):
    '''
    '''

    def getService(service_name, default=None):
        '''
        '''

    def addService(service_name, object, id):
        '''
        '''

    def listServiceNames():
        '''
        '''


=== Added File Zope/lib/python/ComponentArchitecture/__init__.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################
'''
$Id: __init__.py,v 1.1.4.1 2001/08/22 19:18:30 shane Exp $
'''

import Adapter
r = Adapter.GlobalAdapterRegistry()

getAdapter = r.getAdapter
provideAdapter = r.provideAdapter

import Presentation
getPresentation = Presentation.getPresentation
providePresentation = Presentation.global_reg.provideRealization

from Content import Content, ContentContainer

import FactoryComponents
provideSimpleFactory = FactoryComponents.provideSimpleFactory


__all__ = (
    'getAdapter', 'provideAdapter',
    'getPresentation', 'providePresentation',
    'Content', 'ContentContainer',
    'provideSimpleFactory',
    )