Commits

MailChimp  committed 0c3bf78

Use faster JSON libraries if possible

  • Participants
  • Parent commits 55d6d22
  • Tags 1.0.28

Comments (0)

Files changed (2)

 import requests, os.path, logging, sys, time
 try:
-    import json as json
-except:
-    import simplejson as json
+    import ujson as json
+except ImportError:
+    try:
+        import simplejson as json
+    except ImportError:
+        import json
 
 class Error(Exception):
     pass
         params = json.dumps(params)
         self.log('POST to %s%s.json: %s' % (ROOT, url, params))
         start = time.time()
-        r = self.session.post('%s%s.json' % (ROOT, url), data=params, headers={'content-type': 'application/json', 'user-agent': 'Mandrill-Python/1.0.27'})
-        r.raise_for_status()
+        r = self.session.post('%s%s.json' % (ROOT, url), data=params, headers={'content-type': 'application/json', 'user-agent': 'Mandrill-Python/1.0.28'})
         try:
             remote_addr = r.raw._original_response.fp._sock.getpeername() # grab the remote_addr before grabbing the text since the socket will go away
         except:
         self.log('Received %s in %.2fms: %s' % (r.status_code, complete_time * 1000, r.text))
         self.last_request = {'url': url, 'request_body': params, 'response_body': r.text, 'remote_addr': remote_addr, 'response': r, 'time': complete_time}
 
-        # requests 1.0.0 changed this from a property to a function
-        if callable(r.json):
-            result = r.json()
-        else:
-            result = r.json
+        result = json.loads(response_body)
 
         if r.status_code != requests.codes.ok:
             raise self.cast_error(result)
 
 setup(
     name = 'mandrill',
-    version = '1.0.27',
+    version = '1.0.28',
     author = 'Mandrill Devs',
     author_email = 'community@mandrill.com',
     description = 'A CLI client and Python API library for the Mandrill email as a service platform.',