示例#1
0
    def __init__(self, dbName, broker, username, password, options):
        """Constructor for the Connection class.
        
        Arguments:
        dbName -- Name of database you are accessing.
        broker -- Address of the broker you are connecting too.
        username -- NuoDB username.
        password -- NuoDB password.
        options -- A dictionary of NuoDB connection options
            Some common options include:
            "schema"
        
        Returns:
        a Connection instance

        @type dbName str
        @type broker str
        @type username str
        @type password str
        @type options dict[str,str]
        """
        (host, port) = getCloudEntry(broker, dbName)
        self.__session = EncodedSession(host, port)
        self._trans_id = None

        cp = ClientPassword()

        parameters = {'user': username, 'timezone': time.strftime('%Z')}
        if options:
            parameters.update(options)

        version, serverKey, salt = self.__session.open_database(
            dbName, parameters, cp)

        sessionKey = cp.computeSessionKey(string.upper(username), password,
                                          salt, serverKey)
        self.__session.setCiphers(RC4Cipher(sessionKey), RC4Cipher(sessionKey))

        self.__session.check_auth()

        # set auto commit to false by default per PEP
        self.__session.set_autocommit(0)