[Checkins] SVN: zope.app.content/branches/icemac-queryType/ - Moved ``zope.app.interface.queryType`` here to inverse depenency.

Michael Howitz mh at gocept.com
Sat Sep 18 14:50:13 EDT 2010


Log message for revision 116602:
  - Moved ``zope.app.interface.queryType`` here to inverse depenency.
  
  

Changed:
  U   zope.app.content/branches/icemac-queryType/CHANGES.txt
  U   zope.app.content/branches/icemac-queryType/buildout.cfg
  U   zope.app.content/branches/icemac-queryType/setup.py
  U   zope.app.content/branches/icemac-queryType/src/zope/app/content/__init__.py
  A   zope.app.content/branches/icemac-queryType/src/zope/app/content/tests.py

-=-
Modified: zope.app.content/branches/icemac-queryType/CHANGES.txt
===================================================================
--- zope.app.content/branches/icemac-queryType/CHANGES.txt	2010-09-18 18:39:22 UTC (rev 116601)
+++ zope.app.content/branches/icemac-queryType/CHANGES.txt	2010-09-18 18:50:13 UTC (rev 116602)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+3.5.0 (unreleased)
+------------------
+
+- Moved ``zope.app.interface.queryType`` here to inverse depenency.
+
+
 3.4.0 (2007-10-11)
 ------------------
 

Modified: zope.app.content/branches/icemac-queryType/buildout.cfg
===================================================================
--- zope.app.content/branches/icemac-queryType/buildout.cfg	2010-09-18 18:39:22 UTC (rev 116601)
+++ zope.app.content/branches/icemac-queryType/buildout.cfg	2010-09-18 18:50:13 UTC (rev 116602)
@@ -4,5 +4,5 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = zope.app.content
+eggs = zope.app.content [test]
 

Modified: zope.app.content/branches/icemac-queryType/setup.py
===================================================================
--- zope.app.content/branches/icemac-queryType/setup.py	2010-09-18 18:39:22 UTC (rev 116601)
+++ zope.app.content/branches/icemac-queryType/setup.py	2010-09-18 18:50:13 UTC (rev 116602)
@@ -54,10 +54,12 @@
       namespace_packages=['zope', 'zope.app'],
       install_requires=['setuptools',
                         'zope.app.component',
-                        'zope.app.interface',
                         'zope.interface',
                         'zope.schema',
                         ],
+      extras_require=dict(test=[
+          'zope.testing',
+          ]),
       include_package_data = True,
       zip_safe = False,
       )

Modified: zope.app.content/branches/icemac-queryType/src/zope/app/content/__init__.py
===================================================================
--- zope.app.content/branches/icemac-queryType/src/zope/app/content/__init__.py	2010-09-18 18:39:22 UTC (rev 116601)
+++ zope.app.content/branches/icemac-queryType/src/zope/app/content/__init__.py	2010-09-18 18:50:13 UTC (rev 116602)
@@ -11,22 +11,92 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Content Type convenience lookup functions 
+"""Content Type convenience lookup functions."""
 
-$Id$
-"""
-__docformat__ = 'restructuredtext'
 from zope.interface import classProvides
 from zope.schema.interfaces import IVocabularyFactory
-from zope.app.interface import queryType
 from zope.app.content.interfaces import IContentType
 from zope.app.component.vocabulary import UtilityVocabulary
+from zope.security.proxy import removeSecurityProxy
+from zope.interface.declarations import providedBy
 
+
+def queryType(object, interface):
+    """Returns the object's interface which implements interface.
+
+    >>> from zope.interface import Interface
+    >>> class IContentType(Interface):
+    ...    pass
+    >>> from zope.interface import Interface, implements, directlyProvides
+    >>> class I(Interface):
+    ...     pass
+    >>> class J(Interface):
+    ...     pass
+    >>> directlyProvides(I, IContentType)
+    >>> class C(object):
+    ...     implements(I)
+    >>> class D(object):
+    ...     implements(J,I)
+    >>> obj = C()
+    >>> c1_ctype = queryType(obj, IContentType)
+    >>> c1_ctype.__name__
+    'I'
+    >>> class I1(I):
+    ...     pass
+    >>> class I2(I1):
+    ...     pass
+    >>> class I3(Interface):
+    ...     pass
+    >>> class C1(object):
+    ...     implements(I1)
+    >>> obj1 = C1()
+    >>> c1_ctype = queryType(obj1, IContentType)
+    >>> c1_ctype.__name__
+    'I'
+    >>> class C2(object):
+    ...     implements(I2)
+    >>> obj2 = C2()
+    >>> c2_ctype = queryType(obj2, IContentType)
+    >>> c2_ctype.__name__
+    'I'
+
+    >>> class C3(object):
+    ...     implements(I3)
+    >>> obj3 = C3()
+
+    If Interface doesn't provide `IContentType`, `queryType` returns ``None``.
+
+    >>> c3_ctype = queryType(obj3, IContentType)
+    >>> c3_ctype
+    >>> c3_ctype is None
+    True
+    >>> class I4(I):
+    ...     pass
+    >>> directlyProvides(I4, IContentType)
+    >>> class C4(object):
+    ...     implements(I4)
+    >>> obj4 = C4()
+    >>> c4_ctype = queryType(obj4, IContentType)
+    >>> c4_ctype.__name__
+    'I4'
+
+    """
+    # Remove the security proxy, so that we can introspect the type of the
+    # object's interfaces.
+    naked = removeSecurityProxy(object)
+    object_iro = providedBy(naked).__iro__
+    for iface in object_iro:
+        if interface.providedBy(iface):
+            return iface
+    return None
+
+
 def queryContentType(object):
     """Returns the interface implemented by object which implements
     `IContentType`."""
     return queryType(object, IContentType)
 
+
 class ContentTypesVocabulary(UtilityVocabulary):
     classProvides(IVocabularyFactory)
     interface = IContentType

Copied: zope.app.content/branches/icemac-queryType/src/zope/app/content/tests.py (from rev 116458, zope.app.interface/trunk/src/zope/app/interface/tests/test_queryinterface.py)
===================================================================
--- zope.app.content/branches/icemac-queryType/src/zope/app/content/tests.py	                        (rev 0)
+++ zope.app.content/branches/icemac-queryType/src/zope/app/content/tests.py	2010-09-18 18:50:13 UTC (rev 116602)
@@ -0,0 +1,20 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Doc test harness for queryType function."""
+
+import doctest
+import unittest
+
+def test_suite():
+    return doctest.DocTestSuite("zope.app.content")



More information about the checkins mailing list