def _mdb_get_database(uri, **kwargs):
 if (not ('tz_aware' in kwargs)):
  kwargs['tz_aware'] = True
 connection_factory = MongoClient
 _parsed_uri = {}
 try:
  _parsed_uri = pymongo.uri_parser.parse_uri(uri)
 except pymongo.errors.InvalidURI:
  db_name = uri
  _conn = MongoClient()
  pass
 else:
  if ('replicaset' in _parsed_uri['options']):
   connection_factory = MongoReplicaSetClient
  db_name = _parsed_uri.get('database', 'pysaml2')
  _conn = connection_factory(uri, **kwargs)
 _db = _conn[db_name]
 if ('username' in _parsed_uri):
  _db.authenticate(_parsed_uri.get('username', None), _parsed_uri.get('password', None))
 return _db

def _mdb_get_database ( uri , ** kwargs ) : if ( not ( 'tz_aware' in kwargs ) ) : kwargs [ 'tz_aware' ] = True connection_factory = MongoClient _parsed_uri = { } try : _parsed_uri = pymongo . uri_parser . parse_uri ( uri ) except pymongo . errors . InvalidURI : db_name = uri _conn = MongoClient ( ) pass else : if ( 'replicaset' in _parsed_uri [ 'options' ] ) : connection_factory = MongoReplicaSetClient db_name = _parsed_uri . get ( 'database' , 'pysaml2' ) _conn = connection_factory ( uri , ** kwargs ) _db = _conn [ db_name ] if ( 'username' in _parsed_uri ) : _db . authenticate ( _parsed_uri . get ( 'username' , None ) , _parsed_uri . get ( 'password' , None ) ) return _db
helper-function to connect to mongodb and return a database object .