1. dp wiz
  2. baconpie

Commits

dp wiz  committed ac0461f

guess i can do some gzip tricks now

  • Participants
  • Parent commits 24497d5
  • Branches default

Comments (0)

Files changed (1)

File baconpie/__init__.py

View file
     def _request(self, url, **query):
         url = "%s%s%s%s" % (self._host, self._endpoint, url, '?%s' % urlencode(query) if query else '')
         print 'requesting', url
+
         request = Request(url)
         request.add_header('Accept-encoding', 'gzip')  # not really, yet
         response = urlopen(request)
+        data = response.read()
+
         print response.headers
-        return json.loads(response.read())
+        if response.headers.get('Content-Encoding') == 'gzip':
+            from gzip import GzipFile
+            from cStringIO import StringIO
+            data = GzipFile(fileobj=StringIO(data)).read()
+
+        return json.loads(data)
 
     def _inspect(self):
         data = self._request('')