<commit_before>var net = require('net');
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;

module.exports = Nut;

function Nut (port, host)
{
	EventEmitter.call(this);
	Nut.init.call(this, port, host);
}

inherits(Nut, EventEmitter);

Nut.init = function (port, host) {
	this._port = port;
	this._host = host;
};

Nut.prototype.start = function () {
	var self = this;
	self.status = 'idle';

	function open () { self.emit('ready'); }
	function error (err) { self.emit('error', err); }
	function close () { self.emit('close'); }

	this._client = net.createConnection (self._port, self._host, open);
	this._client.setEncoding('ascii');

	this._client.on('data', function (data) {
		if (typeof(self.parseFunc) !== 'undefined') {
			self.parseFunc(data);
		}
		else {
			self.status = 'idle';
		}
	});

	this._client.on('error', error);
	this._client.on('close', close);
};

Nut.prototype.send = function (cmd, parseFunc) {
	if (this.status == 'idle') {
		this.status = 'waiting';
		this.parseFunc = parseFunc;
		this._client.write(cmd + '\n');
	}
};

Nut.prototype.close = function () {
	this.send('LOGOUT');
};

function parseKeyValueList(data, list_type, re, callback) {
    var data_array = data.split('\n');
    for (i = 0; i < data_array.length-1; i++) {
        line = data_array[i];
        if (line.indexOf('BEGIN LIST ' + list_type) === 0) {
            vars = [];
        }<commit_msg>end connection on close<commit_after>var net = require('net');
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;

module.exports = Nut;

function Nut (port, host)
{
	EventEmitter.call(this);
	Nut.init.call(this, port, host);
}

inherits(Nut, EventEmitter);

Nut.init = function (port, host) {
	this._port = port;
	this._host = host;
};

Nut.prototype.start = function () {
	var self = this;
	self.status = 'idle';

	function open () { self.emit('ready'); }
	function error (err) { self.emit('error', err); }
	function close () { self.emit('close'); }

	this._client = net.createConnection (self._port, self._host, open);
	this._client.setEncoding('ascii');

	this._client.on('data', function (data) {
		if (typeof(self.parseFunc) !== 'undefined') {
			self.parseFunc(data);
		}
		else {
			self.status = 'idle';
		}
	});

	this._client.on('error', error);
	this._client.on('close', close);
};

Nut.prototype.send = function (cmd, parseFunc) {
	if (this.status == 'idle') {
		this.status = 'waiting';
		this.parseFunc = parseFunc;
		this._client.write(cmd + '\n');
	}
};

Nut.prototype.close = function () {
	this.send('LOGOUT');
    this._client.end();
};

function parseKeyValueList(data, list_type, re, callback) {
    var data_array = data.split('\n');
    for (i = 0; i < data_array.length-1; i++) {
        line = data_array[i];
        if (line.indexOf('BEGIN LIST ' + list_type) === 0) {
            vars = [];
        }
{'fraction_non_alphanumeric': 0.18698347107438015, 'fraction_numerical': 0.002066115702479339, 'mean_word_length': 3.6930533117932147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3159491', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1026, 'n_words': 214}