Skip to content

Commit 82992ea

Browse files
committed
Adds pylint to tox. Fixes many pylint errors. Many more to go.
1 parent 3d78714 commit 82992ea

17 files changed

Lines changed: 159 additions & 105 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ env:
77
- TOX_ENV=py33
88
- TOX_ENV=pypy
99
- TOX_ENV=pep8
10+
- TOX_ENV=pylint
1011
install: pip install tox --use-mirrors
1112
script: tox -e $TOX_ENV

SoftLayer/API.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def authenticate_with_password(self, username, password,
9595
security_question_id,
9696
security_question_answer)
9797
self.auth = TokenAuthentication(res['userId'], res['hash'])
98-
return (res['userId'], res['hash'])
98+
return res['userId'], res['hash']
9999

100100
def __getitem__(self, name):
101101
""" Get a SoftLayer Service.
@@ -116,8 +116,8 @@ def call(self, service, method, *args, **kwargs):
116116
117117
:param service: the name of the SoftLayer API service
118118
:param method: the method to call on the service
119-
:param \*args: same optional arguments that ``Service.call`` takes
120-
:param \*\*kwargs: same optional keyword arguments that
119+
:param \\*args: same optional arguments that ``Service.call`` takes
120+
:param \\*\\*kwargs: same optional keyword arguments that
121121
``Service.call`` takes
122122
123123
:param service: the name of the SoftLayer API service
@@ -140,44 +140,38 @@ def call(self, service, method, *args, **kwargs):
140140
if not service.startswith(self._prefix):
141141
service = self._prefix + service
142142

143-
objectid = kwargs.get('id')
144-
objectmask = kwargs.get('mask')
145-
objectfilter = kwargs.get('filter')
146143
headers = kwargs.get('headers', {})
147-
compress = kwargs.get('compress', True)
148-
raw_headers = kwargs.get('raw_headers')
149-
limit = kwargs.get('limit')
150-
offset = kwargs.get('offset', 0)
151144

152145
if self.auth:
153146
headers.update(self.auth.get_headers())
154147

155-
if objectid is not None:
156-
headers[service + 'InitParameters'] = {'id': objectid}
148+
if kwargs.get('id') is not None:
149+
headers[service + 'InitParameters'] = {'id': kwargs.get('id')}
157150

158-
if objectmask is not None:
159-
headers.update(self.__format_object_mask(objectmask, service))
151+
if kwargs.get('mask') is not None:
152+
headers.update(self.__format_object_mask(kwargs.get('mask'),
153+
service))
160154

161-
if objectfilter is not None:
162-
headers['%sObjectFilter' % service] = objectfilter
155+
if kwargs.get('filter') is not None:
156+
headers['%sObjectFilter' % service] = kwargs.get('filter')
163157

164-
if limit:
158+
if kwargs.get('limit'):
165159
headers['resultLimit'] = {
166-
'limit': limit,
167-
'offset': offset,
160+
'limit': kwargs.get('limit'),
161+
'offset': kwargs.get('offset', 0),
168162
}
169163

170164
http_headers = {
171165
'User-Agent': USER_AGENT,
172166
'Content-Type': 'application/xml',
173167
}
174168

175-
if compress:
169+
if kwargs.get('compress', True):
176170
http_headers['Accept'] = '*/*'
177171
http_headers['Accept-Encoding'] = 'gzip, deflate, compress'
178172

179-
if raw_headers:
180-
http_headers.update(raw_headers)
173+
if kwargs.get('raw_headers'):
174+
http_headers.update(kwargs.get('raw_headers'))
181175

182176
uri = '/'.join([self.endpoint_url, service])
183177
return make_xml_rpc_api_call(uri, method, args,
@@ -195,8 +189,8 @@ def iter_call(self, service, method,
195189
:param service: the name of the SoftLayer API service
196190
:param method: the method to call on the service
197191
:param integer chunk: result size for each API call
198-
:param \*args: same optional arguments that ``Service.call`` takes
199-
:param \*\*kwargs: same optional keyword arguments that
192+
:param \\*args: same optional arguments that ``Service.call`` takes
193+
:param \\*\\*kwargs: same optional keyword arguments that
200194
``Service.call`` takes
201195
202196
"""
@@ -302,6 +296,11 @@ def get_last_calls(self):
302296

303297

304298
class Service(object):
299+
""" A SoftLayer Service.
300+
:param client: A SoftLayer.API.Client instance
301+
:param name str: The service name
302+
303+
"""
305304
def __init__(self, client, name):
306305
self.client = client
307306
self.name = name
@@ -310,7 +309,7 @@ def call(self, name, *args, **kwargs):
310309
""" Make a SoftLayer API call
311310
312311
:param method: the method to call on the service
313-
:param \*args: (optional) arguments for the remote call
312+
:param \\*args: (optional) arguments for the remote call
314313
:param id: (optional) id for the resource
315314
:param mask: (optional) object mask
316315
:param dict filter: (optional) filter dict
@@ -338,8 +337,8 @@ def iter_call(self, name, *args, **kwargs):
338337
339338
:param method: the method to call on the service
340339
:param integer chunk: result size for each API call
341-
:param \*args: same optional arguments that ``Service.call`` takes
342-
:param \*\*kwargs: same optional keyword arguments that
340+
:param \\*args: same optional arguments that ``Service.call`` takes
341+
:param \\*\\*kwargs: same optional keyword arguments that
343342
``Service.call`` takes
344343
345344
Usage:
@@ -360,6 +359,7 @@ def __getattr__(self, name):
360359
raise AttributeError("'Obj' object has no attribute '%s'" % name)
361360

362361
def call_handler(*args, **kwargs):
362+
" Handler that actually makes the API call "
363363
return self(name, *args, **kwargs)
364364
return call_handler
365365

SoftLayer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
:license: MIT, see LICENSE for more details.
1515
"""
16+
# pylint: disable=w0401
1617
from SoftLayer.consts import VERSION
1718

1819
from .API import * # NOQA

SoftLayer/auth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@
99

1010

1111
class AuthenticationBase(object):
12+
""" A base authentication class intended to be overridden """
1213
def get_headers(self):
14+
""" Return a dictionary of XML-RPC headers to be inserted for
15+
authentication """
1316
raise NotImplementedError
1417

1518

1619
class TokenAuthentication(AuthenticationBase):
20+
""" Token-based authentication class.
21+
22+
:param user_id int: a user's id
23+
:param auth_token str: a user's auth token, attained through
24+
User_Customer::getPortalLoginToken
25+
"""
1726
def __init__(self, user_id, auth_token):
1827
self.user_id = user_id
1928
self.auth_token = auth_token
2029

2130
def get_headers(self):
31+
""" Returns token-based auth headers """
2232
return {
2333
'authenticate': {
2434
'complexType': 'PortalLoginToken',
@@ -32,11 +42,17 @@ def __repr__(self):
3242

3343

3444
class BasicAuthentication(AuthenticationBase):
45+
""" Token-based authentication class.
46+
47+
:param username str: a user's username
48+
:param api_key str: a user's API key
49+
"""
3550
def __init__(self, username, api_key):
3651
self.username = username
3752
self.api_key = api_key
3853

3954
def get_headers(self):
55+
""" Returns token-based auth headers """
4056
return {
4157
'authenticate': {
4258
'username': self.username,

SoftLayer/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def get_client_settings_args(**kwargs):
1616
""" Retreive client settings from user-supplied arguments
1717
18-
:param \*\*kwargs: Arguments that are passed into the client instance
18+
:param \\*\\*kwargs: Arguments that are passed into the client instance
1919
"""
2020
settings = {
2121
'endpoint_url': kwargs.get('endpoint_url'),
@@ -33,7 +33,7 @@ def get_client_settings_args(**kwargs):
3333
def get_client_settings_env(**_):
3434
""" Retreive client settings from environment settings
3535
36-
:param \*\*kwargs: Arguments that are passed into the client instance
36+
:param \\*\\*kwargs: Arguments that are passed into the client instance
3737
"""
3838
username = os.environ.get('SL_USERNAME')
3939
api_key = os.environ.get('SL_API_KEY')
@@ -48,7 +48,7 @@ def get_client_settings_env(**_):
4848
def get_client_settings_config_file(**kwargs):
4949
""" Retreive client settings from the possible config file locations
5050
51-
:param \*\*kwargs: Arguments that are passed into the client instance
51+
:param \\*\\*kwargs: Arguments that are passed into the client instance
5252
"""
5353
config_files = ['/etc/softlayer.conf', '~/.softlayer']
5454
if kwargs.get('config_file'):
@@ -77,7 +77,7 @@ def get_client_settings_config_file(**kwargs):
7777
settings['auth'] = BasicAuthentication(username, api_key)
7878
return settings
7979

80-
setting_resolvers = [get_client_settings_args,
80+
SETTING_RESOLVERS = [get_client_settings_args,
8181
get_client_settings_env,
8282
get_client_settings_config_file]
8383

@@ -88,10 +88,10 @@ def get_client_settings(**kwargs):
8888
settings. The settings currently come from explicit user arguments,
8989
environmental variables and config files.
9090
91-
:param \*\*kwargs: Arguments that are passed into the client instance
91+
:param \\*\\*kwargs: Arguments that are passed into the client instance
9292
"""
9393
all_settings = {}
94-
for setting_method in setting_resolvers:
94+
for setting_method in SETTING_RESOLVERS:
9595
settings = setting_method(**kwargs)
9696
if settings:
9797
settings.update((k, v) for k, v in all_settings.items() if v)

SoftLayer/exceptions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class SoftLayerAPIError(SoftLayerError):
2323
"""
2424
def __init__(self, faultCode, faultString, *args):
2525
SoftLayerError.__init__(self, faultString, *args)
26-
self.faultCode = faultCode
27-
self.reason = self.faultString = faultString
26+
self.faultCode = faultCode # pylint: disable=C0103
27+
self.reason = self.faultString = faultString # pylint: disable=C0103
2828

2929
def __repr__(self):
3030
return '<%s(%s): %s>' % \
@@ -55,33 +55,42 @@ class TransportError(SoftLayerAPIError):
5555
" Transport Error "
5656

5757

58+
# XMLRPC Errors
5859
class NotWellFormed(ParseError):
60+
" Request was not well formed "
5961
pass
6062

6163

6264
class UnsupportedEncoding(ParseError):
65+
" Encoding not supported "
6366
pass
6467

6568

6669
class InvalidCharacter(ParseError):
70+
" There was an invalid character "
6771
pass
6872

6973

7074
class SpecViolation(ServerError):
75+
" There was a spec violation "
7176
pass
7277

7378

7479
class MethodNotFound(ServerError):
80+
" Method name not found "
7581
pass
7682

7783

7884
class InvalidMethodParameters(ServerError):
85+
" Invalid method paramters "
7986
pass
8087

8188

8289
class InternalError(ServerError):
90+
" Internal Server Error "
8391
pass
8492

8593

8694
class DNSZoneNotFound(SoftLayerError):
95+
" DNS Zone was not found "
8796
pass

SoftLayer/managers/cci.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
3838
:param integer nic_speed: filter based on network speed (in MBPS)
3939
:param string public_ip: filter based on public ip address
4040
:param string private_ip: filter based on private ip address
41-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
41+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
4242
:returns: Returns a list of dictionaries representing the matching CCIs
4343
4444
::

SoftLayer/managers/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _get_zone_id_from_name(self, name):
3131
def list_zones(self, **kwargs):
3232
""" Retrieve a list of all DNS zones.
3333
34-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
34+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
3535
:returns: A list of dictionaries representing the matching zones.
3636
3737
"""

SoftLayer/managers/hardware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None,
8585
:param integer nic_speed: filter based on network speed (in MBPS)
8686
:param string public_ip: filter based on public ip address
8787
:param string private_ip: filter based on private ip address
88-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
88+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
8989
:returns: Returns a list of dictionaries representing the matching
9090
hardware. This list will contain both dedicated servers and
9191
bare metal computing instances
@@ -197,7 +197,7 @@ def get_available_dedicated_server_packages(self):
197197
package = package_obj.getObject(id=package_id,
198198
mask='mask[id, name, description]')
199199

200-
if (package.get('name')):
200+
if package.get('name'):
201201
packages.append((package['id'], package['name'],
202202
package['description']))
203203

SoftLayer/managers/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_image(self, image_id, **kwargs):
2929
""" Get details about an image
3030
3131
:param int image: The ID of the image.
32-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
32+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
3333
"""
3434
if 'mask' not in kwargs:
3535
kwargs['mask'] = IMAGE_MASK
@@ -48,7 +48,7 @@ def list_private_images(self, guid=None, name=None, **kwargs):
4848
4949
:param string guid: filter based on GUID
5050
:param string name: filter based on name
51-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
51+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
5252
"""
5353
if 'mask' not in kwargs:
5454
kwargs['mask'] = IMAGE_MASK
@@ -72,7 +72,7 @@ def list_public_images(self, guid=None, name=None, **kwargs):
7272
7373
:param string guid: filter based on GUID
7474
:param string name: filter based on name
75-
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
75+
:param dict \\*\\*kwargs: response-level arguments (limit, offset, etc.)
7676
"""
7777
if 'mask' not in kwargs:
7878
kwargs['mask'] = IMAGE_MASK

0 commit comments

Comments
 (0)