[Zope3-checkins] SVN: Zope3/trunk/ Removed special DomainRegistration and implemented the functionality

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Dec 9 13:43:21 EST 2004


Log message for revision 28599:
  Removed special DomainRegistration and implemented the functionality 
  using subscribers.
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/i18n/configure.zcml
  U   Zope3/trunk/src/zope/app/i18n/tests/test_translationdomain.py
  U   Zope3/trunk/src/zope/app/i18n/translationdomain.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-12-09 18:06:13 UTC (rev 28598)
+++ Zope3/trunk/doc/CHANGES.txt	2004-12-09 18:43:20 UTC (rev 28599)
@@ -160,6 +160,9 @@
       - The `pluggableauth` package has been deprecated. The `pas` module
         provides a much more modular approach with many more capabilities.
 
+      - Removed special `DomainRegistration` now that we have events for
+        notification.
+
       - Removed special `RoleRegistration` now that we have events for
         notification. Also, renamed `PersistentRole` to `LocalRole`.
 

Modified: Zope3/trunk/src/zope/app/i18n/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/i18n/configure.zcml	2004-12-09 18:06:13 UTC (rev 28598)
+++ Zope3/trunk/src/zope/app/i18n/configure.zcml	2004-12-09 18:43:20 UTC (rev 28599)
@@ -1,72 +1,86 @@
 <configure
    xmlns="http://namespaces.zope.org/zope">
 
-<!-- Setup language negotiation -->
-<utility 
-    provides="zope.i18n.interfaces.INegotiator"
-    component="zope.i18n.negotiator.negotiator" />
-
-<adapter factory="zope.publisher.browser.BrowserLanguages"
-    for="zope.publisher.interfaces.browser.IBrowserRequest"
-    provides="zope.i18n.interfaces.IUserPreferredLanguages" />
-
-<!-- Setup charset negotiation -->
-<adapter factory="zope.publisher.http.HTTPCharsets"
-    for="zope.publisher.interfaces.http.IHTTPRequest"
-    provides="zope.i18n.interfaces.IUserPreferredCharsets" />
-
-<!-- Register the Translation Domain as a content object -->
-<localUtility 
-    class=".translationdomain.TranslationDomain">
-   <factory 
-        id="zope.app.TranslationService" 
+  <!-- Setup language negotiation -->
+  <utility 
+      provides="zope.i18n.interfaces.INegotiator"
+      component="zope.i18n.negotiator.negotiator" 
+      />
+  
+  <adapter factory="zope.publisher.browser.BrowserLanguages"
+      for="zope.publisher.interfaces.browser.IBrowserRequest"
+      provides="zope.i18n.interfaces.IUserPreferredLanguages" 
+      />
+  
+  <!-- Setup charset negotiation -->
+  <adapter factory="zope.publisher.http.HTTPCharsets"
+      for="zope.publisher.interfaces.http.IHTTPRequest"
+      provides="zope.i18n.interfaces.IUserPreferredCharsets" 
+      />
+  
+  <!-- Register the Translation Domain as a content object -->
+  <localUtility class=".translationdomain.TranslationDomain">
+    <factory 
+         id="zope.app.TranslationService" 
+         />
+    <allow interface="zope.i18n.interfaces.ITranslationDomain" 
         />
-   <allow interface="zope.i18n.interfaces.ITranslationDomain" 
-       />
-   <require permission="zope.ManageServices"
-       interface="zope.app.container.interfaces.IContainer" 
-       />
-   <require permission="zope.ManageServices"
-       interface=".interfaces.IWriteTranslationDomain" 
-       />
-   <require permission="zope.ManageServices"
-       interface=".interfaces.ISyncTranslationDomain" 
-       />
-</localUtility>
+    <require permission="zope.ManageServices"
+        interface="zope.app.container.interfaces.IContainer" 
+        />
+    <require permission="zope.ManageServices"
+        interface=".interfaces.IWriteTranslationDomain" 
+        />
+    <require permission="zope.ManageServices"
+        interface=".interfaces.ISyncTranslationDomain" 
+        />
+  </localUtility>
+  
+  <subscriber
+     for="..registration.interfaces.IRegistrationActivatedEvent"
+     factory=".translationdomain.setDomainOnActivation"
+     />
 
-<content class=".translationdomain.DomainRegistration">
-  <require
-    permission="zope.ManageServices"
-    interface="zope.app.utility.interfaces.IUtilityRegistration"
-    set_schema="zope.app.utility.interfaces.IUtilityRegistration" />
-</content>
+  <subscriber
+     for="..registration.interfaces.IRegistrationDeactivatedEvent"
+     factory=".translationdomain.unsetDomainOnDeactivation"
+     />  
 
-<!-- Setup Message Catalogs -->
-<content class=".messagecatalog.MessageCatalog">
-  <factory id="zope.app.MessageCatalog" />
-  <implements 
-      interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
+  <content class=".translationdomain.DomainRegistration">
+    <require
+        permission="zope.ManageServices"
+        interface="zope.app.utility.interfaces.IUtilityRegistration"
+        set_schema="zope.app.utility.interfaces.IUtilityRegistration" />
+  </content>
+  
+  <!-- Setup Message Catalogs -->
+  <content class=".messagecatalog.MessageCatalog">
+    <factory id="zope.app.MessageCatalog" />
+    <implements 
+        interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
+  
+    <require permission="zope.View" 
+        interface="zope.i18n.interfaces.IMessageCatalog" />
+    <require permission="zope.ManageServices"
+        attributes="setMessage getMessageIds" />
+  </content>
+  
+  
+  <!-- Setup Export and Import Filters -->
+  <adapter 
+      factory=".filters.GettextExportFilter"
+      for=".interfaces.ILocalTranslationDomain"
+      provides="zope.i18n.interfaces.IMessageExportFilter" 
+      />
+  
+  <adapter 
+      factory=".filters.GettextImportFilter"
+      for=".interfaces.ILocalTranslationDomain"
+      provides="zope.i18n.interfaces.IMessageImportFilter" 
+      />
+  
+  <include file="locales.zcml" />
+  <include package=".xmlrpc" />
+  <include package=".browser" />
 
-  <require permission="zope.View" 
-      interface="zope.i18n.interfaces.IMessageCatalog" />
-  <require permission="zope.ManageServices"
-      attributes="setMessage getMessageIds" />
-</content>
-
-
-<!-- Setup Export and Import Filters -->
-<adapter 
-    factory=".filters.GettextExportFilter"
-    for=".interfaces.ILocalTranslationDomain"
-    provides="zope.i18n.interfaces.IMessageExportFilter" />
-
-<adapter 
-    factory=".filters.GettextImportFilter"
-    for=".interfaces.ILocalTranslationDomain"
-    provides="zope.i18n.interfaces.IMessageImportFilter" />
-
-<include file="locales.zcml" />
-<include package=".xmlrpc" />
-<include package=".browser" />
-
 </configure>

Modified: Zope3/trunk/src/zope/app/i18n/tests/test_translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/app/i18n/tests/test_translationdomain.py	2004-12-09 18:06:13 UTC (rev 28598)
+++ Zope3/trunk/src/zope/app/i18n/tests/test_translationdomain.py	2004-12-09 18:43:20 UTC (rev 28599)
@@ -17,26 +17,29 @@
 """
 import unittest
 
-from zope.app import zapi
 from zope.component.interfaces import IFactory
 from zope.component.factory import Factory
-from zope.app.i18n.interfaces import ISyncTranslationDomain
-from zope.app.servicenames import Utilities
-from zope.app.i18n.messagecatalog import MessageCatalog
+from zope.i18n.interfaces import ITranslationDomain
+from zope.i18n.interfaces import IUserPreferredLanguages
+from zope.i18n.tests.test_itranslationdomain import TestITranslationDomain
 from zope.i18n.translationdomain \
      import TranslationDomain as GlobalTranslationDomain
-from zope.app.i18n.translationdomain import TranslationDomain
-from zope.app.tests import setup, ztapi
-from zope.i18n.interfaces import IUserPreferredLanguages
-from zope.i18n.tests.test_itranslationdomain import TestITranslationDomain
 from zope.interface import implements, classImplements
 from zope.interface.verify import verifyObject
+from zope.testing.doctestunit import DocTestSuite
+
+from zope.app import zapi
+from zope.app.annotation.interfaces import IAttributeAnnotatable
+from zope.app.i18n.interfaces import ISyncTranslationDomain
+from zope.app.i18n.messagecatalog import MessageCatalog
+from zope.app.i18n.translationdomain import TranslationDomain
+from zope.app.servicenames import Utilities
 from zope.app.site.tests.placefulsetup import PlacefulSetup
+from zope.app.tests import setup, ztapi
 from zope.app.utility import LocalUtilityService
-from zope.i18n.interfaces import ITranslationDomain
 from zope.app.utility.interfaces import ILocalUtility 
-from zope.app.annotation.interfaces import IAttributeAnnotatable
 
+
 class Environment(object):
 
     implements(IUserPreferredLanguages)
@@ -269,9 +272,11 @@
                                   target_language='de'),
             'Hallo Welt!')
 
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestTranslationDomain),
+        DocTestSuite('zope.app.i18n.translationdomain'),
         #unittest.makeSuite(TestTranslationDomainInAction),
         ))
 

Modified: Zope3/trunk/src/zope/app/i18n/translationdomain.py
===================================================================
--- Zope3/trunk/src/zope/app/i18n/translationdomain.py	2004-12-09 18:06:13 UTC (rev 28598)
+++ Zope3/trunk/src/zope/app/i18n/translationdomain.py	2004-12-09 18:43:20 UTC (rev 28599)
@@ -41,7 +41,7 @@
     def __init__(self):
         super(TranslationDomain, self).__init__()
         self._catalogs = OOBTree()
-        self.domain = None
+        self.domain = '<domain not activated>'
 
     def _registerMessageCatalog(self, language, catalog_name):
         if language not in self._catalogs.keys():
@@ -223,15 +223,89 @@
                                    fmsg['mod_time'])
 
 
+# BBB: Backward compatibility. 12/09/2004
+DomainRegistration = UtilityRegistration
 
-class DomainRegistration(UtilityRegistration):
-    """Domain Registration
+def setDomainOnActivation(event):
+    """Set the permission id upon registration activation.
 
-    We have a custom registration here, since we want active registrations to
-    set the domain of the TranslationDomain.
+    Let's see how this notifier can be used. First we need to create an event
+    using the permission instance and a registration stub:
+
+    >>> class Registration:
+    ...     def __init__(self, obj, name):
+    ...         self.component = obj
+    ...         self.name = name
+
+    >>> domain1 = TranslationDomain()
+    >>> domain1.domain
+    '<domain not activated>'
+
+    >>> from zope.app.registration import registration 
+    >>> event = registration.RegistrationActivatedEvent(
+    ...     Registration(domain1, 'domain1'))
+
+    Now we pass the event into this function, and the id of the domain should
+    be set to 'domain1'.
+
+    >>> setDomainOnActivation(event)
+    >>> domain1.domain
+    'domain1'
+
+    If the function is called and the component is not a local domain, nothing
+    is done:
+
+    >>> class Foo:
+    ...     domain = 'no domain'
+    >>> foo = Foo()
+    >>> event = registration.RegistrationActivatedEvent(
+    ...     Registration(foo, 'foo'))
+    >>> setDomainOnActivation(event)
+    >>> foo.domain
+    'no domain'
     """
-    def activated(self):
-        self.component.domain = self.name
+    domain = event.object.component
+    if isinstance(domain, TranslationDomain):
+        domain.domain = event.object.name
 
-    def deactivated(self):
-        self.component.domain = '<domain not activated>'
+
+def unsetDomainOnDeactivation(event):
+    """Unset the permission id up registration deactivation.
+
+    Let's see how this notifier can be used. First we need to create an event
+    using the permission instance and a registration stub:
+
+    >>> class Registration:
+    ...     def __init__(self, obj, name):
+    ...         self.component = obj
+    ...         self.name = name
+
+    >>> domain1 = TranslationDomain()
+    >>> domain1.domain = 'domain1'
+
+    >>> from zope.app.registration import registration 
+    >>> event = registration.RegistrationDeactivatedEvent(
+    ...     Registration(domain1, 'domain1'))
+
+    Now we pass the event into this function, and the id of the role should be
+    set to '<domain not activated>'.
+
+    >>> unsetDomainOnDeactivation(event)
+    >>> domain1.domain
+    '<domain not activated>'
+
+    If the function is called and the component is not a local domain,
+    nothing is done:
+
+    >>> class Foo:
+    ...     domain = 'foo'
+    >>> foo = Foo()
+    >>> event = registration.RegistrationDeactivatedEvent(
+    ...     Registration(foo, 'foo'))
+    >>> unsetDomainOnDeactivation(event)
+    >>> foo.domain
+    'foo'
+    """
+    domain = event.object.component
+    if isinstance(domain, TranslationDomain):
+        domain.domain = '<domain not activated>'



More information about the Zope3-Checkins mailing list