Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildbot/tox_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi

# Now install tox
if [ -z "`pip show tox`" ]; then
pip install tox
pip install -Iv tox=1.9.0
if [ -z "`pip show tox`" ]; then
echo "ERROR: Install of tox failed"
exit 1
Expand Down
8 changes: 4 additions & 4 deletions commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"""
distutils commands for riak-python-client
"""

__all__ = ['create_bucket_types', 'setup_security', 'enable_security',
'disable_security', 'preconfigure', 'configure']

from distutils import log
from distutils.core import Command
from distutils.errors import DistutilsOptionError
Expand All @@ -15,6 +11,10 @@
import os.path


__all__ = ['create_bucket_types', 'setup_security', 'enable_security',
'disable_security', 'preconfigure', 'configure']


# Exception classes used by this module.
class CalledProcessError(Exception):
"""This exception is raised when a process run by check_call() or
Expand Down
32 changes: 6 additions & 26 deletions riak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,18 @@
@author Jay Baird (@skatterbean) (jay@mochimedia.com)
"""

__all__ = ['RiakBucket', 'BucketType', 'RiakNode', 'RiakObject', 'RiakClient',
'RiakMapReduce', 'RiakKeyFilter', 'RiakLink', 'RiakError',
'ConflictError', 'ONE', 'ALL', 'QUORUM', 'key_filter']


class RiakError(Exception):
"""
Base class for exceptions generated in the Riak API.
"""
def __init__(self, value):
self.value = value

def __str__(self):
return repr(self.value)


class ConflictError(RiakError):
"""
Raised when an operation is attempted on a
:class:`~riak.riak_object.RiakObject` that has more than one
sibling.
"""
def __init__(self, message="Object in conflict"):
super(ConflictError, self).__init__(message)


from riak.riak_error import RiakError, ConflictError
from riak.client import RiakClient
from riak.bucket import RiakBucket, BucketType
from riak.node import RiakNode
from riak.riak_object import RiakObject
from riak.mapreduce import RiakKeyFilter, RiakMapReduce, RiakLink


__all__ = ['RiakBucket', 'BucketType', 'RiakNode', 'RiakObject', 'RiakClient',
'RiakMapReduce', 'RiakKeyFilter', 'RiakLink', 'RiakError',
'ConflictError', 'ONE', 'ALL', 'QUORUM', 'key_filter']

ONE = "one"
ALL = "all"
QUORUM = "quorum"
Expand Down
7 changes: 3 additions & 4 deletions riak/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from six import string_types, PY2
import mimetypes
from riak.util import lazy_property
from riak.datatypes import TYPES


def bucket_property(name, doc=None):
Expand Down Expand Up @@ -172,6 +173,7 @@ def new(self, key=None, data=None, content_type='application/json',
:class:`~riak.datatypes.Datatype`

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

Expand Down Expand Up @@ -217,6 +219,7 @@ def get(self, key, r=None, pr=None, timeout=None, include_context=None,
:class:`~riak.datatypes.Datatype`

"""
from riak import RiakObject
if self.bucket_type.datatype:
return self._client.fetch_datatype(self, key, r=r, pr=pr,
timeout=timeout,
Expand Down Expand Up @@ -736,7 +739,3 @@ def __ne__(self, other):
return hash(self) != hash(other)
else:
return True


from riak.riak_object import RiakObject
from riak.datatypes import TYPES
3 changes: 1 addition & 2 deletions riak/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from riak.security import SecurityCreds
from riak.util import lazy_property, bytes_to_str, str_to_bytes
from six import string_types, PY2
from riak.client.multiget import MultiGetPool


def default_encoder(obj):
Expand Down Expand Up @@ -371,5 +372,3 @@ def __ne__(self, other):
return hash(self) != hash(other)
else:
return True

from riak.client.multiget import MultiGetPool
37 changes: 29 additions & 8 deletions riak/client/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def get_buckets(self, transport, bucket_type=None, timeout=None):
"""
_validate_timeout(timeout)
if bucket_type:
bucketfn = lambda name: bucket_type.bucket(name)
bucketfn = self._bucket_type_bucket_builder
else:
bucketfn = lambda name: self.bucket(name)
bucketfn = self._default_type_bucket_builder

return [bucketfn(bytes_to_str(name)) for name in
return [bucketfn(bytes_to_str(name), bucket_type) for name in
transport.get_buckets(bucket_type=bucket_type,
timeout=timeout)]

Expand Down Expand Up @@ -103,9 +103,9 @@ def stream_buckets(self, bucket_type=None, timeout=None):
"""
_validate_timeout(timeout)
if bucket_type:
bucketfn = lambda name: bucket_type.bucket(name)
bucketfn = self._bucket_type_bucket_builder
else:
bucketfn = lambda name: self.bucket(name)
bucketfn = self._default_type_bucket_builder

resource = self._acquire()
transport = resource.object
Expand All @@ -114,7 +114,7 @@ def stream_buckets(self, bucket_type=None, timeout=None):
stream.attach(resource)
try:
for bucket_list in stream:
bucket_list = [bucketfn(bytes_to_str(name))
bucket_list = [bucketfn(bytes_to_str(name), bucket_type)
for name in bucket_list]
if len(bucket_list) > 0:
yield bucket_list
Expand Down Expand Up @@ -1000,6 +1000,27 @@ def update_datatype(self, datatype, w=None, dw=None, pw=None,
timeout=timeout,
include_context=include_context)

def _bucket_type_bucket_builder(self, name, bucket_type):
"""
Build a bucket from a bucket type

:param name: Bucket name
:param bucket_type: A bucket type
:return: A bucket object
"""
return bucket_type.bucket(name)

def _default_type_bucket_builder(self, name, unused):
"""
Build a bucket for the default bucket type

:param name: Default bucket name
:param unused: Unused
:return: A bucket object
"""
del unused # Ignored parameters.
return self.bucket(name)

@retryable
def _fetch_datatype(self, transport, bucket, key, r=None, pr=None,
basic_quorum=None, notfound_ok=None,
Expand Down Expand Up @@ -1052,6 +1073,6 @@ def _validate_timeout(timeout):
Raises an exception if the given timeout is an invalid value.
"""
if not (timeout is None or
((type(timeout) == int or (PY2 and type(timeout) == long))
and timeout > 0)):
((type(timeout) == int or (PY2 and type(timeout) == long)) and
timeout > 0)):
raise ValueError("timeout must be a positive integer")
22 changes: 18 additions & 4 deletions riak/datatypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#: A dict from :attr:`type names <Datatype.type_name>` to the
#: class that implements them. This is used inside :class:`Map` to
#: initialize new values.
TYPES = {}
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""

from .types import TYPES
from .datatype import Datatype
from .counter import Counter
from .flag import Flag
Expand Down
20 changes: 19 additions & 1 deletion riak/datatypes/counter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""

from riak.datatypes.datatype import Datatype
from riak.datatypes import TYPES


class Counter(Datatype):
Expand Down Expand Up @@ -57,5 +76,4 @@ def _check_type(self, new_value):
isinstance(new_value, long))


from riak.datatypes import TYPES
TYPES['counter'] = Counter
22 changes: 20 additions & 2 deletions riak/datatypes/datatype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""


from .errors import ContextRequired
from . import TYPES


class Datatype(object):
Expand Down Expand Up @@ -212,5 +232,3 @@ def _require_context(self):
"""
if not self._context:
raise ContextRequired()

from . import TYPES
4 changes: 2 additions & 2 deletions riak/datatypes/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class ContextRequired(RiakError):
"fetch the datatype first")

def __init__(self, message=None):
super(ContextRequired, self).__init__(message
or self._default_message)
super(ContextRequired, self).__init__(message or
self._default_message)
20 changes: 19 additions & 1 deletion riak/datatypes/flag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""

from riak.datatypes.datatype import Datatype
from riak.datatypes import TYPES


class Flag(Datatype):
Expand Down Expand Up @@ -49,5 +68,4 @@ def _check_type(self, new_value):
return isinstance(new_value, bool)


from riak.datatypes import TYPES
TYPES['flag'] = Flag
23 changes: 20 additions & 3 deletions riak/datatypes/map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""

from collections import Mapping
from riak.util import lazy_property
from .datatype import Datatype
from riak.datatypes import TYPES


class TypedMapView(Mapping):
Expand Down Expand Up @@ -238,8 +257,7 @@ def modified(self):
"""
Whether the map has staged local modifications.
"""
is_modified = lambda x: x.modified
values_modified = [is_modified(self._value[v]) for v in self._value]
values_modified = [self._value[v].modified for v in self._value]
modified = (any(values_modified) or self._removes or self._updates)
if modified:
return True
Expand Down Expand Up @@ -282,5 +300,4 @@ def _extract_updates(self, d):
yield ('update', key, d[key].to_op())


from riak.datatypes import TYPES
TYPES['map'] = Map
20 changes: 19 additions & 1 deletion riak/datatypes/register.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
"""
Copyright 2015 Basho Technologies, Inc.

This file is provided to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""

from collections import Sized
from riak.datatypes.datatype import Datatype
from six import string_types
from riak.datatypes import TYPES


class Register(Sized, Datatype):
Expand Down Expand Up @@ -61,5 +80,4 @@ def _check_type(self, new_value):
return isinstance(new_value, string_types)


from riak.datatypes import TYPES
TYPES['register'] = Register
Loading