session => sessions
authorKenneth Reitz <me@kennethreitz.com>
Wed, 17 Aug 2011 02:15:03 +0000 (22:15 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Wed, 17 Aug 2011 02:15:03 +0000 (22:15 -0400)
requests/session.py [deleted file]
requests/sessions.py [new file with mode: 0644]

diff --git a/requests/session.py b/requests/session.py
deleted file mode 100644 (file)
index 7250542..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-# -*- coding: utf-8 -*-
-
-"""
-requests.session
-~~~~~~~~~~~~~~~
-
-This module provides a Session object to manage and persist settings across
-requests (cookies, auth, proxies).
-
-"""
-
-import requests.api
-import cookielib
-
-class Session(object):
-    __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies']
-
-    def __init__(self, **kwargs):
-        # Set up a CookieJar to be used by default
-        self.cookies = cookielib.FileCookieJar()
-        # Map args from kwargs to instance-local variables
-        map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),
-                kwargs.iterkeys(), kwargs.itervalues())
-        # Map and wrap requests.api methods
-        self._map_api_methods()
-        
-    def _map_api_methods(self):
-        """ Reads each available method from requests.api and decorates
-        them with a wrapper that inserts any instance-local attributes
-        (from __attrs__) that have been set, combining them with **kwargs """
-        def pass_args(func):
-            def wrapper_func(*args, **kwargs):
-                inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems() 
-                        if k in self.__attrs__)
-                # Combine instance-local values with kwargs values, with 
-                # priority to values in kwargs
-                kwargs = dict(inst_attrs.items() + kwargs.items())
-                return func(*args, **kwargs)
-            return wrapper_func
-        # Map and decorate each function available in requests.api
-        map(lambda fn: setattr(self, fn, pass_args(getattr(requests.api, fn))),
-                requests.api.__all__) 
-
-
diff --git a/requests/sessions.py b/requests/sessions.py
new file mode 100644 (file)
index 0000000..9303a82
--- /dev/null
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+"""
+requests.session
+~~~~~~~~~~~~~~~
+
+This module provides a Session object to manage and persist settings across
+requests (cookies, auth, proxies).
+
+"""
+
+import requests.api
+import cookielib
+
+class Session(object):
+    __attrs__ = ['headers', 'cookies', 'auth', 'timeout', 'proxies']
+
+    def __init__(self, **kwargs):
+        # Set up a CookieJar to be used by default
+        self.cookies = cookielib.FileCookieJar()
+        # Map args from kwargs to instance-local variables
+        map(lambda k, v: (k in self.__attrs__) and setattr(self, k, v),
+                kwargs.iterkeys(), kwargs.itervalues())
+        # Map and wrap requests.api methods
+        self._map_api_methods()
+
+    def __repr__(self):
+        return '<requests-client at %s>' % (id(self))
+
+    def _map_api_methods(self):
+        """ Reads each available method from requests.api and decorates
+        them with a wrapper that inserts any instance-local attributes
+        (from __attrs__) that have been set, combining them with **kwargs """
+        def pass_args(func):
+            def wrapper_func(*args, **kwargs):
+                inst_attrs = dict((k, v) for k, v in self.__dict__.iteritems()
+                        if k in self.__attrs__)
+                # Combine instance-local values with kwargs values, with
+                # priority to values in kwargs
+                kwargs = dict(inst_attrs.items() + kwargs.items())
+                return func(*args, **kwargs)
+            return wrapper_func
+        # Map and decorate each function available in requests.api
+        map(lambda fn: setattr(self, fn, pass_args(getattr(requests.api, fn))),
+                requests.api.__all__)
+
+