Skip to content

Commit

Permalink
Merge branch 'loop_plugin_multioutput' of https://github.com/AxFounda…
Browse files Browse the repository at this point in the history
…tion/strax into loop_plugin_multioutput
  • Loading branch information
JoranAngevaare committed Nov 26, 2020
2 parents 23decb7 + e5c42aa commit d07cc14
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions strax/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,44 @@ class CorrectionsInterface:
this means a unique set of correction maps.
"""

def __init__(self, host='127.0.0.1', username=None, password=None,
database_name='corrections'):
def __init__(self, client=None, database_name='corrections',
host=None, username=None, password=None,):
"""
:param host: DB host
:param username: DB username
:param password: DB password
:param database_name: DB name
Start the CorrectionsInterface. To initialize you need either:
- a pymongo.MongoClient (add as argument client) OR
- the credentials and url to connect to the pymongo instance
one wants to be using.
:param client: pymongo client, a pymongo.MongoClient object
:param database_name: Database name
(optional if client is not provided)
:param host: DB host or IP address e.g. "127.0.0.1"
:param username: Database username
:param password: Database password
"""
# Let's see if someone just provided a pymongo.MongoClient
if (client is not None) and (
host is None and
username is None and
password is None):
if not isinstance(client, pymongo.MongoClient):
raise TypeError(f'{client} is not a pymongo.MongoClient.')
self.client = client
# In this case, let's just initialize a new pymongo.MongoClient
elif (client is None) and (
host is not None and
username is not None
and password is not None):
self.client = pymongo.MongoClient(host=host,
username=username,
password=password)
else:
# Let's not be flexible with our inputs to prevent later
# misunderstandings because someone thought to be handling a
# different client than anticipated.
raise ValueError('Can only init using *either* the "client" or the '
'combination of "host+username+password", not both')

self.host = host
self.username = username
self.password = password
self.client = pymongo.MongoClient(host=self.host,
username=self.username,
password=self.password)
self.database_name = database_name

def list_corrections(self):
Expand Down

0 comments on commit d07cc14

Please sign in to comment.