[Checkins] SVN: zc.zk/trunk/src/zc/zk/ - The walk method now provides options to:
jim
cvs-admin at zope.org
Tue Sep 25 19:56:18 UTC 2012
Log message for revision 127886:
- The walk method now provides options to:
- skip ephemeral nodes
- yield a mutable children list, allowing walking to be
short-circuited.
- Fixed: if nodes were deleted (e.g. by other clients) then the walk
method could raise ``NoNodeException``.
Changed:
U zc.zk/trunk/src/zc/zk/README.txt
U zc.zk/trunk/src/zc/zk/__init__.py
-=-
Modified: zc.zk/trunk/src/zc/zk/README.txt
===================================================================
--- zc.zk/trunk/src/zc/zk/README.txt 2012-09-25 19:55:31 UTC (rev 127885)
+++ zc.zk/trunk/src/zc/zk/README.txt 2012-09-25 19:56:15 UTC (rev 127886)
@@ -884,6 +884,34 @@
/fooservice/provision/node1
/fooservice/provision/node2
+You can omit ephemeral nodes:
+
+ >>> for path in zk.walk('/fooservice', ephemeral=False):
+ ... print path
+ /fooservice
+ /fooservice/providers
+ /fooservice/providers/192.168.0.42:8080
+ /fooservice/providers/192.168.0.42:8081
+ /fooservice/providers/192.168.0.42:8082
+ /fooservice/provision
+ /fooservice/provision/node1
+ /fooservice/provision/node2
+
+You can also get a mutable list of children, which you can mutate:
+
+ >>> i = zk.walk('/fooservice', children=True)
+ >>> path, children = i.next()
+ >>> path, children
+ ('/fooservice', ['providers', 'provision'])
+
+ >>> del children[0]
+ >>> for path in i:
+ ... print path
+ /fooservice/provision
+ /fooservice/provision/node1
+ /fooservice/provision/node2
+
+
Modifications to nodes are reflected while traversing::
>>> for path in zk.walk('/fooservice'):
@@ -1175,7 +1203,19 @@
Change History
==============
+1.0.0 (2012-09-25)
+------------------
+- The walk method now provides options to:
+
+ - skip ephemeral nodes
+
+ - yield a mutable children list, allowing walking to be
+ short-circuited.
+
+- Fixed: if nodes were deleted (e.g. by other clients) then the walk
+ method could raise ``NoNodeException``.
+
0.9.4 (2012-09-11)
------------------
Modified: zc.zk/trunk/src/zc/zk/__init__.py
===================================================================
--- zc.zk/trunk/src/zc/zk/__init__.py 2012-09-25 19:55:31 UTC (rev 127885)
+++ zc.zk/trunk/src/zc/zk/__init__.py 2012-09-25 19:56:15 UTC (rev 127886)
@@ -563,9 +563,20 @@
return zookeeper.CONNECTING_STATE
return zookeeper.state(self.handle)
- def walk(self, path='/'):
- yield path
- for name in sorted(self.get_children(path)):
+ def walk(self, path='/', ephemeral=True, children=False):
+ try:
+ if not ephemeral and self.get(path)[1]['ephemeralOwner']:
+ return
+
+ _children = sorted(self.get_children(path))
+ if children:
+ yield path, _children
+ else:
+ yield path
+ except zookeeper.NoNodeException:
+ return
+
+ for name in _children:
if path != '/':
name = '/'+name
for p in self.walk(path+name):
More information about the checkins
mailing list