mongotail/conn.py
def connect(address, args):
    """
    Connect with `address`, and return a tuple with a :class:`~pymongo.MongoClient`,
    and a :class:`~pymongo.database.Database` object.
    :param address: a string representation with the db address
    :param args: connection arguments:
    - username: username for authentication (optional)
    - password: password for authentication. If username is given and password isn't,
      it's asked from tty.
    - auth_database: authenticate the username and password against that database (optional).
      If not specified, the database specified in address will be used.
    - ssl, ssl_certfile, ssl_keyfile, ssl_cert_reqs, ssl_ca_certs: SSL authentication options
    :return: a tuple with ``(client, db)``
    """
    try:
        host,  port, dbname = get_res_address(address)
    except AddressError as e:
        error_parsing(str(e).replace("resource", "database"))

    try:
        options = {}
        if args.ssl:
            options["ssl"] = True
            options["ssl_certfile"] = args.ssl_cert_file
            options["ssl_keyfile"] = args.ssl_key_file
            options["ssl_cert_reqs"] = args.ssl_cert_reqs
            options["ssl_ca_certs"] = args.ssl_ca_certs

        client = MongoClient(host=host, port=port, **options)
    except Exception as e:
        error("Error trying to connect: %s" % str(e), ECONNREFUSED)

    username = args.username
    password = args.password
    auth_database = args.auth_database

    if username:
        if password is None:
            password = getpass.getpass()
        if auth_database is None:
            auth_database = dbname
        try:
            auth_db = client[auth_database]
            auth_db.authenticate(username, password)
        except Exception as e:
            error("Error trying to authenticate: %s" % str(e), -3)
    db = client[dbname]
    return client, db
def connect(address, args):
    """
    Connect with `address`, and return a tuple with a :class:`~pymongo.MongoClient`,
    and a :class:`~pymongo.database.Database` object.
    :param address: a string representation with the db address
    :param args: connection arguments:
    - username: username for authentication (optional)
    - password: password for authentication. If username is given and password isn't,
      it's asked from tty.
    - auth_database: authenticate the username and password against that database (optional).
      If not specified, the database specified in address will be used.
    - ssl, ssl_certfile, ssl_keyfile, ssl_cert_reqs, ssl_ca_certs: SSL authentication options
    :return: a tuple with ``(client, db)``
    """
    try:
        host,  port, dbname = get_res_address(address)
    except AddressError as e:
        error_parsing(str(e).replace("resource", "database"))

    try:
        options = {}
        if args.ssl:
            options["ssl"] = True
            options["ssl_certfile"] = args.ssl_cert_file
            options["ssl_keyfile"] = args.ssl_key_file
            options["ssl_cert_reqs"] = args.ssl_cert_reqs
            options["ssl_ca_certs"] = args.ssl_ca_certs

        client = MongoClient(host=host, port=port, **options)
    except Exception as e:
        error("Error trying to connect: %s" % str(e), ECONNREFUSED)

    username = args.username
    password = args.password
    auth_database = args.auth_database

    if username:
        if password is None:
            password = getpass.getpass()
        if auth_database is None:
            auth_database = dbname
        try:
            auth_db = client[auth_database]
            auth_db.authenticate(username, password)
        except Exception as e:
            error("Error trying to authenticate: %s" % str(e), -3)
    db = client[dbname]
    return client, db
def connect ( address , args ) : try : host , port , dbname = get_res_address ( address ) except AddressError as e : error_parsing ( str ( e ) . replace ( "resource" , "database" ) ) try : options = { } if args . ssl : options [ "ssl" ] = True options [ "ssl_certfile" ] = args . ssl_cert_file options [ "ssl_keyfile" ] = args . ssl_key_file options [ "ssl_cert_reqs" ] = args . ssl_cert_reqs options [ "ssl_ca_certs" ] = args . ssl_ca_certs client = MongoClient ( host = host , port = port , * * options ) except Exception as e : error ( "Error trying to connect: %s" % str ( e ) , ECONNREFUSED ) username = args . username password = args . password auth_database = args . auth_database if username : if password is None : password = getpass . getpass ( ) if auth_database is None : auth_database = dbname try : auth_db = client [ auth_database ] auth_db . authenticate ( username , password ) except Exception as e : error ( "Error trying to authenticate: %s" % str ( e ) , - 3 ) db = client [ dbname ] return client , db
Connect with `address`, and return a tuple with a :class:`~pymongo.MongoClient`,
    and a :class:`~pymongo.database.Database` object.
    :param address: a string representation with the db address
    :param args: connection arguments:
    - username: username for authentication (optional)
    - password: password for authentication. If username is given and password isn't,
      it's asked from tty.
    - auth_database: authenticate the username and password against that database (optional).
      If not specified, the database specified in address will be used.
    - ssl, ssl_certfile, ssl_keyfile, ssl_cert_reqs, ssl_ca_certs: SSL authentication options
    :return: a tuple with ``(client, db)``
Connect with address and return a tuple with a : class : ~pymongo . MongoClient and a : class : ~pymongo . database . Database object . : param address : a string representation with the db address : param args : connection arguments : - username : username for authentication ( optional ) - password : password for authentication . If username is given and password isn t it s asked from tty . - auth_database : authenticate the username and password against that database ( optional ) . If not specified the database specified in address will be used . - ssl ssl_certfile ssl_keyfile ssl_cert_reqs ssl_ca_certs : SSL authentication options : return : a tuple with ( client db )