[Checkins] SVN: zc.zk/trunk/src/zc/zk/ Fixed incompatibilities with ZooKeeper 3.3.4

Jim Fulton jim at zope.com
Wed Jan 4 20:48:00 UTC 2012


Log message for revision 123940:
  Fixed incompatibilities with ZooKeeper 3.3.4
  
  - ZooKeeper raises a ``zookeeper.BadArgumentsException`` when an
    invalid path is passed to ``exists``. Previously, returned False.
  
  - ``get_children`` no-longer returnes ordered values.
  
  Also added some missing test cleanup.
  

Changed:
  U   zc.zk/trunk/src/zc/zk/README.txt
  U   zc.zk/trunk/src/zc/zk/__init__.py
  U   zc.zk/trunk/src/zc/zk/testing.py
  U   zc.zk/trunk/src/zc/zk/tests.py

-=-
Modified: zc.zk/trunk/src/zc/zk/README.txt
===================================================================
--- zc.zk/trunk/src/zc/zk/README.txt	2012-01-04 13:12:08 UTC (rev 123939)
+++ zc.zk/trunk/src/zc/zk/README.txt	2012-01-04 20:47:59 UTC (rev 123940)
@@ -989,6 +989,16 @@
 Change History
 ==============
 
+0.5.1 (2012-01-04)
+------------------
+
+- Fixed incompatibilities with ZooKeeper 3.3.4
+
+  - ZooKeeper raises a ``zookeeper.BadArgumentsException`` when an
+    invalid path is passed to ``exists``. Previously, returned False.
+
+  - ``get_children`` no-longer returnes ordered values.
+
 0.5.0 (2011-12-27)
 ------------------
 

Modified: zc.zk/trunk/src/zc/zk/__init__.py
===================================================================
--- zc.zk/trunk/src/zc/zk/__init__.py	2012-01-04 13:12:08 UTC (rev 123939)
+++ zc.zk/trunk/src/zc/zk/__init__.py	2012-01-04 20:47:59 UTC (rev 123940)
@@ -117,8 +117,12 @@
             else:
                 raise zookeeper.NoNodeException(path)
 
-        if self.exists(path):
-            return path
+        try:
+            if self.exists(path):
+                return path
+        except zookeeper.BadArgumentsException:
+            if not path[:1] == '/':
+                raise zookeeper.NoNodeException(path)
 
         if path in seen:
             seen += (path,)
@@ -355,7 +359,7 @@
     def _import_tree(self, path, node, acl, trim, dry_run, top=False):
         if not top:
             new_children = set(node.children)
-            for name in self.get_children(path):
+            for name in sorted(self.get_children(path)):
                 if name in new_children:
                     continue
                 cpath = join(path, name)
@@ -364,7 +368,7 @@
                 else:
                     print 'extra path not trimmed:', cpath
 
-        for name, child in node.children.iteritems():
+        for name, child in sorted(node.children.iteritems()):
             cpath = path + '/' + name
             data = encode(child.properties)
             if self.exists(cpath):

Modified: zc.zk/trunk/src/zc/zk/testing.py
===================================================================
--- zc.zk/trunk/src/zc/zk/testing.py	2012-01-04 13:12:08 UTC (rev 123939)
+++ zc.zk/trunk/src/zc/zk/testing.py	2012-01-04 20:47:59 UTC (rev 123940)
@@ -23,6 +23,7 @@
 import mock
 import os
 import random
+import re
 import sys
 import threading
 import time
@@ -257,6 +258,8 @@
     zookeeper.UnimplementedException: zookeeper.UNIMPLEMENTED,
 }
 
+badpath = re.compile(r'(^([^/]|$))|(/\.\.?(/|$))|(./$)').search
+
 class ZooKeeper:
 
     def __init__(self, connection_string, tree):
@@ -400,6 +403,8 @@
     def exists(self, handle, path, watch=None):
         if watch is not None:
             raise TypeError('exists watch not supported')
+        if badpath(path):
+            raise zookeeper.BadArgumentsException('bad argument')
         with self.lock:
             self._check_handle(handle)
             try:
@@ -418,7 +423,7 @@
             node = self._traverse(path)
             if watch:
                 node.child_watchers += ((handle, watch), )
-            return sorted(node.children)
+            return list(node.children)
 
     def aget_children(self, handle, path, watch=None, completion=None):
         return self._doasync(completion, handle, 1,

Modified: zc.zk/trunk/src/zc/zk/tests.py
===================================================================
--- zc.zk/trunk/src/zc/zk/tests.py	2012-01-04 13:12:08 UTC (rev 123939)
+++ zc.zk/trunk/src/zc/zk/tests.py	2012-01-04 20:47:59 UTC (rev 123940)
@@ -1069,6 +1069,7 @@
     3
     >>> p['x333']
     3
+    >>> zk.close()
     """
 
 def property_links_expand_callbacks_to_linked_nodes():
@@ -1101,6 +1102,7 @@
 
     >>> ac.update(x=4)
 
+    >>> zk.close()
     """
 
 def bad_links_are_reported_and_prevent_updates():
@@ -1169,6 +1171,8 @@
     {u'database': u'/databases/foomain',
      u'favorite_color': u'red',
      u'threads': 1}
+
+    >>> zk.close()
     """
 
 def contains_w_property_link():
@@ -1179,6 +1183,7 @@
     >>> 'c' in properties
     True
 
+    >>> zk.close()
     """
 
 def property_getitem_error_handling():
@@ -1203,6 +1208,8 @@
     Traceback (most recent call last):
     ...
     BadPropertyLink: (IndexError('pop from empty list',), "in 'c =>': u''")
+
+    >>> zk.close()
     """
 
 def property_link_loops():
@@ -1222,6 +1229,7 @@
     (BadPropertyLink(BadPropertyLink(LinkLoop((u'/b', u'/a', u'/b'),),
     "in u'x =>': u'../b x'"), "in u'x =>': u'../a x'"), "in 'x =>': u'../b x'")
 
+    >>> zk.close()
     """
 
 def deleting_linked_nodes():
@@ -1258,6 +1266,7 @@
     >>> ab['x']
     2
 
+    >>> zk.close()
     """
 
 



More information about the checkins mailing list