Pep8 autofixes

This commit is contained in:
Calen Pennington
2013-02-06 11:13:50 -05:00
parent 7fc4081495
commit cfae1cdf62
271 changed files with 2395 additions and 1826 deletions

View File

@@ -5,23 +5,28 @@ import settings
log = logging.getLogger('mitx.' + __name__)
def strip_none(dic):
return dict([(k, v) for k, v in dic.iteritems() if v is not None])
def strip_blank(dic):
def _is_blank(v):
return isinstance(v, str) and len(v.strip()) == 0
return dict([(k, v) for k, v in dic.iteritems() if not _is_blank(v)])
def extract(dic, keys):
if isinstance(keys, str):
return strip_none({keys: dic.get(keys)})
else:
return strip_none({k: dic.get(k) for k in keys})
def merge_dict(dic1, dic2):
return dict(dic1.items() + dic2.items())
def perform_request(method, url, data_or_params=None, *args, **kwargs):
if data_or_params is None:
data_or_params = {}
@@ -34,7 +39,7 @@ def perform_request(method, url, data_or_params=None, *args, **kwargs):
except Exception as err:
log.exception("Trying to call {method} on {url} with params {params}".format(
method=method, url=url, params=data_or_params))
# Reraise with a single exception type
# Reraise with a single exception type
raise CommentClientError(str(err))
if 200 < response.status_code < 500:
@@ -47,6 +52,7 @@ def perform_request(method, url, data_or_params=None, *args, **kwargs):
else:
return json.loads(response.text)
class CommentClientError(Exception):
def __init__(self, msg):
self.message = msg
@@ -54,5 +60,6 @@ class CommentClientError(Exception):
def __str__(self):
return repr(self.message)
class CommentClientUnknownError(CommentClientError):
pass