def __init__(self, connection_string, disable_id_injector=True, manipulators=None): """Initialize database wrapper. :param str connection_string: a full mongodb URL (supports creds too). :keyword bool disable_id_injector: see class docs for detailed info. :keyword list manipulators: a list of manipulator instances to add to each connection instance. Default is None, which sets two manipulators for handling JSON serialization and keys with "." in their name. To disable adding any manilutors, pass in a blank iterable (ex. [] or (,)). """ self.connection_string = connection_string self.safe_connection_string = secrets.hide_url_password( self.connection_string) parsed = pymongo.uri_parser.parse_uri(self.connection_string) self.database_name = parsed['database'] self.disable_id_injector = disable_id_injector self.manipulators = manipulators if self.manipulators is None: self.manipulators = [ KeyTransform(".", "_dot_"), ObjectSerializer(), ] self._client = None self._connection = None if eventlet: eventlet.spawn_n(self.tune) else: self.tune()
def __init__(self, connection_string, disable_id_injector=True, manipulators=None): """Initialize database wrapper. :param str connection_string: a full mongodb URL (supports creds too). :keyword bool disable_id_injector: see class docs for detailed info. :keyword list manipulators: a list of manipulator instances to add to each connection instance. Default is None, which sets two manipulators for handling JSON serialization and keys with "." in their name. To disable adding any manilutors, pass in a blank iterable (ex. [] or (,)). """ self.connection_string = connection_string self.safe_connection_string = secrets.hide_url_password( self.connection_string) parsed = pymongo.uri_parser.parse_uri(self.connection_string) self.database_name = parsed['database'] self.disable_id_injector = disable_id_injector self.manipulators = manipulators if self.manipulators is None: self.manipulators = [ KeyTransform(".", "_dot_"), ObjectSerializer(), ] self._client = None self._connection = None if eventlet: self.client_lock = eventlet.semaphore.Semaphore() eventlet.spawn_n(self.tune) else: self.tune()
def test_git(self): hidden = secrets.hide_url_password('git+https://user:[email protected]') self.assertEqual(hidden, 'git+https://user:*****@github.com')
def test_mongo(self): hidden = secrets.hide_url_password('mongodb://*****:*****@localhost/db') self.assertEqual(hidden, 'mongodb://*****:*****@localhost/db')
def test_http(self): hidden = secrets.hide_url_password('http://*****:*****@localhost') self.assertEqual(hidden, 'http://*****:*****@localhost')