Skip to content

Commit ef1c641

Browse files
author
Paul Tagliamonte
committed
Small pep8 fixes
1 parent 10e5144 commit ef1c641

File tree

9 files changed

+37
-32
lines changed

9 files changed

+37
-32
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* sunlight/services/congress.py:
44
- Add **kwargs for each method, and pass them along to all requests. This
55
helps prevent cases where we add an argument and older versions break.
6+
* sunlight/services/*.py:
7+
- Fixed some outstanding pep8 issues.
68

79
2012-06-29 James Turk <[email protected]>
810

sunlight/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import sunlight.config
2929
import sunlight.service
3030

31+
3132
def _attempt_to_load_apikey():
3233
"""
3334
This function (which will be auto-called on import of :mod:`sunlight`),
@@ -49,7 +50,7 @@ def _attempt_to_load_apikey():
4950
sunlight.config.KEY_LOCATION, str(e)))
5051
try:
5152
sunlight.config.API_KEY = \
52-
os.environ[sunlight.config.KEY_ENVVAR].strip()
53+
os.environ[sunlight.config.KEY_ENVVAR].strip()
5354
except KeyError as e:
5455
pass
5556

sunlight/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
for a Sunlight API key is fun for the whole family!
3030
"""
3131

32-
KEY_LOCATION = "~/.sunlight.key"
32+
KEY_LOCATION = "~/.sunlight.key"
3333
"""
3434
This is the location of the api key that's stored on the filesystem. Currently,
3535
it uses a file directly under a tilde, so that windows users don't have to feel
3636
as much pain when using the API. Usually this is something like
3737
``~/.sunlight.key``
3838
"""
3939

40-
KEY_ENVVAR = "SUNLIGHT_API_KEY"
40+
KEY_ENVVAR = "SUNLIGHT_API_KEY"
4141
"""
4242
This is the name of the ``os.environ`` key to look for. It's usually something
4343
stupid simple, like ``SUNLIGHT_API_KEY``.

sunlight/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:synopsis: Exceptions and Errors
77
"""
88

9+
910
class SunlightException(Exception):
1011
"""
1112
:class:`sunlight.errors.SunlightException` is the base exception,
@@ -31,6 +32,7 @@ def __str__(self):
3132
"""
3233
return repr(self.value)
3334

35+
3436
class BadRequestException(SunlightException):
3537
"""
3638
This gets thrown when the underlying url request has recieved an abnormal
@@ -46,6 +48,7 @@ class InvalidRequestException(BadRequestException):
4648
"""
4749
pass
4850

51+
4952
class NoAPIKeyException(SunlightException):
5053
"""
5154
This gets thrown if the bindings are asked to issue a request, but the

sunlight/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ def get(self, top_level_object, **kwargs):
7878

7979
ex.url = e.geturl()
8080
ex.message = message
81-
ex.code = code
81+
ex.code = code
8282

8383
raise ex

sunlight/services/capitolwords.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
service_url = "http://capitolwords.org/api"
1111

12+
1213
class capitolwords(sunlight.service.Service):
1314
"""
1415
Bindings into the `CapitolWords project <http://capitolwords.org>`_.
@@ -34,7 +35,7 @@ def dates(self, phrase, **kwargs):
3435
endpoint <http://capitolwords.org/api/#dates.json>`_.
3536
"""
3637
kwargs['phrase'] = phrase
37-
return self.get( "dates", **kwargs )
38+
return self.get("dates", **kwargs)
3839

3940
def phrases(self, entity_type, entity_value, **kwargs):
4041
"""
@@ -45,10 +46,10 @@ def phrases(self, entity_type, entity_value, **kwargs):
4546
For a list of arguments see `Capitol Words' phrases.json
4647
endpoint <http://capitolwords.org/api/#phrases.json>`_.
4748
"""
48-
kwargs['entity_type'] = entity_type
49+
kwargs['entity_type'] = entity_type
4950
kwargs['entity_value'] = entity_value
5051

51-
return self.get( "phrases", **kwargs )
52+
return self.get("phrases", **kwargs)
5253

5354
def phrases_by_entity(self, entity_type, **kwargs):
5455
"""
@@ -60,9 +61,9 @@ def phrases_by_entity(self, entity_type, **kwargs):
6061
endpoint <http://capitolwords.org/api/#phrases/entity.json>`_.
6162
"""
6263
lss = "%s/%s" % ("phrases", entity_type)
63-
return self.get( lss, **kwargs )
64+
return self.get(lss, **kwargs)
6465

65-
def text( self, phrase=None, title=None, **kwargs ):
66+
def text(self, phrase=None, title=None, **kwargs):
6667
"""
6768
Full text-search against Capitol Words data.
6869
@@ -85,13 +86,13 @@ def text( self, phrase=None, title=None, **kwargs ):
8586
kwargs['phrase'] = phrase
8687

8788
if title:
88-
kwargs['title'] = title
89+
kwargs['title'] = title
8990

90-
return self.get( "text", **kwargs )
91+
return self.get("text", **kwargs)
9192

9293
# API impl methods below
9394

94-
def _get_url( self, obj, apikey, **kwargs ):
95+
def _get_url(self, obj, apikey, **kwargs):
9596
ret = "%s/%s.json?apikey=%s&%s" % (
9697
service_url,
9798
obj,
@@ -100,15 +101,14 @@ def _get_url( self, obj, apikey, **kwargs ):
100101
)
101102
return ret
102103

103-
def _decode_response( self, response ):
104-
ret = json.loads( response )
104+
def _decode_response(self, response):
105+
ret = json.loads(response)
105106
if "error" in ret:
106-
ex = InvalidRequestException( ret['error'] )
107+
ex = InvalidRequestException(ret['error'])
107108
ex.response = ret
108109
raise ex
109110
if "results" in ret:
110111
return ret['results']
111112
# XXX: Verify this is actually
112113
# what we want.
113114
return ret
114-

sunlight/services/congress.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
service_url = "http://services.sunlightlabs.com/api/"
1515

16+
1617
def _unpack(resp, key):
17-
return [e[key] for e in resp[key+'s']]
18+
return [e[key] for e in resp[key + 's']]
19+
1820

1921
class congress(sunlight.service.Service):
2022
"""
@@ -33,7 +35,6 @@ def legislators(self, **kwargs):
3335
return _unpack(self.get('legislators.getList', **kwargs),
3436
'legislator')
3537

36-
3738
def legislator_search(self, name, threshold=0.9, all_legislators=False,
3839
**kwargs):
3940
"""
@@ -50,7 +51,6 @@ def legislator_search(self, name, threshold=0.9, all_legislators=False,
5051

5152
return _unpack(self.get('legislators.search', **params), 'result')
5253

53-
5454
def legislators_for_zip(self, zipcode, **kwargs):
5555
"""
5656
Query for all legislators representing a given ZIP code.
@@ -113,7 +113,6 @@ def districts_for_lat_lon(self, latitude, longitude, **kwargs):
113113
return _unpack(self.get('districts.getDistrictFromLatLong', **params),
114114
'district')
115115

116-
117116
def committees(self, chamber, **kwargs):
118117
"""
119118
Query for all committees for a chamber. (House|Senate|Joint)

sunlight/services/influenceexplorer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
service_url = "http://transparencydata.com/api/1.0"
1717

18+
1819
class InfluenceExplorer(sunlight.service.Service):
1920
"""
2021
Bindings into the `InfluenceExplorer <http://influenceexplorer.com/>`_
@@ -77,20 +78,18 @@ def entities(self, **kwargs):
7778
return self.get("entities", **kwargs)
7879

7980
# API impl methods below
80-
81-
def _get_url( self, obj, apikey, **kwargs ):
81+
def _get_url(self, obj, apikey, **kwargs):
8282
return "%s/%s?apikey=%s&%s" % (
8383
service_url,
8484
obj,
8585
apikey,
8686
sunlight.service.safe_encode(kwargs)
8787
)
8888

89-
def _decode_response( self, response ):
90-
ret = json.loads( response )
89+
def _decode_response(self, response):
90+
ret = json.loads(response)
9191
if "error" in ret:
92-
ex = InvalidRequestException( ret['error'] )
92+
ex = InvalidRequestException(ret['error'])
9393
ex.response = ret
9494
raise ex
9595
return ret
96-

sunlight/services/openstates.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
module_name = "openstates"
99
service_url = "http://openstates.org/api/v1"
1010

11+
1112
class openstates(sunlight.service.Service):
1213
"""
1314
Bindings into the `Open States API <http://openstates.org/api/>`_. Keep in
@@ -75,7 +76,7 @@ def legislators(self, **kwargs):
7576
The fields and keyword arguments can be found on the
7677
`Legislator API docs <http://openstates.org/api/legislators/>`_.
7778
"""
78-
return self.get( [ "legislators"], **kwargs )
79+
return self.get(["legislators"], **kwargs)
7980

8081
def legislator_detail(self, leg_id, **kwargs):
8182
"""
@@ -98,7 +99,7 @@ def legislator_geo_search(self, latitude, longitude, **kwargs):
9899
See the Open States documentation for examples of `Legislator Geo
99100
Lookup <http://openstates.org/api/legislators/#geo-lookup>`_.
100101
"""
101-
kwargs['lat'] = latitude
102+
kwargs['lat'] = latitude
102103
kwargs['long'] = longitude
103104
return self.get(["legislators", "geo"], **kwargs)
104105

@@ -132,7 +133,7 @@ def events(self, **kwargs):
132133
See the Open States' site for details on the
133134
`Event API <http://openstates.org/api/events/>`_.
134135
"""
135-
return self.get([ "events" ], **kwargs)
136+
return self.get(["events"], **kwargs)
136137

137138
def event_detail(self, event_id, **kwargs):
138139
"""
@@ -143,8 +144,8 @@ def event_detail(self, event_id, **kwargs):
143144
See the Open States' site for details on the
144145
`Event API Fields <http://openstates.org/api/events/#event-fields>`_.
145146
"""
146-
lss = [ "events", event_id ]
147-
return self.get( lss, **kwargs )
147+
lss = ["events", event_id]
148+
return self.get(lss, **kwargs)
148149

149150
def districts(self, state, chamber=None, **kwargs):
150151
"""
@@ -185,7 +186,7 @@ def _get_url(self, objs, apikey, **kwargs):
185186

186187
# join pieces by slashes and add a trailing slash
187188
object_path = "/".join(objs)
188-
object_path += "/"
189+
object_path += "/"
189190

190191
return "%s/%s?apikey=%s&%s" % (
191192
service_url,

0 commit comments

Comments
 (0)