filling out the gaps

This commit is contained in:
Kenneth Reitz
2011-02-13 17:17:33 -05:00
parent af272d5827
commit e9c2b917d2
+50 -15
View File
@@ -50,42 +50,77 @@ class Request(object):
object.__setattr__(self, name, value)
def _checks(self):
pass
def send(self, anyway=False):
"""Sends the request.
:param anyway: If True, request will be sent, even if it has already been sent.
"""
self._checks()
if self.method.lower() == 'get':
if (not self.sent) or anyway:
r = urllib.urlopen('http://kennethreitz.com')
self.response.headers = r.headers.dict
self.response.status_code = r.code
self.response.content = r.read()
success = True
try:
r = urllib.urlopen('http://kennethreitz.com')
self.response.headers = r.headers.dict
self.response.status_code = r.code
self.response.content = r.read()
success = True
except Exception:
raise RequestException
elif self.method.lower() == 'head':
if (not self.sent) or anyway:
pass
try:
pass
success = True
except Exception:
raise RequestException
elif self.method.lower() == 'put':
if (not self.sent) or anyway:
pass
try:
pass
success = True
except Exception:
raise RequestException
elif self.method.lower() == 'post':
if (not self.sent) or anyway:
pass
try:
pass
success = True
except Exception:
raise RequestException
elif self.method.lower() == 'delete':
if (not self.sent) or anyway:
pass
#set self.response
try:
pass
success = True
if success:
self.sent = True
except Exception:
raise RequestException
else:
raise InvalidMethod
self.sent = True if success else False
return success