Skip to content

Commit 1b0c0a0

Browse files
committed
Merge branch 'master' into pevm-unittest-determinism
2 parents 5fbbfbb + 7f90308 commit 1b0c0a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3879
-2456
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ language: python
22
python:
33
- "2.6"
44
- "2.7"
5-
install: ./setup.py develop
5+
install:
6+
- ./setup.py develop
7+
- ./setup.py easy_install protobuf
68
script: ./setup.py test
79
before_script: sudo /usr/sbin/search-cmd install searchbucket
810
notifications:

riak/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
3232

3333

3434
class RiakError(Exception):
35+
"""
36+
Base class for exceptions generated in the Riak API.
37+
"""
3538
def __init__(self, value):
3639
self.value = value
3740

3841
def __str__(self):
3942
return repr(self.value)
4043

41-
from riak_object import RiakObject
42-
from bucket import RiakBucket
43-
from client import RiakClient
44-
from mapreduce import RiakMapReduce, RiakMapReducePhase, RiakLinkPhase,\
45-
RiakKeyFilter
46-
from transports.pbc import RiakPbcTransport
47-
from transports.http import RiakHttpTransport
44+
from mapreduce import RiakKeyFilter
4845

4946
ONE = "one"
5047
ALL = "all"

riak/bucket.py

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ def __init__(self, client, name):
5656
self._encoders = {}
5757
self._decoders = {}
5858

59+
def __hash__(self):
60+
return hash((self.name, self._client))
61+
62+
def __eq__(self, other):
63+
if isinstance(other, self.__class__):
64+
return hash(self) == hash(other)
65+
else:
66+
return False
67+
68+
def __nq__(self, other):
69+
if isinstance(other, self.__class__):
70+
return hash(self) != hash(other)
71+
else:
72+
return True
73+
5974
def get_encoder(self, content_type):
6075
"""
6176
Get the encoding function for the provided content type for
@@ -125,8 +140,8 @@ def new(self, key=None, data=None, content_type='application/json'):
125140
raise TypeError('Unicode data values are not supported.')
126141

127142
obj = RiakObject(self._client, self, key)
128-
obj.set_data(data)
129-
obj.set_content_type(content_type)
143+
obj.data = data
144+
obj.content_type = content_type
130145
obj._encode_data = True
131146
return obj
132147

@@ -146,8 +161,8 @@ def new_binary(self, key, data, content_type='application/octet-stream'):
146161
:rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
147162
"""
148163
obj = RiakObject(self._client, self, key)
149-
obj.set_data(data)
150-
obj.set_content_type(content_type)
164+
obj.data = data
165+
obj.content_type = content_type
151166
obj._encode_data = False
152167
return obj
153168

@@ -222,56 +237,76 @@ def _set_r(self, val):
222237
def _get_r(self):
223238
return self.get_property('r')
224239

225-
r = property(_get_r, _set_r)
240+
r = property(_get_r, _set_r, doc="""
241+
The default 'read' quorum for this bucket (how many replicas must
242+
reply for a successful read). This should be an integer less than
243+
the 'n_val' property, or a string of 'one', 'quorum', 'all', or
244+
'default'""")
226245

227246
def _set_pr(self, val):
228247
return self.set_property('pr', val)
229248

230249
def _get_pr(self):
231250
return self.get_property('pr')
232251

233-
pr = property(_get_pr, _set_pr)
252+
pr = property(_get_pr, _set_pr, doc="""
253+
The default 'primary read' quorum for this bucket (how many
254+
primary replicas are required for a successful read). This should
255+
be an integer less than the 'n_val' property, or a string of
256+
'one', 'quorum', 'all', or 'default'""")
234257

235258
def _set_rw(self, val):
236259
return self.set_property('rw', val)
237260

238261
def _get_rw(self):
239262
return self.get_property('rw')
240263

241-
rw = property(_get_rw, _set_rw)
264+
rw = property(_get_rw, _set_rw, doc="""
265+
The default 'read' and 'write' quorum for this bucket (equivalent
266+
to 'r' and 'w' but for deletes). This should be an integer less
267+
than the 'n_val' property, or a string of 'one', 'quorum', 'all',
268+
or 'default'""")
242269

243270
def _set_w(self, val):
244271
return self.set_property('w', val)
245272

246273
def _get_w(self):
247274
return self.get_property('w')
248275

249-
w = property(_get_w, _set_w)
276+
w = property(_get_w, _set_w, doc="""
277+
The default 'write' quorum for this bucket (how many replicas must
278+
acknowledge receipt of a write). This should be an integer less
279+
than the 'n_val' property, or a string of 'one', 'quorum', 'all',
280+
or 'default'""")
250281

251282
def _set_dw(self, val):
252283
return self.set_property('dw', val)
253284

254285
def _get_dw(self):
255286
return self.get_property('dw')
256287

257-
dw = property(_get_dw, _set_dw)
288+
dw = property(_get_dw, _set_dw, doc="""
289+
The default 'durable write' quorum for this bucket (how many
290+
replicas must commit the write). This should be an integer less
291+
than the 'n_val' property, or a string of 'one', 'quorum', 'all',
292+
or 'default'""")
258293

259294
def _set_pw(self, val):
260295
return self.set_property('pw', val)
261296

262297
def _get_pw(self):
263298
return self.get_property('pw')
264299

265-
pw = property(_get_pw, _set_pw)
300+
pw = property(_get_pw, _set_pw, doc="""
301+
The default 'primary write' quorum for this bucket (how many
302+
primary replicas are required for a successful write). This should
303+
be an integer less than the 'n_val' property, or a string of
304+
'one', 'quorum', 'all', or 'default'""")
266305

267306
def set_property(self, key, value):
268307
"""
269308
Set a bucket property.
270309
271-
.. warning::
272-
273-
This should only be used if you know what you are doing.
274-
275310
:param key: Property to set.
276311
:type key: string
277312
:param value: Property value.
@@ -296,24 +331,18 @@ def set_properties(self, props):
296331
"""
297332
Set multiple bucket properties in one call.
298333
299-
.. warning::
300-
301-
This should only be used if you know what you are doing.
302-
303-
:param props: An associative array of key:value.
304-
:type props: array
334+
:param props: A dictionary of properties
335+
:type props: dict
305336
"""
306-
t = self._client.get_transport()
307-
t.set_bucket_props(self, props)
337+
self._client.set_bucket_props(self, props)
308338

309339
def get_properties(self):
310340
"""
311-
Retrieve an associative array of all bucket properties.
341+
Retrieve a dict of all bucket properties.
312342
313-
:rtype: array
343+
:rtype: dict
314344
"""
315-
t = self._client.get_transport()
316-
return t.get_bucket_props(self)
345+
return self._client.get_bucket_props(self)
317346

318347
def get_keys(self):
319348
"""
@@ -323,7 +352,19 @@ def get_keys(self):
323352
324353
At current, this is a very expensive operation. Use with caution.
325354
"""
326-
return self._client.get_transport().get_keys(self)
355+
return self._client.get_keys(self)
356+
357+
def stream_keys(self):
358+
"""
359+
Streams all keys within the bucket through an iterator.
360+
361+
.. warning::
362+
363+
At current, this is a very expensive operation. Use with caution.
364+
365+
:rtype: iterator
366+
"""
367+
return self._client.stream_keys(self)
327368

328369
def new_binary_from_file(self, key, filename):
329370
"""
@@ -332,6 +373,10 @@ def new_binary_from_file(self, key, filename):
332373
"""
333374
binary_data = open(filename, "rb").read()
334375
mimetype, encoding = mimetypes.guess_type(filename)
376+
if encoding:
377+
binary_data = bytearray(binary_data, encoding)
378+
else:
379+
binary_data = bytearray(binary_data)
335380
if not mimetype:
336381
mimetype = 'application/octet-stream'
337382
return self.new_binary(key, binary_data, mimetype)
@@ -371,11 +416,13 @@ def search(self, query, **params):
371416
"""
372417
Queries a search index over objects in this bucket/index.
373418
"""
374-
return self._client.solr().search(self.name, query, **params)
419+
return self._client.solr.search(self.name, query, **params)
375420

376421
def get_index(self, index, startkey, endkey=None):
377422
"""
378423
Queries a secondary index over objects in this bucket, returning keys.
379424
"""
380-
return self._client._transport.get_index(self.name, index, startkey,
381-
endkey)
425+
return self._client.get_index(self.name, index, startkey, endkey)
426+
427+
def __str__(self):
428+
return '<RiakBucket "{0}">'.format(self.name)

0 commit comments

Comments
 (0)