[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/app/ get rid of some deprecation warnings by using proper z.c API

Philipp von Weitershausen philikon at philikon.de
Wed Apr 19 12:55:19 EDT 2006


Log message for revision 67148:
  get rid of some deprecation warnings by using proper z.c API
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/app/fssync/tests/test_committer.py
  U   Zope3/branches/jim-adapter/src/zope/app/i18n/translationdomain.py
  U   Zope3/branches/jim-adapter/src/zope/app/module/manager.py
  U   Zope3/branches/jim-adapter/src/zope/app/module/tests.py
  U   Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_zopepublication.py
  U   Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
  U   Zope3/branches/jim-adapter/src/zope/app/testing/ztapi.py
  U   Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/fssync/tests/test_committer.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/fssync/tests/test_committer.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/fssync/tests/test_committer.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -21,7 +21,7 @@
 import unittest
 
 import zope.component
-from zope.interface import implements
+import zope.interface
 from zope.traversing.interfaces import TraversalError, IContainmentRoot
 from zope.traversing.interfaces import ITraversable, ITraverser
 from zope.xmlpickle import loads, dumps
@@ -42,7 +42,6 @@
 from zope.app.fssync import committer, syncer # The module
 from zope.app.fssync.committer import Checker, Committer, SynchronizationError
 from zope.app.fssync.fsregistry import provideSynchronizer, fsRegistry
-from zope.app.fssync.interfaces import IGlobalFSSyncUtility
 
 
 class Sample(object):
@@ -50,9 +49,8 @@
 
 
 class PretendContainer(Location):
+    zope.interface.implements(IContainer, ITraversable, ITraverser)
 
-    implements(IContainer, ITraversable, ITraverser)
-
     def __init__(self):
         self.holding = {}
 
@@ -94,10 +92,9 @@
 PCname = PretendContainer.__module__ + "." + PretendContainer.__name__
 
 class PretendRootContainer(PretendContainer):
+    zope.interface.implements(IContainmentRoot)
 
-    implements(IContainmentRoot)
 
-
 class DictAdapter(DefaultFileAdpater):
 
     def setBody(self, body):
@@ -121,8 +118,7 @@
         super(TestBase, self).setUp()
 
         # Set up FSRegistryUtility
-        gsm = zope.component.getGlobalSiteManager()
-        gsm.provideUtility(IGlobalFSSyncUtility, fsRegistry)
+        zope.component.provideUtility(fsRegistry)
         provideSynchronizer(None, DefaultFileAdpater)
 
         # Set up temporary name administration
@@ -135,11 +131,15 @@
         PlacelessSetup.tearDown(self)
 
 
+ at zope.component.adapter(IContainer)
+ at zope.interface.implementer(IFileFactory)
 def file_factory_maker(container):
     def file_factory(name, content_type, data):
         return loads(data)
     return file_factory
 
+ at zope.component.adapter(IContainer)
+ at zope.interface.implementer(IDirectoryFactory)
 def directory_factory_maker(container):
     def directory_factory(name):
         return PretendContainer()
@@ -212,7 +212,7 @@
                 self.name = name
                 self.value = value
         class TestRoot(object):
-            implements(IContainmentRoot, ITraverser)
+            zope.interface.implements(IContainmentRoot, ITraverser)
             def traverse(self, *args):
                 pass
         fspath = tempfile.mktemp()
@@ -259,7 +259,7 @@
         self.assertEqual(container.items(), [("foo", ["hello", "world"])])
 
     def test_create_object_ifilefactory(self):
-        ztapi.provideAdapter(IContainer, IFileFactory, file_factory_maker)
+        zope.component.provideAdapter(file_factory_maker)
         container = PretendContainer()
         entry = {"flag": "added"}
         data = ["hello", "world"]
@@ -269,8 +269,7 @@
         self.assertEqual(container.holding, {"foo": ["hello", "world"]})
 
     def test_create_object_idirectoryfactory(self):
-        ztapi.provideAdapter(IContainer, IDirectoryFactory,
-                             directory_factory_maker)
+        zope.component.provideAdapter(directory_factory_maker)
         container = PretendContainer()
         entry = {"flag": "added"}
         tfn = os.path.join(self.tempdir(), "foo")
@@ -288,9 +287,8 @@
         # Set up environment
         provideSynchronizer(PretendContainer, DirectoryAdapter)
         provideSynchronizer(dict, DictAdapter)
-        ztapi.provideAdapter(IContainer, IFileFactory, file_factory_maker)
-        ztapi.provideAdapter(IContainer, IDirectoryFactory,
-                             directory_factory_maker)
+        zope.component.provideAdapter(file_factory_maker)
+        zope.component.provideAdapter(directory_factory_maker)
 
         # Set up fixed part of object tree
         self.parent = PretendContainer()

Modified: Zope3/branches/jim-adapter/src/zope/app/i18n/translationdomain.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/i18n/translationdomain.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/i18n/translationdomain.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -19,20 +19,20 @@
 
 import re
 from BTrees.OOBTree import OOBTree
+
+import zope.component
 from zope.interface import implements
-
-from zope.app import zapi
-from zope.app.container.btree import BTreeContainer
-from zope.app.i18n.interfaces import ILocalTranslationDomain
 from zope.i18n import interpolate
 from zope.i18n.negotiator import negotiator
 from zope.i18n.interfaces import INegotiator, ITranslationDomain
 from zope.i18n.simpletranslationdomain import SimpleTranslationDomain
+
+from zope.app.container.btree import BTreeContainer
+from zope.app.i18n.interfaces import ILocalTranslationDomain
 from zope.app.container.contained import Contained
 from zope.app.component import queryNextUtility
 
 class TranslationDomain(BTreeContainer, SimpleTranslationDomain, Contained):
-
     implements(ILocalTranslationDomain)
 
     def __init__(self):
@@ -67,7 +67,7 @@
         if target_language is None and context is not None:
             avail_langs = self.getAvailableLanguages()
             # Let's negotiate the language to translate to. :)
-            negotiator = zapi.getUtility(INegotiator, context=self)
+            negotiator = zope.component.getUtility(INegotiator, context=self)
             target_language = negotiator.getLanguage(avail_langs, context)
 
         # Get the translation. Default is the source text itself.
@@ -165,8 +165,8 @@
 
     def addLanguage(self, language):
         'See `IWriteTranslationDomain`'
-        catalog = zapi.createObject(u'zope.app.MessageCatalog',
-                                    language)
+        catalog = zope.component.createObject(u'zope.app.MessageCatalog',
+                                              language)
         self[language] = catalog
 
 
@@ -235,8 +235,8 @@
     >>> domain1.domain
     '<domain not activated>'
 
-    >>> from zope.app.component import registration 
-    >>> event = registration.RegistrationActivatedEvent(
+    >>> import zope.component.interfaces
+    >>> event = zope.component.interfaces.Registered(
     ...     Registration(domain1, 'domain1'))
 
     Now we pass the event into this function, and the id of the domain should
@@ -263,8 +263,8 @@
     >>> domain1 = TranslationDomain()
     >>> domain1.domain = 'domain1'
 
-    >>> from zope.app.component import registration
-    >>> event = registration.RegistrationDeactivatedEvent(
+    >>> import zope.component.interfaces
+    >>> event = zope.component.interfaces.Unregistered(
     ...     Registration(domain1, 'domain1'))
 
     Now we pass the event into this function, and the id of the role should be

Modified: Zope3/branches/jim-adapter/src/zope/app/module/manager.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/module/manager.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/module/manager.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -19,6 +19,7 @@
 import persistent
 import zodbcode.module
 import zope.interface
+import zope.component
 
 from zope.filerepresentation.interfaces import IFileFactory
 from zope.app.container.contained import Contained
@@ -81,7 +82,7 @@
         m.execute()
         return m
 
-
+ at zope.component.adapter(zope.component.interfaces.IRegistered)
 def setNameOnActivation(event):
     """Set the module name upon registration activation."""
     module = event.object.component
@@ -89,6 +90,7 @@
         module.name = event.object.name
         module._recompile = True
 
+ at zope.component.adapter(zope.component.interfaces.IUnregistered)
 def unsetNameOnDeactivation(event):
     """Unset the permission id up registration deactivation."""
     module = event.object.component

Modified: Zope3/branches/jim-adapter/src/zope/app/module/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/module/tests.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/module/tests.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -18,19 +18,15 @@
 __docformat__ = "reStructuredText"
 import unittest
 
+import zope.component
 from zope.testing import doctest
-from zope.app.component import interfaces
 from zope.app.module import manager
-from zope.app.testing import setup, ztapi
+from zope.app.testing import setup
 
 def setUp(test):
     setup.placefulSetUp()
-    ztapi.subscribe(
-        (interfaces.registration.IRegistrationActivatedEvent,), None,
-        manager.setNameOnActivation)
-    ztapi.subscribe(
-        (interfaces.registration.IRegistrationDeactivatedEvent,), None,
-        manager.unsetNameOnDeactivation)
+    zope.component.provideHandler(manager.setNameOnActivation)
+    zope.component.provideHandler(manager.unsetNameOnDeactivation)
 
 def tearDown(test):
     setup.placefulTearDown()

Modified: Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_zopepublication.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/publication/tests/test_zopepublication.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -378,8 +378,7 @@
 
     def testAbortTransactionWithErrorReportingUtility(self):
         # provide our fake error reporting utility
-        sm = zope.component.getGlobalSiteManager()
-        sm.provideUtility(IErrorReportingUtility, ErrorReportingUtility())
+        zope.component.provideUtility(ErrorReportingUtility())
 
         class FooError(Exception):
             pass

Modified: Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/schema/tests/test_interfaceutility.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -178,10 +178,11 @@
                          [foo])
 
     def test_query_get_Utility_delegates_to_global(self):
+        zope.component.provideUtility(Foo("global"), IInterface)
+        zope.component.provideUtility(Foo("global bob"), IInterface,
+                                      name="bob")
+
         gsm = zope.component.getGlobalSiteManager()
-        gsm.provideUtility(IInterface, Foo("global"))
-        gsm.provideUtility(IInterface, Foo("global bob"), name="bob")
-
         sm = zope.component.getSiteManager(self.rootFolder)
         self.assert_(gsm != sm)
 

Modified: Zope3/branches/jim-adapter/src/zope/app/testing/ztapi.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/testing/ztapi.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/testing/ztapi.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -59,7 +59,7 @@
     if layer is None:
         layer = type
     gsm = zope.component.getGlobalSiteManager()
-    gsm.provideAdapter((for_, layer), IDefaultViewName, '', name)
+    gsm.registerAdapter(name, (for_, layer), IDefaultViewName, '')
 
 stypes = list, tuple
 def provideAdapter(required, provided, factory, name='', with=()):

Modified: Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py	2006-04-19 16:54:31 UTC (rev 67147)
+++ Zope3/branches/jim-adapter/src/zope/app/workflow/stateful/tests/test_instance.py	2006-04-19 16:55:18 UTC (rev 67148)
@@ -43,7 +43,7 @@
 from zope.app.workflow.stateful.instance import StateChangeInfo
 
 from zope.app.container.contained import contained
-from zope.app.utility import UtilityRegistration
+from zope.app.component.site import UtilityRegistration
 from zope.app.testing import setup
 
 



More information about the Zope3-Checkins mailing list