[Checkins] SVN: zope.app.content/trunk/ merged branch icemac-queryType to trunk, to make zope.app.content independent of zope.app.interface
Michael Howitz
mh at gocept.com
Mon Sep 20 03:20:26 EDT 2010
Log message for revision 116645:
merged branch icemac-queryType to trunk, to make zope.app.content independent of zope.app.interface
Changed:
U zope.app.content/trunk/CHANGES.txt
U zope.app.content/trunk/buildout.cfg
U zope.app.content/trunk/setup.py
U zope.app.content/trunk/src/zope/app/content/__init__.py
A zope.app.content/trunk/src/zope/app/content/tests.py
-=-
Modified: zope.app.content/trunk/CHANGES.txt
===================================================================
--- zope.app.content/trunk/CHANGES.txt 2010-09-20 06:57:23 UTC (rev 116644)
+++ zope.app.content/trunk/CHANGES.txt 2010-09-20 07:20:25 UTC (rev 116645)
@@ -2,6 +2,13 @@
CHANGES
=======
+3.5.0 (unreleased)
+------------------
+
+- Moved ``zope.app.interface.queryType`` to ``zope.app.content.queryType``
+ to inverse dependency.
+
+
3.4.0 (2007-10-11)
------------------
Modified: zope.app.content/trunk/buildout.cfg
===================================================================
--- zope.app.content/trunk/buildout.cfg 2010-09-20 06:57:23 UTC (rev 116644)
+++ zope.app.content/trunk/buildout.cfg 2010-09-20 07:20:25 UTC (rev 116645)
@@ -4,5 +4,5 @@
[test]
recipe = zc.recipe.testrunner
-eggs = zope.app.content
+eggs = zope.app.content [test]
Modified: zope.app.content/trunk/setup.py
===================================================================
--- zope.app.content/trunk/setup.py 2010-09-20 06:57:23 UTC (rev 116644)
+++ zope.app.content/trunk/setup.py 2010-09-20 07:20:25 UTC (rev 116645)
@@ -27,7 +27,7 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='zope.app.content',
- version = '3.4.0',
+ version = '3.5.0dev',
author='Zope Corporation and Contributors',
author_email='zope-dev at zope.org',
description='Zope Content Type',
@@ -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/trunk/src/zope/app/content/__init__.py
===================================================================
--- zope.app.content/trunk/src/zope/app/content/__init__.py 2010-09-20 06:57:23 UTC (rev 116644)
+++ zope.app.content/trunk/src/zope/app/content/__init__.py 2010-09-20 07:20:25 UTC (rev 116645)
@@ -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/trunk/src/zope/app/content/tests.py (from rev 116644, zope.app.content/branches/icemac-queryType/src/zope/app/content/tests.py)
===================================================================
--- zope.app.content/trunk/src/zope/app/content/tests.py (rev 0)
+++ zope.app.content/trunk/src/zope/app/content/tests.py 2010-09-20 07:20:25 UTC (rev 116645)
@@ -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