Skip to content

Commit

Permalink
Ensure digits from json response are cast to int.
Browse files Browse the repository at this point in the history
PHP, you suck.
  • Loading branch information
sdboyer committed Aug 28, 2013
1 parent ac186b7 commit cf63e15
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ def request_bool(self, *args):
self.protocol.deferred.addCallback(self.convert_bool)

def convert_json(self, raw):
def intify(d):
for k, v in d.iteritems():
if type(v) == dict:
print 'found dict'
d[k] = intify(v)
elif type(v) == unicode and v.isdigit():
print 'found string {0}'.format(v)
d[k] = int(v)
return d

try:
result = json.loads(raw)
return result
return intify(result)
except ValueError:
log.err("Protocol {0}:{1} returned bad JSON.".format(self.protocol.__class__, self.protocol.command))

Expand Down

0 comments on commit cf63e15

Please sign in to comment.