Skip to content

Commit 0742a78

Browse files
committed
Change Server initialization to accept a Server instance instead of the various
args that are then used to create a Server.
1 parent 63c5a8e commit 0742a78

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

couchdb/client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,15 @@ class Server(object):
6666
>>> del server['python-tests']
6767
"""
6868

69-
def __init__(self, url=DEFAULT_BASE_URL, cache=None, timeout=None,
70-
full_commit=True):
69+
def __init__(self, url=DEFAULT_BASE_URL, full_commit=True, session=None):
7170
"""Initialize the server object.
7271
7372
:param uri: the URI of the server (for example
7473
``http://localhost:5984/``)
75-
:param cache: either a cache directory path (as a string) or an object
76-
compatible with the ``httplib2.FileCache`` interface. If
77-
`None` (the default), no caching is performed.
78-
:param timeout: socket timeout in number of seconds, or `None` for no
79-
timeout
74+
:param session: an http.Session instance or None for a default session
8075
"""
8176
if isinstance(url, basestring):
82-
session = http.Session(cache=cache, timeout=timeout)
83-
self.resource = http.Resource(url, session)
77+
self.resource = http.Resource(url, session or http.Session())
8478
else:
8579
self.resource = url # treat as a Resource object
8680
if not full_commit:

couchdb/http.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def __iter__(self):
119119
class Session(object):
120120

121121
def __init__(self, cache=None, timeout=None, max_redirects=5):
122+
"""Initialize an HTTP client session.
123+
124+
:param cache: an instance with a dict-like interface or None to allow
125+
Session to create a dict for caching.
126+
:param timeout: socket timeout in number of seconds, or `None` for no
127+
timeout
128+
"""
122129
from couchdb import __version__ as VERSION
123130
self.user_agent = 'CouchDB-Python/%s' % VERSION
124131
if cache is None:

couchdb/tests/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def test_init_with_resource(self):
4242
serv = client.Server(url=res)
4343
serv.config()
4444

45+
def test_init_with_session(self):
46+
sess = http.Session()
47+
serv = client.Server(client.DEFAULT_BASE_URL, session=sess)
48+
serv.config()
49+
self.assertTrue(serv.resource.session is sess)
50+
4551
def test_exists(self):
4652
self.assertTrue(client.Server(client.DEFAULT_BASE_URL))
4753
self.assertFalse(client.Server('http://localhost:9999'))

0 commit comments

Comments
 (0)