Skip to content

Commit

Permalink
updates for python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
paulswartz committed Apr 4, 2013
1 parent 0ec80dd commit e482b6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions examples/csv_import.py
Expand Up @@ -35,7 +35,7 @@
sr = studentrecord.StudentRecord(auth)
sr.auth_token # make sure we're authenticated
# TODO allow picking a customer from the list
sr.choose_customer(sr.customer[0])
sr.choose_customer(sr['customer'][0])


class CSVMapping(object):
Expand Down Expand Up @@ -132,6 +132,8 @@ def get_update(old, new):
"""
output = {}
for k, v in old.iteritems():
if k[0] == '_':
continue
if isinstance(v, dict):
v2 = get_update(v, new.get(k, {}))
if not v2:
Expand Down Expand Up @@ -166,7 +168,7 @@ def upsert(type_, obj):
if not query:
return
print type_.upper(), obj,
endpoint = getattr(sr, type_)
endpoint = sr[type_]
try:
existing = endpoint.filter(**query)[:1]
if existing:
Expand Down
15 changes: 8 additions & 7 deletions studentrecord.py
Expand Up @@ -246,7 +246,8 @@ def auth_token(self):
if response.status_code != 200:
raise LoginException('invalid username/password',
response.content)
self._auth_token = response.json['authentication_token']
self._auth_token = json.loads(
response.content)['authentication_token']
return self._auth_token

@property
Expand Down Expand Up @@ -297,7 +298,7 @@ def dispatch(self, method, endpoint, _id=None, **kwargs):
raise StudentRecordException(
'%i from %s' % (resp.status_code, resp.url),
resp.content)
return resp.json
return json.loads(resp.content)

def get(self, endpoint, _id=None, **kwargs):
"""
Expand All @@ -324,17 +325,17 @@ def delete(self, endpoint, _id, **kwargs):
return self.dispatch('delete', endpoint, _id, **kwargs)

# data endpoints
def __getattr__(self, attr):
def __getitem__(self, attr):
"""
If we don't recognize the attribute, make an API Endpoint to access
If we're accessed as a dictionary, make an API Endpoint to access
that data.
>>> sr = StudentRecord(auth=auth)
>>> sr.person
>>> sr['person']
<Endpoint>
>>> sr.organization
>>> sr['organization']
<Endpoint>
>>> sr.applicant
>>> sr['applicant']
<Endpoint>
"""
return Endpoint(self, attr)

0 comments on commit e482b6f

Please sign in to comment.