Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
merged branch icemac-queryType to inverse dependency on queryType to …
Browse files Browse the repository at this point in the history
…zope.app.content
  • Loading branch information
Michael Howitz committed Sep 20, 2010
1 parent 9d9d1ec commit 7b1747f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 112 deletions.
6 changes: 5 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
CHANGES
=======

3.5.3 (unreleased)

3.6.0 (unreleased)
------------------

- Added test extra to declare test dependency on `zope.testing`.

- Moved ``zope.app.interfaces.queryType`` to `zope.app.content` to inverse
dependency, leaving BBB import here.


3.5.2 (2010-07-08)
------------------
Expand Down
14 changes: 8 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ def read(*rnames):
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope', 'zope.app'],
install_requires=['setuptools',
'ZODB3',
'zodbcode',
'zope.componentvocabulary',
'zope.security',
],
install_requires=[
'ZODB3',
'setuptools',
'zodbcode',
'zope.app.content >= 3.5',
'zope.componentvocabulary',
'zope.security',
],
extras_require=dict(test=[
'zope.testing',
]),
Expand Down
81 changes: 6 additions & 75 deletions src/zope/app/interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@

from persistent import Persistent
from zodbcode.patch import registerWrapper, Wrapper, NameFinder

from zope.interface.interface import InterfaceClass
from zope.interface import Interface
from zope.security.proxy import removeSecurityProxy

from wref import FlexibleWeakKeyDictionary

# BBB import
from zope.app.content import queryType


class PersistentInterfaceClass(Persistent, InterfaceClass):

def __init__(self, *args, **kw):
Persistent.__init__(self)
InterfaceClass.__init__(self, *args, **kw)

self.dependents = FlexibleWeakKeyDictionary()

# PersistentInterface is equivalent to the zope.interface.Interface object
Expand Down Expand Up @@ -69,74 +70,4 @@ def getInterfaceStateForPersistentInterfaceCreation(iface):
NameFinder.classTypes[PersistentInterfaceClass] = True
NameFinder.types[PersistentInterfaceClass] = True

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

30 changes: 0 additions & 30 deletions src/zope/app/interface/tests/test_queryinterface.py

This file was deleted.

0 comments on commit 7b1747f

Please sign in to comment.