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
+ try:
+ pass
+
+ success = True
+
+ except Exception:
+ raise RequestException
- #set self.response
+ else:
+ raise InvalidMethod
- if success:
- self.sent = True
+
+ self.sent = True if success else False
+
return success