*fully* rely on requests

This commit is contained in:
Kenneth Reitz
2011-03-31 04:51:42 -04:00
parent d2823bf6b7
commit 19ecde4946
+5 -11
View File
@@ -127,14 +127,9 @@ class Gist(object):
def _post(self, params, headers={}):
"""POST to the web form (internal method)."""
request = urllib2.Request(self.post_url,
urllib.urlencode(params),
headers)
try:
response = urllib2.urlopen(request)
except IOError, exc:
response = exc
return response.code, response.msg
r = requests.post(self.post_url, params, headers=headers)
return r.status_code, r.content
def reset(self):
"""Clear the local cache."""
@@ -204,9 +199,8 @@ class Gist(object):
for fn in self._meta['files']:
# Grab file contents
_file_url = GIST_BASE % 'raw/%s/%s' % (self.id, urllib2.quote(fn))
# _files[fn] = unicode(urllib2.urlopen(_file_url).read())
_files[fn] = cStringIO.StringIO()
_files[fn].write(urllib2.urlopen(_file_url).read())
_files[fn].write(requests.get(_file_url).content)
return _files
@@ -228,7 +222,7 @@ class Gists(object):
# Return a list of Gist objects
return [Gist(json=g)
for g in json.load(urllib2.urlopen(_url))['gists']]
for g in json.load(requests.get(_url).content)['gists']]
class GistComment(object):