<commit_before>var logger = require('winston'),
    EventEmitter = require('events').EventEmitter,
    assert = require("assert"),
    util = require('util'),
    auth = require('./lib/auth.js'),
    metadata = require('./lib/metadata.js'),
    search = require('./lib/search.js'),
    update = require('./lib/update.js'),
    object = require('./lib/object.js');

var KEY_MEMBER_NAME = "MemberName";
var KEY_USER = "User";
var KEY_BROKER = "Broker";
var KEY_LOGIN = "Login";
var KEY_LOGOUT = "Logout";
var KEY_SEARCH = "Search";
var KEY_ACTION = "Action";
var KEY_UPDATE = "Update";
var KEY_GET_OBJECT = "GetObject";
var KEY_POST_OBJECT = "PostObject";
var KEY_GET_METADATA = "GetMetadata";
var KEY_METADATA_VERSION = "MetadataVersion";
var KEY_METADATA_TIMESTAMP = "MetadataTimestamp";
var KEY_MIN_METADATA_TIMESTAMP = "MinMetadataTimestamp";
var KEY_RETS_VERSION = "retsVersion";
var KEY_RETS_SERVER = "retsServer";

module.exports = new EventEmitter();

/**
 * Connects to a RETS Service and creates a RETS client instance.
 *
 * Using a hash:
 * @param settings.loginUrl RETS login URL (i.e http://<MLS_DOMAIN>/rets/login.ashx)
 * @param settings.username username credential
 * @param settings.password <PASSWORD>
 * @param settings.userAgent the user-agent to use
 * @param settings.userAgentPassword the user-agent password to use
 * @param settings.version the RETS version
 *
 * OR using discrete arguments (preserve backward compatibility):
 * @param loginUrl RETS login URL (i.e http://<MLS_DOMAIN>/rets/login.ashx)
 * @param username username credential
 * @param password <PASSWORD>
 *
 * @event connection.success Connection succeeded.
 * @event connection.failure(error) Failed to connect.
 *
 * @return RETS Client
 */
module.exports.getClient = function(settings) {

    var settings = (typeof settings === 'object') ? settings : {};
    if (arguments.length === 3) {
        settings.loginUrl = arguments[0];
        settings.username = arguments[1];
        settings.password = arguments[2];
    }

    var client = new Client();

    auth.login(settings, function(error, systemData) {
        if (error) {

            client.emit('connection.failure', error);

            return;
        }

        client.configure(systemData);

        client.emit('connection.success');
    });

    return client;
};

/**
 * RETS Client Object
 *
 * @constructor Creates a new RETS Client object.
 */
var Client = function Client() {};

/** Rets Client inherits from EventEmitter **/
util.inherits(Client, EventEmitter);

/**
 * Configures Rets Client
 * @param systemData RETS system URL data object (Login, GetMetadata, GetObject, etc.)
 */
Client.prototype.configure = function(systemData) {

    var self = this;

    self.systemData = systemData;

    self.retsVersion = self.systemData[KEY_RETS_VERSION];
    self.retsServer = self.systemData[KEY_RETS_SERVER];
    self.memberName = self.systemData[KEY_MEMBER_NAME];
    self.user = self.systemData[KEY_USER];
    self.broker = self.systemData[KEY_BROKER];
    self.metadataVersion = self.systemData[KEY_METADATA_VERSION];
    self.metadataTimestamp = self.systemData[KEY_METADATA_TIMESTAMP];
    self.minMetadataTimestamp = self.systemData[KEY_MIN_METADATA_TIMESTAMP];

    //metadata module
    self.metadataModule = metadata(self.systemData[KEY_GET_METADATA]);
    //search module
    self.searchModule = search(self.systemData[KEY_SEARCH]);
    //object module
    self.objectModule = object(self.systemData[KEY_GET_OBJECT]);
    //update module
    if (KEY_UPDATE in self.systemData) {
        self.updateModule = update(self.systemData[KEY_UPDATE]);
    }
};

/**
 * Private method that handles client interface logic.
 *
 * @param client The RETS client instance
 * @param error Error object (optional)
 * @param data The RETS data (optional)
 * @param eventSuccess Success event name (optional)
 * @param eventFailure Failure event name (optional)
 * @param callback Callback function (optional)
 */
var processRetsResponse = function(client, error, data, eventSuccess, eventFailure, callback) {

    assert(client, "Client is present");

    if (error) {
        if (callback)
            callback(error);

        if (eventFailure)
            client.emit(eventFailure, error);

        return;
    }
<commit_msg>Make sure to provide absolute URLs to sub-modules<commit_after>var logger = require('winston'),
    EventEmitter = require('events').EventEmitter,
    assert = require("assert"),
    util = require('util'),
    url = require('url'),
    auth = require('./lib/auth.js'),
    metadata = require('./lib/metadata.js'),
    search = require('./lib/search.js'),
    update = require('./lib/update.js'),
    object = require('./lib/object.js');

var KEY_MEMBER_NAME = "MemberName";
var KEY_USER = "User";
var KEY_BROKER = "Broker";
var KEY_LOGIN = "Login";
var KEY_LOGOUT = "Logout";
var KEY_SEARCH = "Search";
var KEY_ACTION = "Action";
var KEY_UPDATE = "Update";
var KEY_GET_OBJECT = "GetObject";
var KEY_POST_OBJECT = "PostObject";
var KEY_GET_METADATA = "GetMetadata";
var KEY_METADATA_VERSION = "MetadataVersion";
var KEY_METADATA_TIMESTAMP = "MetadataTimestamp";
var KEY_MIN_METADATA_TIMESTAMP = "MinMetadataTimestamp";
var KEY_RETS_VERSION = "retsVersion";
var KEY_RETS_SERVER = "retsServer";

module.exports = new EventEmitter();

/**
 * Connects to a RETS Service and creates a RETS client instance.
 *
 * Using a hash:
 * @param settings.loginUrl RETS login URL (i.e http://<MLS_DOMAIN>/rets/login.ashx)
 * @param settings.username username credential
 * @param settings.password <PASSWORD>
 * @param settings.userAgent the user-agent to use
 * @param settings.userAgentPassword the user-agent password to use
 * @param settings.version the RETS version
 *
 * OR using discrete arguments (preserve backward compatibility):
 * @param loginUrl RETS login URL (i.e http://<MLS_DOMAIN>/rets/login.ashx)
 * @param username username credential
 * @param password password <PASSWORD>
 *
 * @event connection.success Connection succeeded.
 * @event connection.failure(error) Failed to connect.
 *
 * @return RETS Client
 */
module.exports.getClient = function(settings) {

    var settings = (typeof settings === 'object') ? settings : {};
    if (arguments.length === 3) {
        settings.loginUrl = arguments[0];
        settings.username = arguments[1];
        settings.password = arguments[2];
    }

    var client = new Client();

    auth.login(settings, function(error, systemData) {
        if (error) {

            client.emit('connection.failure', error);

            return;
        }

        client.configure(settings.loginUrl, systemData);

        client.emit('connection.success');
    });

    return client;
};

/**
 * RETS Client Object
 *
 * @constructor Creates a new RETS Client object.
 */
var Client = function Client() {};

/** Rets Client inherits from EventEmitter **/
util.inherits(Client, EventEmitter);

/**
 * Configures Rets Client
 * @param systemData RETS system URL data object (Login, GetMetadata, GetObject, etc.)
 */
Client.prototype.configure = function(loginUrl, systemData) {

    var self = this;

    self.systemData = systemData;

    self.retsVersion = self.systemData[KEY_RETS_VERSION];
    self.retsServer = self.systemData[KEY_RETS_SERVER];
    self.memberName = self.systemData[KEY_MEMBER_NAME];
    self.user = self.systemData[KEY_USER];
    self.broker = self.systemData[KEY_BROKER];
    self.metadataVersion = self.systemData[KEY_METADATA_VERSION];
    self.metadataTimestamp = self.systemData[KEY_METADATA_TIMESTAMP];
    self.minMetadataTimestamp = self.systemData[KEY_MIN_METADATA_TIMESTAMP];

    //metadata module
    var metadataUrl = url.resolve(loginUrl, self.systemData[KEY_GET_METADATA]);
    self.metadataModule = metadata(metadataUrl);
    //search module
    var searchUrl = url.resolve(loginUrl, self.systemData[KEY_SEARCH]);
    self.searchModule = search(searchUrl);
    //object module
    var objectUrl = url.resolve(loginUrl, self.systemData[KEY_GET_OBJECT]);
    self.objectModule = object(objectUrl);
    //update module
    if (KEY_UPDATE in self.systemData) {
        var updateUrl = url.resolve(loginUrl, self.systemData[KEY_UPDATE]);
        self.updateModule = update(updateUrl);
    }
};

/**
 * Private method that handles client interface logic.
 *
 * @param client The RETS client instance
 * @param error Error object (optional)
 * @param data The RETS data (optional)
 * @param eventSuccess Success event name (optional)
 * @param eventFailure Failure event name (optional)
 * @param callback Callback function (optional)
 */
var processRetsResponse = function(client, error, data, eventSuccess, eventFailure, callback) {

    assert(client, "Client is present");

    if (error) {
        if (callback)
            callback(error);

        if (eventFailure)
            client.emit(eventFailure, error);

        return;
    }

{'fraction_non_alphanumeric': 0.1206470456077286, 'fraction_numerical': 0.0008986744551786115, 'mean_word_length': 3.838586956521739, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '578358', 'n_tokens_mistral': 2642, 'n_tokens_neox': 2588, 'n_words': 674}