Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Move IVocabularyFactory to zope.schema.interfaces.
Browse files Browse the repository at this point in the history
Note that this doesn't require BBB. IVocabularyFactory's location at
zope.app.schema.interfaces was introduced only a month back, therefore
never released.
  • Loading branch information
philikon committed Apr 7, 2006
1 parent 8814b9c commit ac7da71
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
$Id$
"""
import zope.component
from zope.interface import implements, classProvides
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from zope.schema.interfaces import ISourceQueriables
from zope.schema.interfaces import ISourceQueriables, IVocabularyFactory
from zope.security.interfaces import IPermission
from zope.security.checker import CheckerPublic

from zope.app import zapi
from zope.app.security.interfaces import IAuthentication
from zope.app.security.interfaces import PrincipalLookupError
from zope.app.security.interfaces import IPrincipalSource
from zope.app.component import queryNextUtility
from zope.app.component.vocabulary import UtilityVocabulary
from zope.app.schema.interfaces import IVocabularyFactory

class PermissionsVocabulary(UtilityVocabulary):
classProvides(IVocabularyFactory)
Expand Down Expand Up @@ -99,7 +98,7 @@ class PermissionIdsVocabulary(SimpleVocabulary):

def __init__(self, context):
terms = []
permissions = zapi.getUtilitiesFor(IPermission, context)
permissions = zope.component.getUtilitiesFor(IPermission, context)
for name, permission in permissions:
if name == 'zope.Public':
terms.append(SimpleTerm(
Expand Down Expand Up @@ -137,8 +136,8 @@ def __contains__(self, id):
simply monkey patch the `getUtility()` method to always return our
dummy authentication utility.
>>> temp = zapi.getUtility
>>> zapi.getUtility = lambda iface: DummyUtility()
>>> temp = zope.component.getUtility
>>> zope.component.getUtility = lambda iface: DummyUtility()
Now initialize the principal source and test the method
Expand All @@ -150,9 +149,9 @@ def __contains__(self, id):
Now revert our patch.
>>> zapi.getUtility = temp
>>> zope.component.getUtility = temp
"""
auth = zapi.getUtility(IAuthentication)
auth = zope.component.getUtility(IAuthentication)
try:
auth.getPrincipal(id)
except PrincipalLookupError:
Expand Down Expand Up @@ -191,17 +190,17 @@ def getQueriables(self):
>>> testingNextUtility(dummy1, dummy2, IAuthentication)
>>> testingNextUtility(dummy2, dummy3, IAuthentication)
>>> temp = zapi.getUtility
>>> zapi.getUtility = lambda iface: dummy1
>>> temp = zope.component.getUtility
>>> zope.component.getUtility = lambda iface: dummy1
>>> source = PrincipalSource()
>>> list(source.getQueriables())
[(u'0', dummy1), (u'1.1', 1), (u'1.2', 2), (u'1.3', 3), (u'2.4', 4)]
>>> zapi.getUtility = temp
>>> zope.component.getUtility = temp
"""
i = 0
auth = zapi.getUtility(IAuthentication)
auth = zope.component.getUtility(IAuthentication)
yielded = []
while True:
queriables = ISourceQueriables(auth, None)
Expand Down

0 comments on commit ac7da71

Please sign in to comment.