Created
December 29, 2009 05:56
-
-
Save daeken/265175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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