Skip to content

Commit 3b44034

Browse files
author
Brett Hazen
committed
Fix all PEP8 warnings for CLIENTS-361
1 parent 2008ae1 commit 3b44034

Some content is hidden

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

41 files changed

+535
-164
lines changed

commands.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
"""
22
distutils commands for riak-python-client
33
"""
4-
5-
__all__ = ['create_bucket_types', 'setup_security', 'enable_security',
6-
'disable_security', 'preconfigure', 'configure']
7-
84
from distutils import log
95
from distutils.core import Command
106
from distutils.errors import DistutilsOptionError
@@ -15,6 +11,10 @@
1511
import os.path
1612

1713

14+
__all__ = ['create_bucket_types', 'setup_security', 'enable_security',
15+
'disable_security', 'preconfigure', 'configure']
16+
17+
1818
# Exception classes used by this module.
1919
class CalledProcessError(Exception):
2020
"""This exception is raised when a process run by check_call() or

riak/__init__.py

+6-26
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,18 @@
3030
@author Jay Baird (@skatterbean) ([email protected])
3131
"""
3232

33-
__all__ = ['RiakBucket', 'BucketType', 'RiakNode', 'RiakObject', 'RiakClient',
34-
'RiakMapReduce', 'RiakKeyFilter', 'RiakLink', 'RiakError',
35-
'ConflictError', 'ONE', 'ALL', 'QUORUM', 'key_filter']
36-
37-
38-
class RiakError(Exception):
39-
"""
40-
Base class for exceptions generated in the Riak API.
41-
"""
42-
def __init__(self, value):
43-
self.value = value
44-
45-
def __str__(self):
46-
return repr(self.value)
47-
48-
49-
class ConflictError(RiakError):
50-
"""
51-
Raised when an operation is attempted on a
52-
:class:`~riak.riak_object.RiakObject` that has more than one
53-
sibling.
54-
"""
55-
def __init__(self, message="Object in conflict"):
56-
super(ConflictError, self).__init__(message)
57-
58-
33+
from riak.riak_error import RiakError, ConflictError
5934
from riak.client import RiakClient
6035
from riak.bucket import RiakBucket, BucketType
6136
from riak.node import RiakNode
6237
from riak.riak_object import RiakObject
6338
from riak.mapreduce import RiakKeyFilter, RiakMapReduce, RiakLink
6439

40+
41+
__all__ = ['RiakBucket', 'BucketType', 'RiakNode', 'RiakObject', 'RiakClient',
42+
'RiakMapReduce', 'RiakKeyFilter', 'RiakLink', 'RiakError',
43+
'ConflictError', 'ONE', 'ALL', 'QUORUM', 'key_filter']
44+
6545
ONE = "one"
6646
ALL = "all"
6747
QUORUM = "quorum"

riak/bucket.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from six import string_types, PY2
2121
import mimetypes
2222
from riak.util import lazy_property
23+
from riak.datatypes import TYPES
2324

2425

2526
def bucket_property(name, doc=None):
@@ -172,6 +173,7 @@ def new(self, key=None, data=None, content_type='application/json',
172173
:class:`~riak.datatypes.Datatype`
173174
174175
"""
176+
from riak import RiakObject
175177
if self.bucket_type.datatype:
176178
return TYPES[self.bucket_type.datatype](bucket=self, key=key)
177179

@@ -217,6 +219,7 @@ def get(self, key, r=None, pr=None, timeout=None, include_context=None,
217219
:class:`~riak.datatypes.Datatype`
218220
219221
"""
222+
from riak import RiakObject
220223
if self.bucket_type.datatype:
221224
return self._client.fetch_datatype(self, key, r=r, pr=pr,
222225
timeout=timeout,
@@ -736,7 +739,3 @@ def __ne__(self, other):
736739
return hash(self) != hash(other)
737740
else:
738741
return True
739-
740-
741-
from riak.riak_object import RiakObject
742-
from riak.datatypes import TYPES

riak/client/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from riak.security import SecurityCreds
3737
from riak.util import lazy_property, bytes_to_str, str_to_bytes
3838
from six import string_types, PY2
39+
from riak.client.multiget import MultiGetPool
3940

4041

4142
def default_encoder(obj):
@@ -371,5 +372,3 @@ def __ne__(self, other):
371372
return hash(self) != hash(other)
372373
else:
373374
return True
374-
375-
from riak.client.multiget import MultiGetPool

riak/client/operations.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def get_buckets(self, transport, bucket_type=None, timeout=None):
5858
"""
5959
_validate_timeout(timeout)
6060
if bucket_type:
61-
bucketfn = lambda name: bucket_type.bucket(name)
61+
bucketfn = self._bucket_type_bucket_builder
6262
else:
63-
bucketfn = lambda name: self.bucket(name)
63+
bucketfn = self._default_type_bucket_builder
6464

65-
return [bucketfn(bytes_to_str(name)) for name in
65+
return [bucketfn(bytes_to_str(name), bucket_type) for name in
6666
transport.get_buckets(bucket_type=bucket_type,
6767
timeout=timeout)]
6868

@@ -103,9 +103,9 @@ def stream_buckets(self, bucket_type=None, timeout=None):
103103
"""
104104
_validate_timeout(timeout)
105105
if bucket_type:
106-
bucketfn = lambda name: bucket_type.bucket(name)
106+
bucketfn = self._bucket_type_bucket_builder
107107
else:
108-
bucketfn = lambda name: self.bucket(name)
108+
bucketfn = self._default_type_bucket_builder
109109

110110
resource = self._acquire()
111111
transport = resource.object
@@ -114,7 +114,7 @@ def stream_buckets(self, bucket_type=None, timeout=None):
114114
stream.attach(resource)
115115
try:
116116
for bucket_list in stream:
117-
bucket_list = [bucketfn(bytes_to_str(name))
117+
bucket_list = [bucketfn(bytes_to_str(name), bucket_type)
118118
for name in bucket_list]
119119
if len(bucket_list) > 0:
120120
yield bucket_list
@@ -1000,6 +1000,27 @@ def update_datatype(self, datatype, w=None, dw=None, pw=None,
10001000
timeout=timeout,
10011001
include_context=include_context)
10021002

1003+
def _bucket_type_bucket_builder(self, name, bucket_type):
1004+
"""
1005+
Build a bucket from a bucket type
1006+
1007+
:param name: Bucket name
1008+
:param bucket_type: A bucket type
1009+
:return: A bucket object
1010+
"""
1011+
return bucket_type.bucket(name)
1012+
1013+
def _default_type_bucket_builder(self, name, unused):
1014+
"""
1015+
Build a bucket for the default bucket type
1016+
1017+
:param name: Default bucket name
1018+
:param unused: Unused
1019+
:return: A bucket object
1020+
"""
1021+
del unused # Ignored parameters.
1022+
return self.bucket(name)
1023+
10031024
@retryable
10041025
def _fetch_datatype(self, transport, bucket, key, r=None, pr=None,
10051026
basic_quorum=None, notfound_ok=None,
@@ -1052,6 +1073,6 @@ def _validate_timeout(timeout):
10521073
Raises an exception if the given timeout is an invalid value.
10531074
"""
10541075
if not (timeout is None or
1055-
((type(timeout) == int or (PY2 and type(timeout) == long))
1056-
and timeout > 0)):
1076+
((type(timeout) == int or (PY2 and type(timeout) == long)) and
1077+
timeout > 0)):
10571078
raise ValueError("timeout must be a positive integer")

riak/datatypes/__init__.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
#: A dict from :attr:`type names <Datatype.type_name>` to the
2-
#: class that implements them. This is used inside :class:`Map` to
3-
#: initialize new values.
4-
TYPES = {}
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
53
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
19+
from .types import TYPES
620
from .datatype import Datatype
721
from .counter import Counter
822
from .flag import Flag

riak/datatypes/counter.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
119
from riak.datatypes.datatype import Datatype
20+
from riak.datatypes import TYPES
221

322

423
class Counter(Datatype):
@@ -57,5 +76,4 @@ def _check_type(self, new_value):
5776
isinstance(new_value, long))
5877

5978

60-
from riak.datatypes import TYPES
6179
TYPES['counter'] = Counter

riak/datatypes/datatype.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
19+
120
from .errors import ContextRequired
21+
from . import TYPES
222

323

424
class Datatype(object):
@@ -212,5 +232,3 @@ def _require_context(self):
212232
"""
213233
if not self._context:
214234
raise ContextRequired()
215-
216-
from . import TYPES

riak/datatypes/errors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ class ContextRequired(RiakError):
1212
"fetch the datatype first")
1313

1414
def __init__(self, message=None):
15-
super(ContextRequired, self).__init__(message
16-
or self._default_message)
15+
super(ContextRequired, self).__init__(message or
16+
self._default_message)

riak/datatypes/flag.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
119
from riak.datatypes.datatype import Datatype
20+
from riak.datatypes import TYPES
221

322

423
class Flag(Datatype):
@@ -49,5 +68,4 @@ def _check_type(self, new_value):
4968
return isinstance(new_value, bool)
5069

5170

52-
from riak.datatypes import TYPES
5371
TYPES['flag'] = Flag

riak/datatypes/map.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
119
from collections import Mapping
220
from riak.util import lazy_property
321
from .datatype import Datatype
22+
from riak.datatypes import TYPES
423

524

625
class TypedMapView(Mapping):
@@ -238,8 +257,7 @@ def modified(self):
238257
"""
239258
Whether the map has staged local modifications.
240259
"""
241-
is_modified = lambda x: x.modified
242-
values_modified = [is_modified(self._value[v]) for v in self._value]
260+
values_modified = [self._value[v].modified for v in self._value]
243261
modified = (any(values_modified) or self._removes or self._updates)
244262
if modified:
245263
return True
@@ -282,5 +300,4 @@ def _extract_updates(self, d):
282300
yield ('update', key, d[key].to_op())
283301

284302

285-
from riak.datatypes import TYPES
286303
TYPES['map'] = Map

riak/datatypes/register.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
"""
2+
Copyright 2015 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
119
from collections import Sized
220
from riak.datatypes.datatype import Datatype
321
from six import string_types
22+
from riak.datatypes import TYPES
423

524

625
class Register(Sized, Datatype):
@@ -61,5 +80,4 @@ def _check_type(self, new_value):
6180
return isinstance(new_value, string_types)
6281

6382

64-
from riak.datatypes import TYPES
6583
TYPES['register'] = Register

0 commit comments

Comments
 (0)