Permalink
Browse files

Merge pull request #44 from verm666/fix-mongodb-uri-parsing

Fix uri parsing in MongoDBBackend
  • Loading branch information...
2 parents 7d2fe1e + b5dd840 commit ba3bacfea66ec031a37927cb82a1900ff630936b Roman Valls committed Oct 28, 2012
Showing with 16 additions and 2 deletions.
  1. +16 −2 logbook/ticketing.py
View
@@ -275,15 +275,29 @@ def __init__(self, db, row):
#TODO: Update connection setup once PYTHON-160 is solved.
def setup_backend(self):
+ import pymongo
from pymongo import ASCENDING, DESCENDING
- from pymongo.connection import Connection, _parse_uri
+ from pymongo.connection import Connection
+
+ try:
+ from pymongo.uri_parser import parse_uri
+ except ImportError:
+ from pymongo.connection import _parse_uri as parse_uri
+
from pymongo.errors import AutoReconnect
_connection = None
uri = self.options.pop('uri', u'')
_connection_attempts = 0
- hosts, database, user, password = _parse_uri(uri, Connection.PORT)
+ parsed_uri = parse_uri(uri, Connection.PORT)
+
+ if type(parsed_uri) is tuple:
+ # pymongo < 2.0
+ database = parsed_uri[1]
+ else:
+ # pymongo >= 2.0
+ database = parsed_uri['database']
# Handle auto reconnect signals properly
while _connection_attempts < 5:

0 comments on commit ba3bacf

Please sign in to comment.