Add all methods to session
authorKenneth Reitz <me@kennethreitz.com>
Sat, 22 Oct 2011 22:15:28 +0000 (18:15 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 22 Oct 2011 22:15:28 +0000 (18:15 -0400)
requests/sessions.py

index 0dc5e9d..1d130a3 100644 (file)
@@ -167,6 +167,7 @@ class Session(object):
 
         return r.response
 
+
     def get(self, url, **kwargs):
         """Sends a GET request. Returns :class:`Response` object.
 
@@ -178,6 +179,61 @@ class Session(object):
         return self.request('GET', url, **kwargs)
 
 
+    def head(self, url, **kwargs):
+        """Sends a HEAD request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        kwargs.setdefault('allow_redirects', True)
+        return self.request('HEAD', url, **kwargs)
+
+
+    def post(self, url, data='', **kwargs):
+        """Sends a POST request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        return self.request('post', url, data=data, **kwargs)
+
+
+    def put(self, url, data='', **kwargs):
+        """Sends a PUT request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        return self.request('put', url, data=data, **kwargs)
+
+
+    def patch(url, data='', **kwargs):
+        """Sends a PATCH request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        return self.request('patch', url,  data='', **kwargs)
+
+
+    def delete(self, url, **kwargs):
+        """Sends a DELETE request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        return self.request('delete', url, **kwargs)
+
+
+
 def session(**kwargs):
     """Returns a :class:`Session` for context-management."""