Updated ZEO connection timeout management
authorThierry Florac <thierry.florac@onf.fr>
Mon, 05 Feb 2018 13:53:51 +0100
changeset 134 73c01f34ef19
parent 133 8491b96ad19c
child 135 fc98621aa9d2
Updated ZEO connection timeout management
src/pyams_utils/interfaces/zeo.py
src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo
src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po
src/pyams_utils/locales/pyams_utils.pot
src/pyams_utils/zodb.py
--- a/src/pyams_utils/interfaces/zeo.py	Mon Feb 05 10:50:20 2018 +0100
+++ b/src/pyams_utils/interfaces/zeo.py	Mon Feb 05 13:53:51 2018 +0100
@@ -47,15 +47,15 @@
                        default='1')
 
     username = TextLine(title=_("ZEO user name"),
-                        description=_("User name on ZEO server"),
+                        description=_("User name on ZEO server; only for ZEO server before 5.0"),
                         required=False)
 
     password = Password(title=_("ZEO password"),
-                        description=_("User password on ZEO server"),
+                        description=_("User password on ZEO server; only for ZEO server before 5.0"),
                         required=False)
 
     server_realm = TextLine(title=_("ZEO server realm"),
-                            description=_("Realm name on ZEO server"),
+                            description=_("Realm name on ZEO server; only for ZEO server before 5.0"),
                             required=False)
 
     blob_dir = TextLine(title=_("BLOBs directory"),
@@ -76,5 +76,5 @@
     def update(self, settings):
         """Update internal fields with given settings dict"""
 
-    def get_connection(self, wait=False, get_storage=False):
+    def get_connection(self, wait_timeout=30, get_storage=False):
         """Open ZEO connection with given settings"""
Binary file src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.mo has changed
--- a/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po	Mon Feb 05 10:50:20 2018 +0100
+++ b/src/pyams_utils/locales/fr/LC_MESSAGES/pyams_utils.po	Mon Feb 05 13:53:51 2018 +0100
@@ -4,7 +4,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2018-01-26 15:31+0100\n"
+"POT-Creation-Date: 2018-02-05 13:53+0100\n"
 "PO-Revision-Date: 2015-01-18 01:01+0100\n"
 "Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
 "Language-Team: French\n"
@@ -627,25 +627,30 @@
 msgstr "Code utilisateur"
 
 #: src/pyams_utils/interfaces/zeo.py:50
-msgid "User name on ZEO server"
+msgid "User name on ZEO server; only for ZEO server before 5.0"
 msgstr ""
-"Code utilisateur nécessaire lorsque le serveur demande une authentification"
+"Code utilisateur nécessaire lorsque le serveur demande une authentification; "
+"pour les serveurs ZEO avant la version 5.0 uniquement!!"
 
 #: src/pyams_utils/interfaces/zeo.py:53
 msgid "ZEO password"
 msgstr "Mot de passe"
 
 #: src/pyams_utils/interfaces/zeo.py:54
-msgid "User password on ZEO server"
-msgstr "Mot de passe correspondant au code utilisateur indiqué"
+msgid "User password on ZEO server; only for ZEO server before 5.0"
+msgstr ""
+"Mot de passe correspondant au code utilisateur indiqué; pour les serveurs "
+"ZEO avant la version 5.0 uniquement!!"
 
 #: src/pyams_utils/interfaces/zeo.py:57
 msgid "ZEO server realm"
 msgstr "Domaine"
 
 #: src/pyams_utils/interfaces/zeo.py:58
-msgid "Realm name on ZEO server"
-msgstr "Nom du domaine d'authentification"
+msgid "Realm name on ZEO server; only for ZEO server before 5.0"
+msgstr ""
+"Nom du domaine d'authentification; pour les serveurs ZEO avant la version "
+"5.0 uniquement!!"
 
 #: src/pyams_utils/interfaces/zeo.py:61
 msgid "BLOBs directory"
@@ -749,3 +754,8 @@
 #: src/pyams_utils/interfaces/__init__.py:51
 msgid "Not an iterator"
 msgstr "Ce n'est pas un itérateur"
+
+#~ msgid "User name on ZEO server"
+#~ msgstr ""
+#~ "Code utilisateur nécessaire lorsque le serveur demande une "
+#~ "authentification"
--- a/src/pyams_utils/locales/pyams_utils.pot	Mon Feb 05 10:50:20 2018 +0100
+++ b/src/pyams_utils/locales/pyams_utils.pot	Mon Feb 05 13:53:51 2018 +0100
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2018-01-26 15:31+0100\n"
+"POT-Creation-Date: 2018-02-05 13:53+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -624,7 +624,7 @@
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:50
-msgid "User name on ZEO server"
+msgid "User name on ZEO server; only for ZEO server before 5.0"
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:53
@@ -632,7 +632,7 @@
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:54
-msgid "User password on ZEO server"
+msgid "User password on ZEO server; only for ZEO server before 5.0"
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:57
@@ -640,7 +640,7 @@
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:58
-msgid "Realm name on ZEO server"
+msgid "Realm name on ZEO server; only for ZEO server before 5.0"
 msgstr ""
 
 #: ./src/pyams_utils/interfaces/zeo.py:61
--- a/src/pyams_utils/zodb.py	Mon Feb 05 10:50:20 2018 +0100
+++ b/src/pyams_utils/zodb.py	Mon Feb 05 13:53:51 2018 +0100
@@ -33,8 +33,7 @@
 from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from pyramid_zodbconn import get_uris, db_from_uri
-from ZEO import ClientStorage
-from ZODB import DB
+from ZEO import DB
 from zope.container.contained import Contained
 from zope.interface import implementer
 from zope.schema import getFieldNames
@@ -143,25 +142,24 @@
             if key in names:
                 setattr(self, key, value)
 
-    def get_connection(self, wait=False, get_storage=False):
+    def get_connection(self, wait_timeout=30, get_storage=False):
         """Create ZEO client connection from current settings
 
-        :param boolean wait: should connection wait until storage is ready
+        :param boolean wait_timeout: connection timeout, in seconds
         :param boolean get_storage: if *True*, the method should return a tuple containing
             storage and DB objects; otherwise only DB object is returned
         :return: tuple containing ZEO client storage and DB object (if *get_storage* argument is
             set to *True*), or only DB object otherwise
         """
-        storage = ClientStorage.ClientStorage((self.server_name, self.server_port),
-                                              storage=self.storage,
-                                              username=self.username or '',
-                                              password=self.password or '',
-                                              realm=self.server_realm,
-                                              blob_dir=self.blob_dir,
-                                              shared_blob_dir=self.shared_blob_dir,
-                                              wait=wait)
-        db = DB(storage)
-        return (storage, db) if get_storage else db
+        db = DB((self.server_name, self.server_port),
+                storage=self.storage,
+                username=self.username or '',
+                password=self.password or '',
+                realm=self.server_realm,
+                blob_dir=self.blob_dir,
+                shared_blob_dir=self.shared_blob_dir,
+                wait_timeout=wait_timeout)
+        return (db.storage, db) if get_storage else db
 
     @property
     def connection(self):
@@ -170,7 +168,7 @@
     # Context manager methods
     def __enter__(self):
         self._storage, self._db = self.get_connection(get_storage=True)
-        self._connection = self._db.open()
+        self._connection = self._db.open_then_close_db_when_connection_closes()
         return self._connection.root()
 
     def __exit__(self, exc_type, exc_val, exc_tb):