[Checkins] SVN: Zope3/trunk/src/zope/app/intid/ Added a level of indirection as to what BTree flavour the IntIds utility uses.

Bernd Dorn zope-mailinglist at mopa.at
Thu Feb 1 12:52:53 EST 2007


On 01.02.2007, at 18:06, Albertas Agejevas wrote:

> Log message for revision 72302:
>   Added a level of indirection as to what BTree flavour the IntIds  
> utility uses.
>
>
> Changed:
>   U   Zope3/trunk/src/zope/app/intid/__init__.py
>   U   Zope3/trunk/src/zope/app/intid/configure.zcml
>   U   Zope3/trunk/src/zope/app/intid/interfaces.py
>   U   Zope3/trunk/src/zope/app/intid/tests.py
>
> -=-
> Modified: Zope3/trunk/src/zope/app/intid/__init__.py
> ===================================================================
> --- Zope3/trunk/src/zope/app/intid/__init__.py	2007-02-01 17:03:58  
> UTC (rev 72301)
> +++ Zope3/trunk/src/zope/app/intid/__init__.py	2007-02-01 17:06:08  
> UTC (rev 72302)
> @@ -29,8 +29,10 @@
>  from zope.interface import implements
>  from zope.security.proxy import removeSecurityProxy
>  from zope.location.interfaces import ILocation
> -from zope.component import adapter, getAllUtilitiesRegisteredFor
> +from zope.component import adapter, getAllUtilitiesRegisteredFor,  
> getUtility
> +from zope.component.interfaces import IFactory
>
> +from zope.component.factory import Factory
>  from zope.app.container.interfaces import IObjectRemovedEvent
>  from zope.app.container.interfaces import IObjectAddedEvent
>  from zope.app.container.contained import Contained
> @@ -40,6 +42,7 @@
>  from zope.app.intid.interfaces import IntIdRemovedEvent
>  from zope.app.intid.interfaces import IntIdAddedEvent
>
> +
>  class IntIds(Persistent, Contained):
>      """This utility provides a two way mapping between objects and
>      integer ids.
> @@ -48,13 +51,13 @@
>      """
>      implements(IIntIds)
>
> -    _v_nextid = None
> +    _v_nextid = None
>
>      _randrange = random.randrange
>
>      def __init__(self):
> -        self.ids = OIBTree.OIBTree()
> -        self.refs = IOBTree.IOBTree()
> +        self.ids = getUtility(IFactory, 'OIBTree')()
> +        self.refs = getUtility(IFactory, 'IOBTree')()
>

you should use query utility and return the default if no util is  
foud, because i think lots of unit tests will fail because  the setup  
is not correct

>      def __len__(self):
>          return len(self.ids)
> @@ -167,3 +170,10 @@
>                  utility.register(key)
>              # Notify the catalogs that this object was added.
>              notify(IntIdAddedEvent(ob, event))
> +
> +
> +#
> +# Hooks for changing the flavour of BTrees IntIds utility uses
> +#
> +IOBTreeFactory = Factory(IOBTree.IOBTree)
> +OIBTreeFactory = Factory(OIBTree.OIBTree)
>
> Modified: Zope3/trunk/src/zope/app/intid/configure.zcml
> ===================================================================
> --- Zope3/trunk/src/zope/app/intid/configure.zcml	2007-02-01  
> 17:03:58 UTC (rev 72301)
> +++ Zope3/trunk/src/zope/app/intid/configure.zcml	2007-02-01  
> 17:06:08 UTC (rev 72302)
> @@ -32,6 +32,9 @@
>    <subscriber handler=".removeIntIdSubscriber" />
>    <subscriber handler=".addIntIdSubscriber" />
>
> +  <utility component=".IOBTreeFactory" name="IOBTree" />
> +  <utility component=".OIBTreeFactory" name="OIBTree" />
> +
>    <!-- Views -->
>    <include package=".browser" />
>
>
> Modified: Zope3/trunk/src/zope/app/intid/interfaces.py
> ===================================================================
> --- Zope3/trunk/src/zope/app/intid/interfaces.py	2007-02-01  
> 17:03:58 UTC (rev 72301)
> +++ Zope3/trunk/src/zope/app/intid/interfaces.py	2007-02-01  
> 17:06:08 UTC (rev 72302)
> @@ -29,8 +29,8 @@
>
>      def __iter__():
>          """Return an iteration on the ids"""
> -
>
> +
>  class IIntIdsSet(Interface):
>
>      def register(ob):
>
> Modified: Zope3/trunk/src/zope/app/intid/tests.py
> ===================================================================
> --- Zope3/trunk/src/zope/app/intid/tests.py	2007-02-01 17:03:58 UTC  
> (rev 72301)
> +++ Zope3/trunk/src/zope/app/intid/tests.py	2007-02-01 17:06:08 UTC  
> (rev 72302)
> @@ -25,12 +25,14 @@
>  from zope.interface.verify import verifyObject
>  from zope.location.interfaces import ILocation
>
> +from zope.component.interfaces import IFactory
> +
>  from zope.app.testing import setup, ztapi
>  from zope.app import zapi
>  from zope.app.component.hooks import setSite
>
>  from zope.app.intid.interfaces import IIntIds
> -from zope.app.intid import IntIds
> +from zope.app.intid import IntIds, IOBTreeFactory, OIBTreeFactory
>  from zope.app.keyreference.persistent import KeyReferenceToPersistent
>  from zope.app.keyreference.persistent import connectionOfPersistent
>  from zope.app.keyreference.interfaces import IKeyReference
> @@ -61,6 +63,8 @@
>          ztapi.provideAdapter(IPersistent, IConnection,  
> connectionOfPersistent)
>          ztapi.provideAdapter(IPersistent, IKeyReference,
>                               KeyReferenceToPersistent)
> +        ztapi.provideUtility(IFactory, IOBTreeFactory, 'IOBTree')
> +        ztapi.provideUtility(IFactory, OIBTreeFactory, 'OIBTree')
>
>      def tearDown(self):
>          setup.placefulTearDown()
>
> _______________________________________________
> Checkins mailing list
> Checkins at zope.org
> http://mail.zope.org/mailman/listinfo/checkins



More information about the Checkins mailing list