[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ Move zope.app.component.interface to zope.component.interface (note the singular).

Philipp von Weitershausen philikon at philikon.de
Tue Apr 11 04:23:18 EDT 2006


Log message for revision 66830:
  Move zope.app.component.interface to zope.component.interface (note the singular).
  It contains some helpers regarding interfaces that are useful outside zope.app.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/README.txt
  U   Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/ifacemodule.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/browser/__init__.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/browser/tests/test_directives.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/contentdirective.py
  D   Zope3/branches/jim-adapter/src/zope/app/component/interface.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/metaconfigure.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/tests/test_contentdirective.py
  U   Zope3/branches/jim-adapter/src/zope/app/component/tests/test_directives.py
  D   Zope3/branches/jim-adapter/src/zope/app/component/tests/test_interface.py
  U   Zope3/branches/jim-adapter/src/zope/app/interface/vocabulary.py
  U   Zope3/branches/jim-adapter/src/zope/app/introspector/__init__.py
  U   Zope3/branches/jim-adapter/src/zope/app/introspector/browser.py
  U   Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspector.py
  U   Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspectorview.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/icon.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menumeta.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metaconfigure.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/browser/viewmeta.py
  U   Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metaconfigure.py
  U   Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
  U   Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/contentworkflow.py
  U   Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
  A   Zope3/branches/jim-adapter/src/zope/component/interface.py
  U   Zope3/branches/jim-adapter/src/zope/component/tests.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/README.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/README.txt	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/README.txt	2006-04-11 08:23:15 UTC (rev 66830)
@@ -15,7 +15,7 @@
   >>> class IFoo(Interface):
   ...     pass
 
-  >>> from zope.app.component.interface import provideInterface
+  >>> from zope.component.interface import provideInterface
   >>> provideInterface(None, IFoo)
   >>> provideInterface('IFoo', IFoo)
 

Modified: Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/ifacemodule.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/ifacemodule.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/apidoc/ifacemodule/ifacemodule.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -25,11 +25,11 @@
 from zope.app import zapi
 from zope.interface import implements
 from zope.location import LocationProxy
+from zope.component.interface import queryInterface
+from zope.component.interface import searchInterfaceUtilities
 
 from zope.app.apidoc.interfaces import IDocumentationModule
 from zope.app.apidoc.utilities import ReadContainerBase
-from zope.app.component.interface import queryInterface
-from zope.app.component.interface import searchInterfaceUtilities
 from zope.app.i18n import ZopeMessageFactory as _
 
 class IInterfaceModule(IDocumentationModule):

Modified: Zope3/branches/jim-adapter/src/zope/app/component/browser/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/browser/__init__.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/browser/__init__.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -21,6 +21,8 @@
 from zope.publisher.browser import BrowserView
 from zope.component.interfaces import ComponentLookupError
 from zope.component.interfaces import IFactory
+from zope.component.interface import getInterface, provideInterface
+from zope.component.interface import searchInterface
 from zope.interface.interfaces import IMethod
 from zope.schema.interfaces import IField
 
@@ -30,8 +32,6 @@
 from zope.app.interface.interfaces import IInterfaceBasedRegistry
 from zope.app.component.site import LocalSiteManager
 from zope.app.component.interfaces import ISite
-from zope.app.component.interface import getInterface, provideInterface
-from zope.app.component.interface import searchInterface
 
 class ComponentAdding(Adding):
     """Adding subclass used for registerable components."""

Modified: Zope3/branches/jim-adapter/src/zope/app/component/browser/tests/test_directives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/browser/tests/test_directives.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/browser/tests/test_directives.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -43,7 +43,7 @@
     >>> iface['discriminator']
 
     >>> iface['callable'].__module__
-    'zope.app.component.interface'
+    'zope.component.interface'
 
     >>> iface['args'][1].getName()
     'IDummyUtility'

Modified: Zope3/branches/jim-adapter/src/zope/app/component/contentdirective.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/contentdirective.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/contentdirective.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -20,21 +20,21 @@
 import warnings
 from types import ModuleType
 from persistent.interfaces import IPersistent
+
 from zope.component.interfaces import IFactory
 from zope.component.factory import Factory
+from zope.component.interface import provideInterface
 from zope.interface import classImplements
 from zope.schema.interfaces import IField
 from zope.configuration.exceptions import ConfigurationError
 from zope.location.interfaces import ILocation
 from zope.annotation.interfaces import IAttributeAnnotatable
 
-from zope.app.component.interface import provideInterface
 from zope.app.component.interfaces import ILocalUtility
+from zope.app.component.metaconfigure import utility
 from zope.app.security.protectclass import protectLikeUnto, protectName
 from zope.app.security.protectclass import protectSetAttribute
 
-from zope.app.component.metaconfigure import utility
-
 PublicPermission = 'zope.Public'
 
 def dottedName(klass):

Deleted: Zope3/branches/jim-adapter/src/zope/app/component/interface.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/interface.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/interface.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -1,286 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Interface utility functions
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from types import ClassType
-
-import zope.component
-from zope.component.interfaces import ComponentLookupError
-from zope.interface import directlyProvides, directlyProvidedBy
-from zope.interface.interfaces import IInterface
-
-def provideInterface(id, interface, iface_type=None, info=''):
-    """register Interface with global site manager as utility
-
-    >>> from zope.app.testing import placelesssetup
-    >>> placelesssetup.setUp()
-    >>> gsm = zope.component.getGlobalSiteManager()
-
-    >>> from zope.interface import Interface
-    >>> from zope.interface.interfaces import IInterface
-    >>> from zope.app.content.interfaces import IContentType
-
-    >>> class I(Interface):
-    ...     pass
-    >>> IInterface.providedBy(I)
-    True
-    >>> IContentType.providedBy(I)
-    False
-    >>> interfaces = gsm.getUtilitiesFor(IContentType)
-    >>> list(interfaces)
-    []
-
-    # provide first interface type
-    >>> provideInterface('', I, IContentType)
-    >>> IContentType.providedBy(I)
-    True
-    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
-    >>> [name for (name, iface) in interfaces]
-    [u'zope.app.component.interface.I']
-    >>> [iface.__name__ for (name, iface) in interfaces]
-    ['I']
-
-    # provide second interface type
-    >>> class IOtherType(IInterface):
-    ...     pass
-    >>> provideInterface('', I, IOtherType)
-
-    >>> IContentType.providedBy(I)
-    True
-    >>> IOtherType.providedBy(I)
-    True
-    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
-    >>> [name for (name, iface) in interfaces]
-    [u'zope.app.component.interface.I']
-    >>> interfaces = list(gsm.getUtilitiesFor(IOtherType))
-    >>> [name for (name, iface) in interfaces]
-    [u'zope.app.component.interface.I']
-
-    >>> class I1(Interface):
-    ...     pass
-    >>> provideInterface('', I1)
-    >>> IInterface.providedBy(I1)
-    True
-    >>> IContentType.providedBy(I1)
-    False
-    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
-    >>> [name for (name, iface) in interfaces]
-    [u'zope.app.component.interface.I']
-    >>> [iface.__name__ for (name, iface) in interfaces]
-    ['I']
-    >>> placelesssetup.tearDown()
-    """
-    if not id:
-        id = "%s.%s" % (interface.__module__, interface.__name__)
-
-    if not IInterface.providedBy(interface):
-        if not isinstance(interface, (type, ClassType)):
-            raise TypeError(id, "is not an interface or class")
-        return
-
-    if iface_type is not None:
-        if not iface_type.extends(IInterface):
-            raise TypeError(iface_type, "is not an interface type")
-        directlyProvides(interface, iface_type, directlyProvidedBy(interface))
-    else:
-        iface_type = IInterface
-        
-    gsm = zope.component.getGlobalSiteManager()
-    gsm.registerUtility(interface, iface_type, id, info)
-
-
-def getInterface(context, id):
-    """return interface or ComponentLookupError
-
-    >>> from zope.app.testing import placelesssetup
-    >>> placelesssetup.setUp()
-
-    >>> from zope.interface import Interface
-    >>> from zope.app.content.interfaces import IContentType
-
-    >>> class I4(Interface):
-    ...     pass
-    >>> IInterface.providedBy(I4)
-    True
-    >>> IContentType.providedBy(I4)
-    False
-    >>> getInterface(None, 'zope.app.component.interface.I4')
-    Traceback (most recent call last):
-    ...
-    ComponentLookupError: zope.app.component.interface.I4
-    >>> provideInterface('', I4, IContentType)
-    >>> IContentType.providedBy(I4)
-    True
-    >>> iface = queryInterface( """\
-                """ 'zope.app.component.interface.I4')
-    >>> iface.__name__
-    'I4'
-    >>> placelesssetup.tearDown()    
-    """
-    iface = queryInterface(id, None)
-    if iface is None:
-        raise ComponentLookupError(id)
-    return iface
-
-
-def queryInterface(id, default=None):
-    """return interface or ``None``
-
-    >>> from zope.app.testing import placelesssetup
-    >>> placelesssetup.tearDown()
-    >>> placelesssetup.setUp()
-
-    >>> from zope.interface import Interface
-    >>> from zope.interface.interfaces import IInterface
-    >>> from zope.app.content.interfaces import IContentType
-
-    >>> class I3(Interface):
-    ...     pass
-    >>> IInterface.providedBy(I3)
-    True
-    >>> IContentType.providedBy(I3)
-    False
-    >>> queryInterface('zope.app.component.interface.I3')
-    
-    >>> provideInterface('', I3, IContentType)
-    >>> IContentType.providedBy(I3)
-    True
-    >>> iface = queryInterface('zope.app.component.interface.I3')
-    >>> iface.__name__
-    'I3'
-    >>> placelesssetup.tearDown()
-    """
-    return zope.component.queryUtility(IInterface, id, default)
-
-
-def searchInterface(context, search_string=None, base=None):
-    """Interfaces search
-
-    >>> from zope.app.testing import placelesssetup
-    >>> placelesssetup.setUp()
-
-    >>> from zope.interface import Interface
-    >>> from zope.interface.interfaces import IInterface
-    >>> from zope.app.content.interfaces import IContentType
-
-    >>> class I5(Interface):
-    ...     pass
-    >>> IInterface.providedBy(I5)
-    True
-    >>> IContentType.providedBy(I5)
-    False
-    >>> searchInterface(None, 'zope.app.component.interface.I5')
-    []
-    >>> provideInterface('', I5, IContentType)
-    >>> IContentType.providedBy(I5)
-    True
-    >>> iface = searchInterface(None, 'zope.app.component.interface.I5')
-    >>> iface[0].__name__
-    'I5'
-    >>> placelesssetup.tearDown()
-    """
-    return [iface_util[1]
-            for iface_util in
-            searchInterfaceUtilities(context, search_string, base)]
-
-
-def searchInterfaceIds(context, search_string=None, base=None):
-    """Interfaces search
-
-    >>> from zope.app.testing import placelesssetup
-    >>> placelesssetup.setUp()
-
-    >>> from zope.interface import Interface
-    >>> from zope.interface.interfaces import IInterface
-    >>> from zope.app.content.interfaces import IContentType
-
-    >>> class I5(Interface):
-    ...     pass
-    >>> IInterface.providedBy(I5)
-    True
-    >>> IContentType.providedBy(I5)
-    False
-    >>> searchInterface(None, 'zope.app.component.interface.I5')
-    []
-    >>> provideInterface('', I5, IContentType)
-    >>> IContentType.providedBy(I5)
-    True
-    >>> iface = searchInterfaceIds(None,
-    ...                        'zope.app.component.interface.I5')
-    >>> iface
-    [u'zope.app.component.interface.I5']
-    >>> placelesssetup.tearDown()
-    """
-    return [iface_util[0]
-            for iface_util in
-            searchInterfaceUtilities(context, search_string, base)]
-
-
-def searchInterfaceUtilities(context, search_string=None, base=None):
-    gsm = zope.component.getGlobalSiteManager()
-    iface_utilities = gsm.getUtilitiesFor(IInterface)
-
-    if search_string:
-        search_string = search_string.lower()
-        iface_utilities = [iface_util for iface_util in iface_utilities
-                           if (getInterfaceAllDocs(iface_util[1]).\
-                               find(search_string) >= 0)]
-    if base:
-        res = [iface_util for iface_util in iface_utilities
-               if iface_util[1].extends(base)]
-    else:
-        res = [iface_util for iface_util in iface_utilities]
-    return res
-
-
-def getInterfaceAllDocs(interface):
-    iface_id = '%s.%s' %(interface.__module__, interface.__name__)
-    docs = [str(iface_id).lower(),
-            str(interface.__doc__).lower()]
-
-    if IInterface.providedBy(interface):
-        for name in interface:
-            docs.append(
-                str(interface.getDescriptionFor(name).__doc__).lower())
-
-    return '\n'.join(docs)
-
-
-def nameToInterface(context, id):
-    if id == 'None':
-        return None
-    iface = getInterface(context, id)
-    return iface
-
-def interfaceToName(context, interface):
-    if interface is None:
-        return 'None'
-    items = searchInterface(context, base=interface)
-    ids = [('%s.%s' %(iface.__module__, iface.__name__))
-           for iface in items
-           if iface == interface]
-
-    if not ids:
-        # Do not fail badly, instead resort to the standard
-        # way of getting the interface name, cause not all interfaces
-        # may be registered as utilities.
-        return interface.__module__ + '.' + interface.__name__
-
-    assert len(ids) == 1, "Ambiguous interface names: %s" % ids
-    return ids[0]
-

Modified: Zope3/branches/jim-adapter/src/zope/app/component/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/metaconfigure.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/metaconfigure.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -40,7 +40,7 @@
     method=getattr(zope.component.getGlobalSiteManager(), methodName)
     method(*args, **kwargs)
 
-from zope.app.component.interface import provideInterface
+from zope.component.interface import provideInterface
 def interface(_context, interface, type=None, name=''):
     _context.action(
         discriminator = None,

Modified: Zope3/branches/jim-adapter/src/zope/app/component/tests/test_contentdirective.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/tests/test_contentdirective.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/tests/test_contentdirective.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -18,15 +18,15 @@
 import unittest
 from StringIO import StringIO
 
+from zope.component.interfaces import IFactory
+from zope.component.interfaces import ComponentLookupError
+from zope.component.interface import queryInterface
+from zope.configuration.xmlconfig import xmlconfig, XMLConfig
+
 import zope.app.security
 import zope.app.component
-
 from zope.app import zapi
-from zope.component.interfaces import IFactory
-from zope.component.interfaces import ComponentLookupError
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.component.interface import queryInterface
 
 # explicitly import ExampleClass and IExample using full paths
 # so that they are the same objects as resolve will get.

Modified: Zope3/branches/jim-adapter/src/zope/app/component/tests/test_directives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/tests/test_directives.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/tests/test_directives.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -26,22 +26,18 @@
 from zope.component import createObject
 from zope.component.interfaces import IDefaultViewName
 from zope.component.registry import SubscriptionRegistration
+from zope.component.interfaces import ComponentLookupError
+from zope.component.interface import queryInterface
 
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.configuration.exceptions import ConfigurationError
 from zope.configuration.xmlconfig import ZopeXMLConfigurationError
+from zope.security.proxy import removeSecurityProxy, getTestProxyItems
+from zope.security.checker import ProxyFactory, selectChecker
 
-from zope.security.proxy import removeSecurityProxy
-from zope.security.proxy import getTestProxyItems
-from zope.security.checker import ProxyFactory
-from zope.security.checker import selectChecker
-
 import zope.app.component
-from zope.component.interfaces import ComponentLookupError
-
 from zope.app import zapi
 from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.component.interface import queryInterface
 from zope.app.component.metaconfigure import interface
 from zope.app.component.tests.adapter import A1, A2, A3, Handler
 from zope.app.component.tests.adapter import I1, I2, I3, IS
@@ -51,7 +47,6 @@
 from zope.app.content.interfaces import IContentType
 
 from zope.app.component.tests import module, exampleclass
-from zope.app.component.interface import queryInterface
 
 # TODO: tests for other directives needed
 

Deleted: Zope3/branches/jim-adapter/src/zope/app/component/tests/test_interface.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/tests/test_interface.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/component/tests/test_interface.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -1,28 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Interface utility tests
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite('zope.app.component.interface'),
-        ))
-
-if __name__ == "__main__":
-    unittest.TextTestRunner().run(test_suite())
-

Modified: Zope3/branches/jim-adapter/src/zope/app/interface/vocabulary.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/interface/vocabulary.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/interface/vocabulary.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -21,7 +21,7 @@
 from zope.security.proxy import removeSecurityProxy
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
 from zope.schema.interfaces import IVocabularyFactory
-from zope.app.component.interface import interfaceToName
+from zope.component.interface import interfaceToName
 
 
 class ObjectInterfacesVocabulary(SimpleVocabulary):

Modified: Zope3/branches/jim-adapter/src/zope/app/introspector/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/introspector/__init__.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/introspector/__init__.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -23,9 +23,8 @@
 from zope.interface.interfaces import IInterface
 from zope.interface.interface import InterfaceClass
 from zope.security.proxy import removeSecurityProxy
+from zope.component.interface import searchInterface, getInterface
 
-from zope.app import zapi
-from zope.app.component.interface import searchInterface, getInterface
 from zope.app.introspector.interfaces import IIntrospector
 
 ##############################################################################

Modified: Zope3/branches/jim-adapter/src/zope/app/introspector/browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/introspector/browser.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/introspector/browser.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -21,9 +21,9 @@
 from zope.interface import directlyProvides, directlyProvidedBy
 from zope.proxy import removeAllProxies
 from zope.publisher.browser import BrowserView
+from zope.component.interface import getInterface
 
 from zope.app import zapi
-from zope.app.component.interface import getInterface
 from zope.app.introspector.interfaces import IIntrospector
 
 class IntrospectorView(BrowserView):

Modified: Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspector.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspector.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspector.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -18,14 +18,17 @@
 import zope.deprecation
 
 from unittest import TestCase, TestSuite, main, makeSuite
+
+from zope.interface import Interface, Attribute, implements, directlyProvides
+from zope.interface.verify import verifyObject
+from zope.component.interface import provideInterface
+
+from zope.app.testing import placelesssetup
+
 zope.deprecation.__show__.off()
 from zope.app.introspector import Introspector
 from zope.app.introspector.interfaces import IIntrospector
 zope.deprecation.__show__.on()
-from zope.interface import Interface, Attribute, implements, directlyProvides
-from zope.interface.verify import verifyObject
-from zope.app.component.interface import provideInterface
-from zope.app.testing import placelesssetup
 
 class ITestClass(Interface):
     def drool():

Modified: Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspectorview.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspectorview.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/introspector/tests/test_introspectorview.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -19,12 +19,14 @@
 
 import zope.deprecation
 
-from zope.app.component.testing import PlacefulSetup
 from zope.publisher.browser import TestRequest
 from zope.interface import Interface, directlyProvidedBy
 from zope.interface import directlyProvides, implements
-from zope.app.component.interface import provideInterface
+from zope.component.interface import provideInterface
+
+from zope.app.component.testing import PlacefulSetup
 from zope.app.testing import ztapi, setup
+
 zope.deprecation.__show__.off()
 from zope.app.introspector.interfaces import IIntrospector
 from zope.app.introspector import Introspector

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/icon.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/icon.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/icon.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -22,8 +22,8 @@
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.configuration.exceptions import ConfigurationError
 from zope.traversing.namespace import getResource
+from zope.component.interface import provideInterface
 
-from zope.app.component.interface import provideInterface
 from zope.app.component.metaconfigure import handler
 from zope.app.publisher.browser import metaconfigure
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menumeta.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menumeta.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/menumeta.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -15,29 +15,27 @@
 
 $Id$
 """
+import zope.component
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface.interface import InterfaceClass
 from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.security.checker import InterfaceChecker, CheckerPublic
+from zope.component.interface import provideInterface
 
-from zope.app import zapi
-from zope.app.component.interface import provideInterface
 from zope.app.component.metaconfigure import adapter, proxify
 from zope.app.component.metaconfigure import utility
+from zope.app.component.contentdirective import ClassDirective
 from zope.app.pagetemplate.engine import Engine
+from zope.app.container.interfaces import IAdding
 from zope.app.publisher.browser.menu import BrowserMenu
 from zope.app.publisher.browser.menu import BrowserMenuItem, BrowserSubMenuItem
 from zope.app.publisher.interfaces.browser import IBrowserMenu
 from zope.app.publisher.interfaces.browser import IBrowserMenuItem
 from zope.app.publisher.interfaces.browser import IMenuItemType
-
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.app.container.interfaces import IAdding
-from zope.app.component.contentdirective import ClassDirective
 from zope.app.publisher.interfaces.browser import AddMenu
 
-
 # Create special modules that contain all menu item types
 from types import ModuleType as module
 import sys
@@ -208,7 +206,7 @@
             " is optional but can\'t be empty"
             )
 
-    gsm = zapi.getGlobalSiteManager()
+    gsm = zope.component.getGlobalSiteManager()
     if gsm.adapters.lookup((for_, layer),
                            Interface, view_name) is None:
         raise ConfigurationError(
@@ -240,7 +238,7 @@
 
     if menu is not None:
         if isinstance(menu, (str, unicode)):
-            menu = zapi.getUtility(IMenuItemType, menu)
+            menu = zope.component.getUtility(IMenuItemType, menu)
             if menu is None:
                 raise ValueError("Missing menu id '%s'" % menu)
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metaconfigure.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metaconfigure.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -17,6 +17,7 @@
 """
 import warnings
 from zope.component.interfaces import IDefaultViewName
+from zope.component.interface import provideInterface
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface import directlyProvides
 from zope.interface.interface import InterfaceClass
@@ -31,7 +32,6 @@
 from zope.app.publisher.browser.resourcemeta import resourceDirectory
 from zope.app.publisher.browser.i18nresourcemeta import I18nResource
 from zope.app.publisher.browser.viewmeta import view
-from zope.app.component.interface import provideInterface
 
 # BBB 2006/02/18, to be removed after 12 months
 import zope.deprecation

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/viewmeta.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/viewmeta.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -17,7 +17,9 @@
 """
 import os
 
+from zope.component import queryMultiAdapter
 from zope.component.interfaces import ComponentLookupError, IDefaultViewName
+from zope.component.interface import provideInterface
 from zope.interface import implements, classImplements, Interface
 from zope.publisher.interfaces import NotFound
 from zope.security.checker import CheckerPublic, Checker, defineChecker
@@ -27,8 +29,6 @@
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.browser import BrowserView
 
-from zope.app import zapi
-from zope.app.component.interface import provideInterface
 from zope.app.component.metaconfigure import handler
 from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
@@ -281,7 +281,7 @@
 
                 if name in pages:
                     return getattr(self, pages[name])
-                view = zapi.queryMultiAdapter((self, request), name=name)
+                view = queryMultiAdapter((self, request), name=name)
                 if view is not None:
                     return view
 
@@ -294,7 +294,7 @@
 
                 if name in pages:
                     return getattr(self, pages[name])
-                view = zapi.queryMultiAdapter((self, request), name=name)
+                view = queryMultiAdapter((self, request), name=name)
                 if view is not None:
                     return view
 

Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metaconfigure.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/xmlrpc/metaconfigure.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -20,9 +20,8 @@
 from zope.security.checker import CheckerPublic, Checker
 from zope.configuration.exceptions import ConfigurationError
 from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
+from zope.component.interface import provideInterface
 
-from zope.app import zapi
-from zope.app.component.interface import provideInterface
 from zope.app.component.metaconfigure import handler
 from zope.app.publisher.xmlrpc import MethodPublisher
 

Modified: Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -21,11 +21,11 @@
 from zope.interface.interface import InterfaceClass
 from zope.interface.interfaces import IInterface
 from zope.component.interfaces import ComponentLookupError
+from zope.component.interface import getInterface, searchInterface
 from zope.traversing.api import traverse
 
 from zope.app.component.interfaces import ILocalUtility
 from zope.app.component.testing import PlacefulSetup
-from zope.app.component.interface import getInterface, searchInterface
 from zope.app.component.interfaces.registration import ActiveStatus
 from zope.app.component.interfaces.registration import InactiveStatus
 from zope.app.component.interfaces.registration import IRegistered

Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/contentworkflow.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/contentworkflow.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/contentworkflow.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -16,12 +16,12 @@
 $Id$
 """
 from zope.component import getUtilitiesFor
+from zope.component.interface import nameToInterface, interfaceToName
 from zope.interface import Interface
 from zope.publisher.browser import BrowserView
 from zope.schema import Choice, List
 from zope.security.proxy import removeSecurityProxy 
 
-from zope.app.component.interface import nameToInterface, interfaceToName
 from zope.app.i18n import ZopeMessageFactory as _
 from zope.app.form.utility import setUpWidgets
 from zope.app.form.interfaces import IInputWidget

Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -19,9 +19,9 @@
 import re
 
 from transaction import commit
+from zope.interface import Interface
+from zope.component.interface import nameToInterface
 
-from zope.interface import Interface
-from zope.app.component.interface import nameToInterface
 from zope.app import zapi
 from zope.app.testing.functional import BrowserTestCase
 from zope.app.testing.setup import addUtility

Copied: Zope3/branches/jim-adapter/src/zope/component/interface.py (from rev 66723, Zope3/branches/jim-adapter/src/zope/app/component/interface.py)
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/interface.py	2006-04-09 13:48:55 UTC (rev 66723)
+++ Zope3/branches/jim-adapter/src/zope/component/interface.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -0,0 +1,266 @@
+##############################################################################
+#
+# 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.1 (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.
+#
+##############################################################################
+"""Interface utility functions
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+from types import ClassType
+
+import zope.component
+from zope.component.interfaces import ComponentLookupError
+from zope.interface import directlyProvides, directlyProvidedBy
+from zope.interface.interfaces import IInterface
+
+def provideInterface(id, interface, iface_type=None, info=''):
+    """register Interface with global site manager as utility
+
+    >>> gsm = zope.component.getGlobalSiteManager()
+
+    >>> from zope.interface import Interface
+    >>> from zope.interface.interfaces import IInterface
+    >>> from zope.app.content.interfaces import IContentType
+
+    >>> class I(Interface):
+    ...     pass
+    >>> IInterface.providedBy(I)
+    True
+    >>> IContentType.providedBy(I)
+    False
+    >>> interfaces = gsm.getUtilitiesFor(IContentType)
+    >>> list(interfaces)
+    []
+
+    # provide first interface type
+    >>> provideInterface('', I, IContentType)
+    >>> IContentType.providedBy(I)
+    True
+    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
+    >>> [name for (name, iface) in interfaces]
+    [u'zope.component.interface.I']
+    >>> [iface.__name__ for (name, iface) in interfaces]
+    ['I']
+
+    # provide second interface type
+    >>> class IOtherType(IInterface):
+    ...     pass
+    >>> provideInterface('', I, IOtherType)
+
+    >>> IContentType.providedBy(I)
+    True
+    >>> IOtherType.providedBy(I)
+    True
+    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
+    >>> [name for (name, iface) in interfaces]
+    [u'zope.component.interface.I']
+    >>> interfaces = list(gsm.getUtilitiesFor(IOtherType))
+    >>> [name for (name, iface) in interfaces]
+    [u'zope.component.interface.I']
+
+    >>> class I1(Interface):
+    ...     pass
+    >>> provideInterface('', I1)
+    >>> IInterface.providedBy(I1)
+    True
+    >>> IContentType.providedBy(I1)
+    False
+    >>> interfaces = list(gsm.getUtilitiesFor(IContentType))
+    >>> [name for (name, iface) in interfaces]
+    [u'zope.component.interface.I']
+    >>> [iface.__name__ for (name, iface) in interfaces]
+    ['I']
+    """
+    if not id:
+        id = "%s.%s" % (interface.__module__, interface.__name__)
+
+    if not IInterface.providedBy(interface):
+        if not isinstance(interface, (type, ClassType)):
+            raise TypeError(id, "is not an interface or class")
+        return
+
+    if iface_type is not None:
+        if not iface_type.extends(IInterface):
+            raise TypeError(iface_type, "is not an interface type")
+        directlyProvides(interface, iface_type, directlyProvidedBy(interface))
+    else:
+        iface_type = IInterface
+        
+    gsm = zope.component.getGlobalSiteManager()
+    gsm.registerUtility(interface, iface_type, id, info)
+
+
+def getInterface(context, id):
+    """Return interface or raise ComponentLookupError
+
+    >>> from zope.interface import Interface
+    >>> from zope.app.content.interfaces import IContentType
+
+    >>> class I4(Interface):
+    ...     pass
+    >>> IInterface.providedBy(I4)
+    True
+    >>> IContentType.providedBy(I4)
+    False
+    >>> getInterface(None, 'zope.component.interface.I4')
+    Traceback (most recent call last):
+    ...
+    ComponentLookupError: zope.component.interface.I4
+    >>> provideInterface('', I4, IContentType)
+    >>> IContentType.providedBy(I4)
+    True
+    >>> iface = queryInterface( """\
+                """ 'zope.component.interface.I4')
+    >>> iface.__name__
+    'I4'
+    """
+    iface = queryInterface(id, None)
+    if iface is None:
+        raise ComponentLookupError(id)
+    return iface
+
+
+def queryInterface(id, default=None):
+    """return interface or ``None``
+
+    >>> from zope.interface import Interface
+    >>> from zope.interface.interfaces import IInterface
+    >>> from zope.app.content.interfaces import IContentType
+
+    >>> class I3(Interface):
+    ...     pass
+    >>> IInterface.providedBy(I3)
+    True
+    >>> IContentType.providedBy(I3)
+    False
+    >>> queryInterface('zope.component.interface.I3')
+    
+    >>> provideInterface('', I3, IContentType)
+    >>> IContentType.providedBy(I3)
+    True
+    >>> iface = queryInterface('zope.component.interface.I3')
+    >>> iface.__name__
+    'I3'
+    """
+    return zope.component.queryUtility(IInterface, id, default)
+
+
+def searchInterface(context, search_string=None, base=None):
+    """Interfaces search
+
+    >>> from zope.interface import Interface
+    >>> from zope.interface.interfaces import IInterface
+    >>> from zope.app.content.interfaces import IContentType
+
+    >>> class I5(Interface):
+    ...     pass
+    >>> IInterface.providedBy(I5)
+    True
+    >>> IContentType.providedBy(I5)
+    False
+    >>> searchInterface(None, 'zope.component.interface.I5')
+    []
+    >>> provideInterface('', I5, IContentType)
+    >>> IContentType.providedBy(I5)
+    True
+    >>> iface = searchInterface(None, 'zope.component.interface.I5')
+    >>> iface[0].__name__
+    'I5'
+    """
+    return [iface_util[1]
+            for iface_util in
+            searchInterfaceUtilities(context, search_string, base)]
+
+
+def searchInterfaceIds(context, search_string=None, base=None):
+    """Interfaces search
+
+    >>> from zope.interface import Interface
+    >>> from zope.interface.interfaces import IInterface
+    >>> from zope.app.content.interfaces import IContentType
+
+    >>> class I5(Interface):
+    ...     pass
+    >>> IInterface.providedBy(I5)
+    True
+    >>> IContentType.providedBy(I5)
+    False
+    >>> searchInterface(None, 'zope.component.interface.I5')
+    []
+    >>> provideInterface('', I5, IContentType)
+    >>> IContentType.providedBy(I5)
+    True
+    >>> iface = searchInterfaceIds(None,
+    ...                        'zope.component.interface.I5')
+    >>> iface
+    [u'zope.component.interface.I5']
+    """
+    return [iface_util[0]
+            for iface_util in
+            searchInterfaceUtilities(context, search_string, base)]
+
+
+def searchInterfaceUtilities(context, search_string=None, base=None):
+    gsm = zope.component.getGlobalSiteManager()
+    iface_utilities = gsm.getUtilitiesFor(IInterface)
+
+    if search_string:
+        search_string = search_string.lower()
+        iface_utilities = [iface_util for iface_util in iface_utilities
+                           if (getInterfaceAllDocs(iface_util[1]).\
+                               find(search_string) >= 0)]
+    if base:
+        res = [iface_util for iface_util in iface_utilities
+               if iface_util[1].extends(base)]
+    else:
+        res = [iface_util for iface_util in iface_utilities]
+    return res
+
+
+def getInterfaceAllDocs(interface):
+    iface_id = '%s.%s' %(interface.__module__, interface.__name__)
+    docs = [str(iface_id).lower(),
+            str(interface.__doc__).lower()]
+
+    if IInterface.providedBy(interface):
+        for name in interface:
+            docs.append(
+                str(interface.getDescriptionFor(name).__doc__).lower())
+
+    return '\n'.join(docs)
+
+
+def nameToInterface(context, id):
+    if id == 'None':
+        return None
+    iface = getInterface(context, id)
+    return iface
+
+def interfaceToName(context, interface):
+    if interface is None:
+        return 'None'
+    items = searchInterface(context, base=interface)
+    ids = [('%s.%s' %(iface.__module__, iface.__name__))
+           for iface in items
+           if iface == interface]
+
+    if not ids:
+        # Do not fail badly, instead resort to the standard
+        # way of getting the interface name, cause not all interfaces
+        # may be registered as utilities.
+        return interface.__module__ + '.' + interface.__name__
+
+    assert len(ids) == 1, "Ambiguous interface names: %s" % ids
+    return ids[0]
+

Modified: Zope3/branches/jim-adapter/src/zope/component/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/tests.py	2006-04-11 08:05:21 UTC (rev 66829)
+++ Zope3/branches/jim-adapter/src/zope/component/tests.py	2006-04-11 08:23:15 UTC (rev 66830)
@@ -810,6 +810,8 @@
         doctest.DocFileSuite('registry.txt', checker=checker,
                              tearDown=tearDownRegistryTests),
         doctest.DocFileSuite('event.txt'),
+        doctest.DocTestSuite('zope.component.interface',
+                             setUp=setUp, tearDown=tearDown),
         ))
 
 if __name__ == "__main__":



More information about the Zope3-Checkins mailing list