filling out the gaps
authorKenneth Reitz <me@kennethreitz.com>
Sun, 13 Feb 2011 22:17:33 +0000 (17:17 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Sun, 13 Feb 2011 22:17:33 +0000 (17:17 -0500)
requests/core.py

index 977e4b23ac34f5bfc3697fb937e8e08d317fd43c..940ff06b283121eab0d5f44421bd20751317261b 100644 (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
+                               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