コード例 #1
0
    def new(self,
            key=None,
            data=None,
            content_type='application/json',
            encoded_data=None):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>`
        that will be stored as JSON. A shortcut for manually
        instantiating a :class:`RiakObject
        <riak.riak_object.RiakObject>`.

        :param key: Name of the key. Leaving this to be None (default)
                    will make Riak generate the key on store.
        :type key: string
        :param data: The data to store.
        :type data: object
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        try:
            if isinstance(data, basestring):
                data = data.encode('ascii')
        except UnicodeError:
            raise TypeError('Unicode data values are not supported.')

        obj = RiakObject(self._client, self, key)
        obj.content_type = content_type
        if data is not None:
            obj.data = data
        if encoded_data is not None:
            obj.encoded_data = encoded_data
        return obj
コード例 #2
0
    def new(self, key=None, data=None, content_type='application/json',
            encoded_data=None):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>`
        that will be stored as JSON. A shortcut for manually
        instantiating a :class:`RiakObject
        <riak.riak_object.RiakObject>`.

        :param key: Name of the key. Leaving this to be None (default)
                    will make Riak generate the key on store.
        :type key: string
        :param data: The data to store.
        :type data: object
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        try:
            if isinstance(data, basestring):
                data = data.encode('ascii')
        except UnicodeError:
            raise TypeError('Unicode data values are not supported.')

        obj = RiakObject(self._client, self, key)
        obj.content_type = content_type
        if data is not None:
            obj.data = data
        if encoded_data is not None:
            obj.encoded_data = encoded_data
        return obj
コード例 #3
0
    def get(self, key, r=None, pr=None, timeout=None, include_context=None,
            basic_quorum=None, notfound_ok=None):
        """
        Retrieve an object or datatype from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :param include_context: if the bucket contains datatypes, include
           the opaque context in the result
        :type include_context: bool
        :param basic_quorum: whether to use the "basic quorum" policy
           for not-founds
        :type basic_quorum: bool
        :param notfound_ok: whether to treat not-found responses as successful
        :type notfound_ok: bool
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>` or
           :class:`~riak.datatypes.Datatype`
        """
        if self.bucket_type.datatype:
            return self._client.fetch_datatype(self, key, r=r, pr=pr,
                                               timeout=timeout,
                                               include_context=include_context,
                                               basic_quorum=basic_quorum,
                                               notfound_ok=notfound_ok)
        else:
            obj = RiakObject(self._client, self, key)
            return obj.reload(r=r, pr=pr, timeout=timeout,
                              basic_quorum=basic_quorum,
                              notfound_ok=notfound_ok)
コード例 #4
0
 def get_binary(self, key, r=None):
     """
     Retrieve a binary/string object from Riak.
     @param string key - Name of the key.
     @param int r - R-Value of the request (defaults to bucket's R)
     @return RiakObject
     """
     obj = RiakObject(self._client, self, key)
     obj._encode_data = False
     r = self.get_r(r)
     return obj.reload(r)
コード例 #5
0
ファイル: bucket.py プロジェクト: pigmej/riak-python-client
    def new(self,
            key=None,
            data=None,
            content_type='application/json',
            encoded_data=None):
        """A shortcut for manually instantiating a new
        :class:`~riak.riak_object.RiakObject` or a new
        :class:`~riak.datatypes.Datatype`, based on the presence and value
        of the :attr:`datatype <BucketType.datatype>` bucket property. When
        the bucket contains a :class:`~riak.datatypes.Datatype`, all
        arguments are ignored except ``key``, otherwise they are used to
        initialize the :class:`~riak.riak_object.RiakObject`.

        :param key: Name of the key. Leaving this to be None (default)
                    will make Riak generate the key on store.
        :type key: str
        :param data: The data to store in a
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.data <riak.riak_object.RiakObject.data>`.
        :type data: object
        :param content_type: The media type of the data stored in the
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.content_type
           <riak.riak_object.RiakObject.content_type>`.
        :type content_type: str
        :param encoded_data: The encoded data to store in a
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.encoded_data
           <riak.riak_object.RiakObject.encoded_data>`.
        :type encoded_data: str
        :rtype: :class:`~riak.riak_object.RiakObject` or
                :class:`~riak.datatypes.Datatype`

        """
        if self.bucket_type.datatype:
            return TYPES[self.bucket_type.datatype](bucket=self, key=key)

        try:
            if isinstance(data, basestring):
                data = data.encode('ascii')
        except UnicodeError:
            raise TypeError('Unicode data values are not supported.')

        obj = RiakObject(self._client, self, key)
        obj.content_type = content_type
        if data is not None:
            obj.data = data
        if encoded_data is not None:
            obj.encoded_data = encoded_data
        return obj
コード例 #6
0
ファイル: bucket.py プロジェクト: sa2ajj/riak-python-client
    def get_binary(self, key, r=None):
        """
        Retrieve a binary/string object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj._encode_data = False
        r = self.get_r(r)
        return obj.reload(r)
コード例 #7
0
ファイル: bucket.py プロジェクト: Atilla/riak-python-client
    def get(self, key, r=None, pr=None):
        """
        Retrieve a JSON-encoded object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        return obj.reload(r=r, pr=pr)
コード例 #8
0
    def get_binary(self, key, r=None):
        """
        Retrieve a binary/string object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj._encode_data = False
        r = self.get_r(r)
        return obj.reload(r)
コード例 #9
0
    def get(self, key, r=None, pr=None):
        """
        Retrieve a JSON-encoded object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        return obj.reload(r=r, pr=pr)
コード例 #10
0
ファイル: bucket.py プロジェクト: pigmej/riak-python-client
    def get(self,
            key,
            r=None,
            pr=None,
            timeout=None,
            include_context=None,
            basic_quorum=None,
            notfound_ok=None):
        """
        Retrieve an :class:`~riak.riak_object.RiakObject` or
        :class:`~riak.datatypes.Datatype`, based on the presence and value
        of the :attr:`datatype <BucketType.datatype>` bucket property.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :param include_context: if the bucket contains datatypes, include
           the opaque context in the result
        :type include_context: bool
        :param basic_quorum: whether to use the "basic quorum" policy
           for not-founds
        :type basic_quorum: bool
        :param notfound_ok: whether to treat not-found responses as successful
        :type notfound_ok: bool
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>` or
           :class:`~riak.datatypes.Datatype`

        """
        if self.bucket_type.datatype:
            return self._client.fetch_datatype(self,
                                               key,
                                               r=r,
                                               pr=pr,
                                               timeout=timeout,
                                               include_context=include_context,
                                               basic_quorum=basic_quorum,
                                               notfound_ok=notfound_ok)
        else:
            obj = RiakObject(self._client, self, key)
            return obj.reload(r=r,
                              pr=pr,
                              timeout=timeout,
                              basic_quorum=basic_quorum,
                              notfound_ok=notfound_ok)
コード例 #11
0
    def get(self, key, r=None, pr=None, timeout=None):
        """
        Retrieve an object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        return obj.reload(r=r, pr=pr, timeout=timeout)
コード例 #12
0
    def get(self, key, r=None, pr=None, timeout=None):
        """
        Retrieve an object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        return obj.reload(r=r, pr=pr, timeout=timeout)
コード例 #13
0
    def new_binary(self, key, data, content_type='application/octet-stream'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>`
        that will be stored as plain text/binary. A shortcut for
        manually instantiating a :class:`RiakObject
        <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :param content_type: The content type of the object.
        :type content_type: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj.data = data
        obj.content_type = content_type
        obj._encode_data = False
        return obj
コード例 #14
0
 def new(self, key, data=None, content_type='application/json'):
     """
     Create a new Riak object that will be stored as JSON.
     @param string key - Name of the key.
     @param object data - The data to store. (default None)
     @return RiakObject
     """
     obj = RiakObject(self._client, self, key)
     obj.set_data(data)
     obj.set_content_type(content_type)
     obj._encode_data = True
     return obj
コード例 #15
0
    def new(self, key, data=None, content_type='application/json'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>` that will be stored as JSON. A shortcut for
        manually instantiating a :class:`RiakObject <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj.set_data(data)
        obj.set_content_type(content_type)
        obj._encode_data = True
        return obj
コード例 #16
0
 def new_binary(self, key, data, content_type='application/octet-stream'):
     """
     Create a new Riak object that will be stored as plain text/binary.
     @param string key - Name of the key.
     @param object data - The data to store.
     @param string content_type - The content type of the object.
            (default 'application/octet-stream')
     @return RiakObject
     """
     obj = RiakObject(self._client, self, key)
     obj.set_data(data)
     obj.set_content_type(content_type)
     obj._encode_data = False
     return obj
コード例 #17
0
ファイル: bucket.py プロジェクト: pipoket/riak-python-client
    def new_binary(self, key, data, content_type='application/octet-stream'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>` that will be stored as plain text/binary.
        A shortcut for manually instantiating a :class:`RiakObject <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :param content_type: The content type of the object.
        :type content_type: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj.set_data(data)
        obj.set_content_type(content_type)
        obj._encode_data = False
        return obj
コード例 #18
0
    def new(self, key, data=None, content_type='application/json'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>` that will be stored as JSON. A shortcut for
        manually instantiating a :class:`RiakObject <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        obj = RiakObject(self._client, self, key)
        obj.set_data(data)
        obj.set_content_type(content_type)
        obj._encode_data = True
        return obj
コード例 #19
0
ファイル: bucket.py プロジェクト: semk/riak-python-client
    def new(self, key, data=None, content_type="application/json"):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>` that will be stored as JSON. A shortcut for
        manually instantiating a :class:`RiakObject <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        try:
            if isinstance(data, basestring):
                data = data.encode("ascii")
        except UnicodeError:
            raise TypeError("Unicode data values are not supported.")

        obj = RiakObject(self._client, self, key)
        obj.set_data(data)
        obj.set_content_type(content_type)
        obj._encode_data = True
        return obj