def create(self, path, value=b"", acl=None, ephemeral=False, sequence=False): """Add a create ZNode to the transaction. Takes the same arguments as :meth:`KazooClient.create`, with the exception of `makepath`. :returns: None """ if acl is None and self.client.default_acl: acl = self.client.default_acl if not isinstance(path, basestring): raise TypeError("path must be a string") if acl and not isinstance(acl, (tuple, list)): raise TypeError("acl must be a tuple/list of ACL's") if not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(ephemeral, bool): raise TypeError("ephemeral must be a bool") if not isinstance(sequence, bool): raise TypeError("sequence must be a bool") flags = 0 if ephemeral: flags |= 1 if sequence: flags |= 2 if acl is None: acl = OPEN_ACL_UNSAFE self._add(Create(_prefix_root(self.client.chroot, path), value, acl, flags), None)
def create_async(self, path, value=b"", acl=None, ephemeral=False, sequence=False): """Asynchronously create a ZNode. Takes the same arguments as :meth:`create`, with the exception of `makepath`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if acl is None and self.default_acl: acl = self.default_acl if not isinstance(path, basestring): raise TypeError("path must be a string") if acl and (isinstance(acl, ACL) or not isinstance(acl, (tuple, list))): raise TypeError("acl must be a tuple/list of ACL's") if not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(ephemeral, bool): raise TypeError("ephemeral must be a bool") if not isinstance(sequence, bool): raise TypeError("sequence must be a bool") flags = 0 if ephemeral: flags |= 1 if sequence: flags |= 2 if acl is None: acl = OPEN_ACL_UNSAFE async_result = self.handler.async_result() self._call(Create(_prefix_root(self.chroot, path), value, acl, flags), async_result) return async_result
def create_async(self, path, value="", acl=None, ephemeral=False, sequence=False): """Asynchronously create a ZNode. Takes the same arguments as :meth:`create`, with the exception of `makepath`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if acl is None and self.default_acl: acl = self.default_acl if not isinstance(path, basestring): raise TypeError("path must be a string") if acl and (isinstance(acl, ACL) or not isinstance(acl, (tuple, list))): raise TypeError("acl must be a tuple/list of ACL's") if not isinstance(value, str): raise TypeError("value must be a byte string") if not isinstance(ephemeral, bool): raise TypeError("ephemeral must be a bool") if not isinstance(sequence, bool): raise TypeError("sequence must be a bool") flags = 0 if ephemeral: flags |= 1 if sequence: flags |= 2 if acl is None: acl = OPEN_ACL_UNSAFE async_result = self.handler.async_result() self._call(Create(_prefix_root(self.chroot, path), value, acl, flags), async_result) return async_result
def sync_async(self, path): """Asynchronous sync. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ async_result = self.handler.async_result() self._call(Sync(_prefix_root(self.chroot, path)), async_result) return async_result
def delete(self, path, version=-1): """Add a delete ZNode to the transaction. Takes the same arguments as :meth:`KazooClient.delete`, with the exception of `recursive`. """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") self._add(Delete(_prefix_root(self.client.chroot, path), version))
def delete(self, path, version=-1): """Add a delete ZNode to the transaction. Takes the same arguments as :meth:`KazooClient.delete`, with the exception of `recursive`. """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(version, int): raise TypeError("version must be an int") self._add(Delete(_prefix_root(self.client.chroot, path), version))
def get_children_async(self, path, watch=None, include_data=False): """Asynchronously get a list of child nodes of a path. Takes the same arguments as :meth:`get_children`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if watch and not callable(watch): raise TypeError("watch must be a callable") if not isinstance(include_data, bool): raise TypeError("include_data must be a bool") async_result = self.handler.async_result() if include_data: req = GetChildren2(_prefix_root(self.chroot, path), watch) else: req = GetChildren(_prefix_root(self.chroot, path), watch) self._call(req, async_result) return async_result
def check(self, path, version): """Add a Check Version to the transaction. This command will fail and abort a transaction if the path does not match the specified version. """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(version, int): raise TypeError("version must be an int") self._add(CheckVersion(_prefix_root(self.client.chroot, path), version))
def set_data(self, path, value, version=-1): """Add a set ZNode value to the transaction. Takes the same arguments as :meth:`KazooClient.set`. """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(version, int): raise TypeError("version must be an int") self._add(SetData(_prefix_root(self.client.chroot, path), value, version))
def get_acls_async(self, path): """Return the ACL and stat of the node of the given path. Takes the same arguments as :meth:`get_acls`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") async_result = self.handler.async_result() self._call(GetACL(_prefix_root(self.chroot, path)), async_result) return async_result
def check(self, path, version): """Add a Check Version to the transaction. This command will fail and abort a transaction if the path does not match the specified version. """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") self._add(CheckVersion(_prefix_root(self.client.chroot, path), version))
def set_data(self, path, value, version=-1): """Add a set ZNode value to the transaction. Takes the same arguments as :meth:`KazooClient.set`. """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if not isinstance(value, bytes_types): raise TypeError("Invalid type for 'value' (must be a byte string)") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") self._add(SetData(_prefix_root(self.client.chroot, path), value, version))
def set_data(self, path, value, version=-1): """Add a set ZNode value to the transaction. Takes the same arguments as :meth:`KazooClient.set`. """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(version, int): raise TypeError("version must be an int") self._add( SetData(_prefix_root(self.client.chroot, path), value, version))
def _create_async_inner(self, path, value, acl, flags, trailing=False): async_result = self.handler.async_result() call_result = self._call( Create(_prefix_root(self.chroot, path, trailing=trailing), value, acl, flags), async_result) if call_result is False: # We hit a short-circuit exit on the _call. Because we are # not using the original async_result here, we bubble the # exception upwards to the do_create function in # KazooClient.create so that it gets set on the correct # async_result object raise async_result.exception return async_result
def delete_async(self, path, version=-1): """Asynchronously delete a node. Takes the same arguments as :meth:`delete`, with the exception of `recursive`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(version, int): raise TypeError("version must be an int") async_result = self.handler.async_result() self._call(Delete(_prefix_root(self.chroot, path), version), async_result) return async_result
def get_async(self, path, watch=None): """Asynchronously get the value of a node. Takes the same arguments as :meth:`get`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if watch and not callable(watch): raise TypeError("watch must be a callable") async_result = self.handler.async_result() self._call(GetData(_prefix_root(self.chroot, path), watch), async_result) return async_result
def delete_async(self, path, version=-1): """Asynchronously delete a node. Takes the same arguments as :meth:`delete`, with the exception of `recursive`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") async_result = self.handler.async_result() self._call(Delete(_prefix_root(self.chroot, path), version), async_result) return async_result
def exists_async(self, path, watch=None): """Asynchronously check if a node exists. Takes the same arguments as :meth:`exists`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if watch and not callable(watch): raise TypeError("Invalid type for 'watch' (must be a callable)") async_result = self.handler.async_result() self._call(Exists(_prefix_root(self.chroot, path), watch), async_result) return async_result
def set_acls_async(self, path, acls, version=-1): """Set the ACL for the node of the given path. Takes the same arguments as :meth:`set_acls`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if isinstance(acls, ACL) or not isinstance(acls, (tuple, list)): raise TypeError("acl must be a tuple/list of ACL's") if not isinstance(version, int): raise TypeError("version must be an int") async_result = self.handler.async_result() self._call(SetACL(_prefix_root(self.chroot, path), acls, version), async_result) return async_result
def set_async(self, path, value, version=-1): """Set the value of a node. Takes the same arguments as :meth:`set`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(version, int): raise TypeError("version must be an int") async_result = self.handler.async_result() self._call(SetData(_prefix_root(self.chroot, path), value, version), async_result) return async_result
def set_async(self, path, value, version=-1): """Set the value of a node. Takes the same arguments as :meth:`set`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if value is not None and not isinstance(value, bytes_types): raise TypeError("Invalid type for 'value' (must be a byte string)") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") async_result = self.handler.async_result() self._call(SetData(_prefix_root(self.chroot, path), value, version), async_result) return async_result
def set_async(self, path, value, version=-1): """Set the value of a node. Takes the same arguments as :meth:`set`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, basestring): raise TypeError("path must be a string") if value is not None and not isinstance(value, bytes): raise TypeError("value must be a byte string") if not isinstance(version, int): raise TypeError("version must be an int") async_result = self.handler.async_result() self._call(SetData(_prefix_root(self.chroot, path), value, version), async_result) return async_result
def set_acls_async(self, path, acls, version=-1): """Set the ACL for the node of the given path. Takes the same arguments as :meth:`set_acls`. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ if not isinstance(path, string_types): raise TypeError("Invalid type for 'path' (string expected)") if isinstance(acls, ACL) or not isinstance(acls, (tuple, list)): raise TypeError("Invalid type for 'acl' (acl must be a tuple/list" " of ACL's") if not isinstance(version, int): raise TypeError("Invalid type for 'version' (int expected)") async_result = self.handler.async_result() self._call(SetACL(_prefix_root(self.chroot, path), acls, version), async_result) return async_result
def test_prefix_root(self): self.assertEquals(paths._prefix_root('/a/', 'b/c'), '/a/b/c') self.assertEquals(paths._prefix_root('/a/b', 'c/d'), '/a/b/c/d') self.assertEquals(paths._prefix_root('/a', '/b/c'), '/a/b/c') self.assertEquals(paths._prefix_root('/a', '//b/c.'), '/a/b/c.')
def test_prefix_root(self): assert paths._prefix_root('/a/', 'b/c') == '/a/b/c' assert paths._prefix_root('/a/b', 'c/d') == '/a/b/c/d' assert paths._prefix_root('/a', '/b/c') == '/a/b/c' assert paths._prefix_root('/a', '//b/c.') == '/a/b/c.'
def _create_async_inner(self, path, value, acl, flags, trailing=False): async_result = self.handler.async_result() self._call( Create(_prefix_root(self.chroot, path, trailing=trailing), value, acl, flags), async_result) return async_result
def _create_async_inner(self, path, value, acl, flags, trailing=False): async_result = self.handler.async_result() self._call(Create(_prefix_root(self.chroot, path, trailing=trailing), value, acl, flags), async_result) return async_result
def _reset_watchers(self): client = self._tree._client for _watchers in (client._data_watchers, client._child_watchers): _path = _prefix_root(client.chroot, self._path) _watcher = _watchers.get(_path, set()) _watcher.discard(self._process_watch)