示例#1
0
    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)
示例#2
0
    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
示例#3
0
 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
示例#4
0
 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