mirror of
https://github.com/kennethreitz/gistapi.py.git
synced 2026-06-05 23:10:17 +00:00
*fully* rely on requests
This commit is contained in:
+5
-11
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user