Skip to content

Instantly share code, notes, and snippets.

@daeken
Created December 29, 2009 05:56
Show Gist options
  • Save daeken/265175 to your computer and use it in GitHub Desktop.
Save daeken/265175 to your computer and use it in GitHub Desktop.
import urllib, urllib2
class Url(object):
def __init__(self, url):
self.url = url
def get(self, **kwargs):
url = self.url
if len(kwargs):
url += '?' + urllib.urlencode(kwargs)
return self.send(url, None)
def post(self, _data=None, **kwargs):
if _data == None:
_data = urllib.urlencode(kwargs)
return self.send(self.url, _data)
def send(self, url, data=None):
try:
resp = urllib2.urlopen(url, data)
return None, resp.read()
except urllib2.HTTPError, e:
return e.code, None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment