[Checkins] SVN: zope.app.principalannotation/trunk/ Use zope.principalannotation.
Dan Korostelev
nadako at gmail.com
Mon Mar 9 10:50:04 EDT 2009
Log message for revision 97695:
Use zope.principalannotation.
Changed:
U zope.app.principalannotation/trunk/CHANGES.txt
U zope.app.principalannotation/trunk/README.txt
U zope.app.principalannotation/trunk/buildout.cfg
U zope.app.principalannotation/trunk/setup.py
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/__init__.py
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.py
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.zcml
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/configure.zcml
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/interfaces.py
U zope.app.principalannotation/trunk/src/zope/app/principalannotation/tests.py
-=-
Modified: zope.app.principalannotation/trunk/CHANGES.txt
===================================================================
--- zope.app.principalannotation/trunk/CHANGES.txt 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/CHANGES.txt 2009-03-09 14:50:04 UTC (rev 97695)
@@ -2,7 +2,7 @@
CHANGES
=======
-3.5.2 (unreleased)
+3.6.0 (unreleased)
------------------
- ...
Modified: zope.app.principalannotation/trunk/README.txt
===================================================================
--- zope.app.principalannotation/trunk/README.txt 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/README.txt 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,3 +1,5 @@
-This package implements annotations for Zope security principals. Common
-annotation techniques, like AttributeAnnotations cannot be applied to
-principals, since they are created on the fly for every request.
+This package used to provide implementation of IAnnotations for zope.security
+principal objects, but it's now moved to the ``zope.principalannotation``
+package. This package only contains a bootstrap subscriber that sets up
+the principal annotation utility for the root site and the browser add
+menu item for adding the annotation utility through ZMI.
Modified: zope.app.principalannotation/trunk/buildout.cfg
===================================================================
--- zope.app.principalannotation/trunk/buildout.cfg 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/buildout.cfg 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,5 +1,5 @@
[buildout]
-develop = .
+develop = . ../zope.principalannotation
parts = test
[test]
Modified: zope.app.principalannotation/trunk/setup.py
===================================================================
--- zope.app.principalannotation/trunk/setup.py 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/setup.py 2009-03-09 14:50:04 UTC (rev 97695)
@@ -22,16 +22,16 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name='zope.app.principalannotation',
- version = '3.5.2dev',
+ version = '3.6.0dev',
author='Zope Corporation and Contributors',
author_email='zope-dev at zope.org',
- description='Annotations for Zope Principals',
+ description='Bootstrap subscriber and browser menu item for zope.principalannotation',
long_description=(
read('README.txt')
+ '\n\n' +
read('CHANGES.txt')
),
- keywords = "zope3 annotation principal publisher",
+ keywords = "zope security principal annotation",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
@@ -47,17 +47,11 @@
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope', 'zope.app'],
- extras_require = dict(test=['zope.app.testing']),
+ extras_require = dict(test=['zope.testing']),
install_requires=['setuptools',
- 'zope.annotation',
'zope.app.appsetup',
- 'zope.component',
- 'zope.container',
- 'zope.interface',
- 'zope.location',
- 'zope.security',
- 'zope.site',
- 'ZODB3',
+ 'zope.app.publisher',
+ 'zope.principalannotation',
],
include_package_data = True,
zip_safe = False,
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/__init__.py
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/__init__.py 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/__init__.py 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -15,128 +15,9 @@
$Id$
"""
-__docformat__ = 'restructuredtext'
-# TODO: register utility as adapter for IAnnotations on utility activation.
-
-from persistent import Persistent
-from persistent.dict import PersistentDict
-from BTrees.OOBTree import OOBTree
-import zope.security.interfaces
-from zope import interface, component
-from zope.annotation.interfaces import IAnnotations
-from zope.container.contained import Contained
-from zope.location import Location
-from zope.site.next import queryNextUtility
-
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
-
-class PrincipalAnnotationUtility(Persistent, Contained):
- """Stores `IAnnotations` for `IPrinicipals`.
-
- The utility ID is 'PrincipalAnnotation'.
- """
-
- interface.implements(IPrincipalAnnotationUtility)
-
- def __init__(self):
- self.annotations = OOBTree()
-
- def getAnnotations(self, principal):
- """Return object implementing IAnnotations for the given principal.
-
- If there is no `IAnnotations` it will be created and then returned.
- """
- return self.getAnnotationsById(principal.id)
-
- def getAnnotationsById(self, principalId):
- """Return object implementing `IAnnotations` for the given principal.
-
- If there is no `IAnnotations` it will be created and then returned.
- """
-
- annotations = self.annotations.get(principalId)
- if annotations is None:
- annotations = Annotations(principalId, store=self.annotations)
- annotations.__parent__ = self
- annotations.__name__ = principalId
-
- return annotations
-
- def hasAnnotations(self, principal):
- """Return boolean indicating if given principal has `IAnnotations`."""
- return principal.id in self.annotations
-
-
-class Annotations(Persistent, Location):
- """Stores annotations."""
-
- interface.implements(IAnnotations)
-
- def __init__(self, principalId, store=None):
- self.principalId = principalId
- self.data = PersistentDict() # We don't really expect that many
-
- # _v_store is used to remember a mapping object that we should
- # be saved in if we ever change
- self._v_store = store
-
- def __getitem__(self, key):
- try:
- return self.data[key]
- except KeyError:
- # We failed locally: delegate to a higher-level utility.
- utility = queryNextUtility(self, IPrincipalAnnotationUtility)
- if utility is not None:
- annotations = utility.getAnnotationsById(self.principalId)
- return annotations[key]
- raise
-
- def __setitem__(self, key, value):
- if getattr(self, '_v_store', None) is not None:
- # _v_store is used to remember a mapping object that we should
- # be saved in if we ever change
- self._v_store[self.principalId] = self
- del self._v_store
-
- self.data[key] = value
-
- def __delitem__(self, key):
- del self.data[key]
-
- def get(self, key, default=None):
- return self.data.get(key, default)
-
-def annotations(principal, context=None):
- """adapt principal to annotations via principal annotation utility.
-
- To illustrate, we'll register the adapter and a dummy
- principal annotation utility.
-
- >>> component.provideAdapter(annotations)
- >>> class DummyPrincipal(object):
- ... interface.implements(zope.security.interfaces.IPrincipal)
- ... def __init__(self, id, title=None, description=None):
- ... self.id = id
- ... self.title = title
- ... self.description = description
- ...
- >>> dummy_annotation = {}
- >>> class DummyPAU(object):
- ... interface.implements(interfaces.IPrincipalAnnotationUtility)
- ... def getAnnotations(self, principal):
- ... if principal.id == 'sue':
- ... return dummy_annotation
- ... raise NotImplementedError
- ...
- >>> pau = DummyPAU()
- >>> component.provideUtility(pau)
- >>> sue = DummyPrincipal('sue')
- >>> annotation = IAnnotations(sue)
- >>> annotation is dummy_annotation
- True
- """ # TODO move this out to a doctest file when we have one...
- utility = component.getUtility(IPrincipalAnnotationUtility, context=context)
- return utility.getAnnotations(principal)
-component.adapter(zope.security.interfaces.IPrincipal)(annotations)
-interface.implementer(IAnnotations)(annotations)
+# BBB: the functionality was moved to zope.principalannotation
+from zope.principalannotation.utility import (
+ PrincipalAnnotationUtility,
+ Annotations,
+ annotations)
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.py
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.py 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.py 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2002, 2004 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -20,8 +20,8 @@
from zope.app.appsetup.bootstrap import ensureUtility, getInformationFromEvent
-from zope.app.principalannotation import PrincipalAnnotationUtility
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
+from zope.principalannotation.utility import PrincipalAnnotationUtility
+from zope.principalannotation.interfaces import IPrincipalAnnotationUtility
def bootStrapSubscriber(event):
"""Subscriber to the IDatabaseOpenedWithRootEvent
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.zcml
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.zcml 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/bootstrap.zcml 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,7 +1,4 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:browser="http://namespaces.zope.org/browser"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
<subscriber
for="zope.app.appsetup.interfaces.IDatabaseOpenedWithRootEvent"
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/configure.zcml
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/configure.zcml 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/configure.zcml 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,28 +1,6 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:browser="http://namespaces.zope.org/browser"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
- <class class=".PrincipalAnnotationUtility">
- <factory
- id="zope.app.PrincipalAnnotationUtility"
- />
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
- <require
- permission="zope.View"
- interface=".interfaces.IPrincipalAnnotationUtility"
- />
- </class>
-
- <adapter factory=".annotations" />
-
- <adapter
- for="zope.security.interfaces.IPrincipal *"
- factory=".annotations"
- />
-
+ <include package="zope.principalannotation" />
<include file="bootstrap.zcml" />
<include file="browser.zcml" />
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/interfaces.py
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/interfaces.py 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/interfaces.py 2009-03-09 14:50:04 UTC (rev 97695)
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
@@ -15,28 +15,4 @@
$Id$
"""
-__docformat__ = 'restructuredtext'
-
-from zope.interface import Interface
-
-
-class IPrincipalAnnotationUtility(Interface):
- """Stores `IAnnotations` for `IPrinicipals`."""
-
- def getAnnotations(principal):
- """Return object implementing `IAnnotations` for the given
- `IPrinicipal`.
-
- If there is no `IAnnotations` it will be created and then returned.
- """
-
- def getAnnotationsById(principalId):
- """Return object implementing `IAnnotations` for the given
- `prinicipalId`.
-
- If there is no `IAnnotations` it will be created and then returned.
- """
-
- def hasAnnotations(principal):
- """Return boolean indicating if given `IPrincipal` has
- `IAnnotations`."""
+from zope.principalannotation.interfaces import IPrincipalAnnotationUtility # BBB
Modified: zope.app.principalannotation/trunk/src/zope/app/principalannotation/tests.py
===================================================================
--- zope.app.principalannotation/trunk/src/zope/app/principalannotation/tests.py 2009-03-09 14:33:38 UTC (rev 97694)
+++ zope.app.principalannotation/trunk/src/zope/app/principalannotation/tests.py 2009-03-09 14:50:04 UTC (rev 97695)
@@ -15,79 +15,34 @@
$Id$
"""
+import unittest
from zope.testing import doctest
-from unittest import TestCase, TestLoader, TextTestRunner
-import zope.component
-from zope.interface import implements
-from zope.security.interfaces import IPrincipal
+def test_bbb_imports():
+ """
+ The most of functionality was moved to zope.principalannotation.
+ Let's test if old imports still work::
+
+ >>> from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
+ >>> IPrincipalAnnotationUtility
+ <InterfaceClass zope.principalannotation.interfaces.IPrincipalAnnotationUtility>
+
+ >>> from zope.app.principalannotation import PrincipalAnnotationUtility
+ >>> from zope.app.principalannotation import Annotations
+ >>> from zope.app.principalannotation import annotations
+
+ >>> PrincipalAnnotationUtility
+ <class 'zope.principalannotation.utility.PrincipalAnnotationUtility'>
-from zope.app.principalannotation import PrincipalAnnotationUtility
-from zope.app.component.testing import PlacefulSetup
-from zope.app.testing import setup
-from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
+ >>> Annotations
+ <class 'zope.principalannotation.utility.Annotations'>
-class Principal(object):
- implements(IPrincipal)
+ >>> print annotations.__module__ + '.' + annotations.__name__
+ zope.principalannotation.utility.annotations
+
+ """
- def __init__(self, id):
- self.id = id
-
-
-class PrincipalAnnotationTests(PlacefulSetup, TestCase):
-
- def setUp(self):
- PlacefulSetup.setUp(self)
- sm = self.buildFolders(site='/')
- self.util = PrincipalAnnotationUtility()
- zope.component.provideUtility(self.util, IPrincipalAnnotationUtility)
-
- def testGetSimple(self):
- prince = Principal('somebody')
- self.assert_(not self.util.hasAnnotations(prince))
-
- princeAnnotation = self.util.getAnnotations(prince)
- # Just getting doesn't actualy store. We don't want to store unless
- # we make a change.
- self.assert_(not self.util.hasAnnotations(prince))
-
- princeAnnotation['something'] = 'whatever'
-
- # But now we should have the annotation:
- self.assert_(self.util.hasAnnotations(prince))
-
- def testGetFromLayered(self):
- princeSomebody = Principal('somebody')
- sm1 = self.makeSite('folder1')
- subUtil = setup.addUtility(sm1, '', IPrincipalAnnotationUtility,
- PrincipalAnnotationUtility())
-
- parentAnnotation = self.util.getAnnotations(princeSomebody)
-
- # Just getting doesn't actualy store. We don't want to store unless
- # we make a change.
- self.assert_(not subUtil.hasAnnotations(princeSomebody))
-
- parentAnnotation['hair_color'] = 'blue'
-
- # But now we should have the annotation:
- self.assert_(self.util.hasAnnotations(princeSomebody))
-
- subAnnotation = subUtil.getAnnotations(princeSomebody)
- self.assertEquals(subAnnotation['hair_color'], 'blue')
-
- subAnnotation['foo'] = 'bar'
-
- self.assertEquals(parentAnnotation.get("foo"), None)
-
def test_suite():
- loader=TestLoader()
- tests = loader.loadTestsFromTestCase(PrincipalAnnotationTests)
- import zope.app.principalannotation
- tests.addTest(doctest.DocTestSuite(zope.app.principalannotation,
- setUp=setup.placelessSetUp,
- tearDown=setup.placelessTearDown))
- return tests
-
-if __name__=='__main__':
- TextTestRunner().run(test_suite())
+ return unittest.TestSuite((
+ doctest.DocTestSuite()
+ ))
More information about the Checkins
mailing list