Updated ZODB connection interface ZTK-1.1
authorThierry Florac <tflorac@ulthar.net>
Mon, 24 Sep 2012 08:49:04 +0200
branchZTK-1.1
changeset 173 7164eb24f949
parent 171 0e8925323082
child 174 380f23a1587e
Updated ZODB connection interface
src/ztfy/utils/interfaces.py
src/ztfy/utils/zodb.py
--- a/src/ztfy/utils/interfaces.py	Fri Sep 21 01:18:08 2012 +0200
+++ b/src/ztfy/utils/interfaces.py	Mon Sep 24 08:49:04 2012 +0200
@@ -42,44 +42,44 @@
 class IListInfo(Interface):
     """Custom interface used to handle list-like components"""
 
-    def count():
+    def count(self):
         """Get list items count"""
 
-    def index():
+    def index(self):
         """Get position of the given item"""
 
-    def __contains__():
-        """Check if given value is int list"""
+    def __contains__(self, value):
+        """Check if given value is in list"""
 
-    def __getitem__():
+    def __getitem__(self, index):
         """Return item at given position"""
 
-    def __iter__():
+    def __iter__(self):
         """Iterator over list items"""
 
 
 class IListWriter(Interface):
     """Writer interface for list-like components"""
 
-    def append():
+    def append(self, value):
         """Append value to list"""
 
-    def extend():
+    def extend(self, values):
         """Extend list with given items"""
 
-    def insert():
+    def insert(self, index, value):
         """Insert item to given index"""
 
-    def pop():
+    def pop(self):
         """Pop item from list and returns it"""
 
-    def remove():
+    def remove(self, value):
         """Remove given item from list"""
 
-    def reverse():
+    def reverse(self):
         """Sort list in reverse order"""
 
-    def sort():
+    def sort(self):
         """Sort list"""
 
 
@@ -94,50 +94,50 @@
 class IDictInfo(Interface):
     """Custom interface used to handle dict-like components"""
 
-    def keys():
+    def keys(self):
         """Get list of keys for the dict"""
 
-    def has_key(key):
+    def has_key(self, key):
         """Check to know if dict includes the given key"""
 
-    def get(key, default=None):
+    def get(self, key, default=None):
         """Get given key or default from dict"""
 
-    def copy():
+    def copy(self,):
         """Duplicate content of dict"""
 
-    def __contains__(key):
+    def __contains__(self, key):
         """Check if given key is in dict"""
 
-    def __getitem__(key):
+    def __getitem__(self, key):
         """Get given key value from dict"""
 
-    def __iter__():
+    def __iter__(self):
         """Iterator over dictionnary keys"""
 
 
 class IDictWriter(Interface):
     """Writer interface for dict-like components"""
 
-    def clear():
+    def clear(self):
         """Clear dict"""
 
-    def update(b):
+    def update(self, b):
         """Update dict with given values"""
 
-    def setdefault(key, failobj=None):
+    def setdefault(self, key, failobj=None):
         """Create value for given key if missing"""
 
-    def pop(key, *args):
+    def pop(self, key, *args):
         """Remove and return given key from dict"""
 
-    def popitem():
+    def popitem(self, item):
         """Pop item from dict"""
 
-    def __setitem__(key, value):
+    def __setitem__(self, key, value):
         """Update given key with given value"""
 
-    def __delitem__(key):
+    def __delitem__(self, key):
         """Remove selected key from dict"""
 
 
@@ -182,5 +182,8 @@
     def getJSONSettings(self):
         """Get ZEO connection setting as a JSON dict"""
 
+    def update(self, values):
+        """Update connection properties from given dict values"""
+
     def getConnection(self, wait=False):
         """Open ZEO connection with given settings"""
--- a/src/ztfy/utils/zodb.py	Fri Sep 21 01:18:08 2012 +0200
+++ b/src/ztfy/utils/zodb.py	Mon Sep 24 08:49:04 2012 +0200
@@ -53,17 +53,23 @@
     server_realm = FieldProperty(IZEOConnection['server_realm'])
 
     def getJSONSettings(self):
-        result = []
+        result = {}
         for name in getFieldNames(IZEOConnection):
             result[name] = getattr(self, name)
         return result
 
+    def update(self, values):
+        names = getFieldNames(IZEOConnection)
+        for k, v in values.items():
+            if k in names:
+                setattr(self, k, unicode(v) if isinstance(v, str) else v)
+
     def getConnection(self, wait=False, get_storage=False):
         """Get a tuple made of storage and DB connection for given settings"""
         storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port),
-                                              storage=self.server_storage,
-                                              username=self.server_username or '',
-                                              password=self.server_password or '',
+                                              storage=self.storage,
+                                              username=self.username or '',
+                                              password=self.password or '',
                                               realm=self.server_realm,
                                               wait=wait)
         db = DB(storage)