Skip to content

Commit b7b2b15

Browse files
committed
feat(core): Add support for Create2 in transactions.
1 parent 5225b3e commit b7b2b15

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

kazoo/client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,13 @@ def __init__(self, client):
16731673
self.committed = False
16741674

16751675
def create(
1676-
self, path, value=b"", acl=None, ephemeral=False, sequence=False
1676+
self,
1677+
path,
1678+
value=b"",
1679+
acl=None,
1680+
ephemeral=False,
1681+
sequence=False,
1682+
include_data=False,
16771683
):
16781684
"""Add a create ZNode to the transaction. Takes the same
16791685
arguments as :meth:`KazooClient.create`, with the exception
@@ -1697,6 +1703,8 @@ def create(
16971703
raise TypeError("Invalid type for 'ephemeral' (bool expected)")
16981704
if not isinstance(sequence, bool):
16991705
raise TypeError("Invalid type for 'sequence' (bool expected)")
1706+
if not isinstance(include_data, bool):
1707+
raise TypeError("Invalid type for 'include_data' (bool expected)")
17001708

17011709
flags = 0
17021710
if ephemeral:
@@ -1705,9 +1713,13 @@ def create(
17051713
flags |= 2
17061714
if acl is None:
17071715
acl = OPEN_ACL_UNSAFE
1716+
if include_data:
1717+
opcode = Create2
1718+
else:
1719+
opcode = Create
17081720

17091721
self._add(
1710-
Create(_prefix_root(self.client.chroot, path), value, acl, flags),
1722+
opcode(_prefix_root(self.client.chroot, path), value, acl, flags),
17111723
None,
17121724
)
17131725

kazoo/protocol/serialization.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ def deserialize(cls, bytes, offset):
343343
while not header.done:
344344
if header.type == Create.type:
345345
response, offset = read_string(bytes, offset)
346+
elif header.type == Create2.type:
347+
path, offset = read_string(bytes, offset)
348+
stat = ZnodeStat._make(stat_struct.unpack_from(bytes, offset))
349+
offset += stat_struct.size
350+
response = (path, stat)
346351
elif header.type == Delete.type:
347352
response = True
348353
elif header.type == SetData.type:
@@ -367,6 +372,10 @@ def unchroot(client, response):
367372
for result in response:
368373
if isinstance(result, str):
369374
resp.append(client.unchroot(result))
375+
elif isinstance(result, ZnodeStat): # Need to test before tuple
376+
resp.append(result)
377+
elif isinstance(result, tuple):
378+
resp.append((client.unchroot(result[0]), result[1]))
370379
else:
371380
resp.append(result)
372381
return resp

0 commit comments

Comments
 (0)