Trim whitespace

This commit is contained in:
Jason R. Coombs 2016-09-03 11:05:48 -04:00
parent 43f656f296
commit e98b5d74ca

View File

@ -9,7 +9,7 @@ compat.fix_HTTPMessage()
class Client(object): class Client(object):
""" """
Wolfram|Alpha v2.0 client Wolfram|Alpha v2.0 client
Pass an ID to the object upon instantiation, then Pass an ID to the object upon instantiation, then
query Wolfram Alpha using the query method. query Wolfram Alpha using the query method.
""" """
@ -28,7 +28,7 @@ class Client(object):
} }
if assumption: if assumption:
data.update({'assumption': assumption}) data.update({'assumption': assumption})
query = urllib.parse.urlencode(data) query = urllib.parse.urlencode(data)
url = 'https://api.wolframalpha.com/v2/query?' + query url = 'https://api.wolframalpha.com/v2/query?' + query
resp = urllib.request.urlopen(url) resp = urllib.request.urlopen(url)
@ -59,29 +59,29 @@ class Result(object):
self.info.append(self.warnings) self.info.append(self.warnings)
except KeyError: except KeyError:
self.warnings = None self.warnings = None
def _handle_error(self): def _handle_error(self):
error_state = self.tree['@error'] error_state = self.tree['@error']
if error_state == 'false': if error_state == 'false':
return return
error = self.tree['error'] error = self.tree['error']
code = error['code'] code = error['code']
msg = error['msg'] msg = error['msg']
template = 'Error {code}: {msg}' template = 'Error {code}: {msg}'
raise Exception(template.format(code=code, msg=msg)) raise Exception(template.format(code=code, msg=msg))
def __iter__(self): def __iter__(self):
return iter(self.info) return iter(self.info)
def __len__(self): def __len__(self):
return len(self.info) return len(self.info)
@property @property
def results(self): def results(self):
''' Get the pods that hold the response to a simple, discrete query. ''' ''' Get the pods that hold the response to a simple, discrete query. '''
return [pod for pod in self.pods if pod.primary or pod.title=='Result'] return [pod for pod in self.pods if pod.primary or pod.title=='Result']
@property @property
def details(self): def details(self):
''' Get a simplified set of answers with some context. ''' ''' Get a simplified set of answers with some context. '''
@ -109,16 +109,16 @@ class Pod(object):
def _handle_error(self): def _handle_error(self):
if self.error == 'false': if self.error == 'false':
return return
error = self.node['error'] error = self.node['error']
code = error['code'] code = error['code']
msg = error['msg'] msg = error['msg']
template = 'Error {code}: {msg}' template = 'Error {code}: {msg}'
raise Exception(template.format(code=code, msg=msg)) raise Exception(template.format(code=code, msg=msg))
def __iter__(self): def __iter__(self):
return iter(self.subpods) return iter(self.subpods)
def __len__(self): def __len__(self):
return self.number_of_subpods return self.number_of_subpods
@ -145,13 +145,13 @@ class Assumption(object):
def __init__(self, node): def __init__(self, node):
self.assumption = node self.assumption = node
#self.description = self.assumption[0]['desc'] # We only care about our given assumption. #self.description = self.assumption[0]['desc'] # We only care about our given assumption.
def __iter__(self): def __iter__(self):
return iter(self.assumption) return iter(self.assumption)
def __len__(self): def __len__(self):
return len(self.assumption) return len(self.assumption)
@property @property
def text(self): def text(self):
text = self.template.replace('${desc1}', self.description) text = self.template.replace('${desc1}', self.description)
@ -168,7 +168,7 @@ class Warning(object):
def __iter__(self): def __iter__(self):
return iter(node) return iter(node)
def __len__(self): def __len__(self):
return len(node) return len(node)
@ -181,4 +181,4 @@ class Image(object):
self.height = node['@height'] self.height = node['@height']
self.width = node['@width'] self.width = node['@width']
self.src = node['@src'] self.src = node['@src']