Package restkit :: Module session
[hide private]

Source Code for Module restkit.session

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of restkit released under the MIT license. 
 4  # See the NOTICE for more information. 
 5   
 6  from socketpool import ConnectionPool 
 7  from restkit.conn import Connection 
 8   
 9   
10  _default_session = {} 
11   
12 -def get_session(backend_name, **options):
13 global _default_session 14 15 if not _default_session: 16 _default_session = {} 17 pool = ConnectionPool(factory=Connection, 18 backend=backend_name, **options) 19 _default_session[backend_name] = pool 20 else: 21 if backend_name not in _default_session: 22 pool = ConnectionPool(factory=Connection, 23 backend=backend_name, **options) 24 25 _default_session[backend_name] = pool 26 else: 27 pool = _default_session.get(backend_name) 28 return pool
29
30 -def set_session(backend_name, **options):
31 32 global _default_session 33 34 if not _default_session: 35 _default_session = {} 36 37 if backend_name in _default_session: 38 pool = _default_session.get(backend_name) 39 else: 40 pool = ConnectionPool(factory=Connection, 41 backend=backend_name, **options) 42 _default_session[backend_name] = pool 43 return pool
44