Skip to content

Commit 0d29ecc

Browse files
tammoippendjc
authored andcommitted
Enable querying the version of CouchDB server
1 parent 0628d62 commit 0d29ecc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

couchdb/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, url=DEFAULT_BASE_URL, full_commit=True, session=None):
8585
self.resource = url # treat as a Resource object
8686
if not full_commit:
8787
self.resource.headers['X-Couch-Full-Commit'] = 'false'
88+
self._version_info = None
8889

8990
def __contains__(self, name):
9091
"""Return whether the server contains a database with the specified
@@ -166,6 +167,18 @@ def version(self):
166167
status, headers, data = self.resource.get_json()
167168
return data['version']
168169

170+
def version_info(self):
171+
"""The version of the CouchDB server as a tuple of ints.
172+
173+
Note that this results in a request being made only at the first call.
174+
Afterwards the result will be cached.
175+
176+
:rtype: `tuple(int, int, int)`"""
177+
if self._version_info is None:
178+
version = self.version()
179+
self._version_info = tuple(map(int, version.split('.')))
180+
return self._version_info
181+
169182
def stats(self, name=None):
170183
"""Server statistics.
171184

0 commit comments

Comments
 (0)