Skip to content

Commit 7e4340b

Browse files
fixing up some tox complaints
1 parent 62f2457 commit 7e4340b

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

SoftLayer/CLI/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
:license: MIT, see LICENSE for more details.
77
"""
88
# pylint: disable=w0401, invalid-name
9-
import logging
109

1110
from SoftLayer.CLI.helpers import * # NOQA
12-

SoftLayer/CLI/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ def output_diagnostics(env, verbose=0, **kwargs):
151151

152152
if verbose > 1:
153153
for call in env.client.transport.get_last_calls():
154-
call_table = formatting.Table(['','{}::{}'.format(call.service, call.method)])
154+
call_table = formatting.Table(['', '{}::{}'.format(call.service, call.method)])
155155
nice_mask = ''
156156
if call.mask is not None:
157157
nice_mask = call.mask
158158

159159
call_table.add_row(['id', call.identifier])
160-
call_table.add_row(['mask', call.mask])
160+
call_table.add_row(['mask', nice_mask])
161161
call_table.add_row(['filter', call.filter])
162162
call_table.add_row(['limit', call.limit])
163163
call_table.add_row(['offset', call.offset])

SoftLayer/transports.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ def __init__(self):
120120
#: Exception any exceptions that got caught
121121
self.exception = None
122122

123-
#: String Url parameters used in the Rest transport
124-
self.params = None
125-
126123

127124
class SoftLayerListResult(list):
128125
"""A SoftLayer API list result."""
@@ -168,9 +165,12 @@ def __call__(self, request):
168165
headers[header_name] = {'id': request.identifier}
169166

170167
if request.mask is not None:
171-
request.mask = _format_object_mask(request.mask)
172-
headers.update(_format_object_mask_xmlrpc(request.mask, request.service))
173-
168+
if isinstance(request.mask, dict):
169+
mheader = '%sObjectMask' % request.service
170+
else:
171+
mheader = 'SoftLayer_ObjectMask'
172+
request.mask = _format_object_mask(request.mask)
173+
headers.update({mheader: {'mask': request.mask}})
174174

175175
if request.filter is not None:
176176
headers['%sObjectFilter' % request.service] = request.filter
@@ -187,15 +187,14 @@ def __call__(self, request):
187187

188188
request.url = '/'.join([self.endpoint_url, request.service])
189189
request.payload = utils.xmlrpc_client.dumps(tuple(largs),
190-
methodname=request.method,
191-
allow_none=True)
190+
methodname=request.method,
191+
allow_none=True)
192192

193193
# Prefer the request setting, if it's not None
194194
verify = request.verify
195195
if verify is None:
196196
request.verify = self.verify
197197

198-
199198
try:
200199
resp = self.client.request('POST', request.url,
201200
data=request.payload,
@@ -259,17 +258,17 @@ def print_reproduceable(self, request):
259258
verify = $verify
260259
cert = $cert
261260
proxy = $proxy
262-
response = client.request('POST', url, data=payload, headers=transport_headers, timeout=timeout,
261+
response = client.request('POST', url, data=payload, headers=transport_headers, timeout=timeout,
263262
verify=verify, cert=cert, proxies=proxy)
264263
xml = ElementTree.fromstring(response.content)
265264
ElementTree.dump(xml)
266265
==========================''')
267266

268-
269267
safe_payload = re.sub(r'<string>[a-z0-9]{64}</string>', r'<string>API_KEY_GOES_HERE</string>', request.payload)
270268
safe_payload = re.sub(r'(\s+)', r' ', safe_payload)
271-
substitutions = dict(url=request.url, payload=safe_payload, transport_headers=request.transport_headers,
272-
timeout=self.timeout, verify=request.verify, cert=request.cert, proxy=_proxies_dict(self.proxy))
269+
substitutions = dict(url=request.url, payload=safe_payload, transport_headers=request.transport_headers,
270+
timeout=self.timeout, verify=request.verify, cert=request.cert,
271+
proxy=_proxies_dict(self.proxy))
273272
return output.substitute(substitutions)
274273

275274

@@ -340,7 +339,6 @@ def __call__(self, request):
340339
method = 'POST'
341340
body['parameters'] = request.args
342341

343-
344342
if body:
345343
request.payload = json.dumps(body)
346344

@@ -385,7 +383,6 @@ def __call__(self, request):
385383
request.url = ex.response.url
386384
raise exceptions.SoftLayerAPIError(ex.response.status_code, message)
387385
except requests.RequestException as ex:
388-
request.url = ex.response.url
389386
raise exceptions.TransportError(0, str(ex))
390387

391388
def print_reproduceable(self, request):
@@ -442,17 +439,24 @@ def __call__(self, call):
442439
return call.result
443440

444441
def pre_transport_log(self, call):
445-
LOGGER.warning("Calling: {}::{}(id={})".format(call.service, call.method, call.identifier))
442+
"""Prints a warning before calling the API """
443+
output = "Calling: {}::{}(id={})".format(call.service, call.method, call.identifier)
444+
LOGGER.warning(output)
446445

447446
def post_transport_log(self, call):
448-
LOGGER.debug("Returned Data: \n{}".format(call.result))
447+
"""Prints the result "Returned Data: \n%s" % (call.result)of an API call"""
448+
output = "Returned Data: \n{}".format(call.result)
449+
LOGGER.debug(output)
449450

450451
def get_last_calls(self):
452+
"""Returns all API calls for a session"""
451453
return self.requests
452454

453455
def print_reproduceable(self, call):
456+
"""Prints a reproduceable debugging output"""
454457
return self.transport.print_reproduceable(call)
455458

459+
456460
class TimingTransport(object):
457461
"""Transport that records API call timings."""
458462

@@ -480,6 +484,10 @@ def get_last_calls(self):
480484
self.last_calls = []
481485
return last_calls
482486

487+
def print_reproduceable(self, call):
488+
"""Not Implemented"""
489+
return "Not Implemented"
490+
483491

484492
class FixtureTransport(object):
485493
"""Implements a transport which returns fixtures."""
@@ -495,6 +503,10 @@ def __call__(self, call):
495503
except AttributeError:
496504
raise NotImplementedError('%s::%s fixture is not implemented' % (call.service, call.method))
497505

506+
def print_reproduceable(self, call):
507+
"""Not Implemented"""
508+
return "Not Implemented"
509+
498510

499511
def _proxies_dict(proxy):
500512
"""Makes a proxy dict appropriate to pass to requests."""
@@ -503,21 +515,6 @@ def _proxies_dict(proxy):
503515
return {'http': proxy, 'https': proxy}
504516

505517

506-
def _format_object_mask_xmlrpc(objectmask, service):
507-
"""Format new and old style object masks into proper headers.
508-
509-
:param objectmask: a string- or dict-based object mask
510-
:param service: a SoftLayer API service name
511-
512-
"""
513-
if isinstance(objectmask, dict):
514-
mheader = '%sObjectMask' % service
515-
else:
516-
mheader = 'SoftLayer_ObjectMask'
517-
518-
return {mheader: {'mask': objectmask}}
519-
520-
521518
def _format_object_mask(objectmask):
522519
"""Format the new style object mask.
523520
@@ -528,7 +525,7 @@ def _format_object_mask(objectmask):
528525
529526
"""
530527
objectmask = objectmask.strip()
531-
objectmask = re.sub(r'(\s+)', r' ', objectmask)
528+
532529
if (not objectmask.startswith('mask') and
533530
not objectmask.startswith('[')):
534531
objectmask = "mask[%s]" % objectmask

0 commit comments

Comments
 (0)