<commit_before>/***/
var util = require('util'), events = require('events'), crypto = require('crypto');
var fs = require('fs'), URL = require('url'), path = require('path');

var STATE = {
  CONNECTING: 0,
  OPEN: 1,
  CLOSING: 2,
  CLOSED: 3
};

module.exports = exports = WebSocket;

var EVTS = ['close', '_closing', 'connect', 'error', 'message'], length = EVTS.length;

function WebSocket() {
  //req, socket, upgradeHead, opts
  var self = this;
  events.EventEmitter.call(self);

  self.readyState = STATE.CONNECTING;

  self.on('error', function(err) {
    self.close(err && err.message);
    if('function' === typeof self.onerror)
      self.onerror(err);
  });

  self.on('close', function(reason) {
    self.readyState = STATE.CLOSED;
    if('function' === typeof self.onclose)
      self.onclose(reason);
  });

  self.on('open', function(evt) {
    self.readyState = STATE.OPEN;
    if('function' === typeof self.onopen)
      self.onopen(evt);
  });

  self.on('message', function(evt) {
    if('function' === typeof self.onmessage)
      self.onmessage(evt);
  });

  self.on('_closing', function(reason) {
    self.readyState = STATE.CLOSING;
    process.nextTick(function() {
      close.call(self, reason);
    });
  });

  self.on('connect', function(evt) {
    self.emit('open', evt);
  });

  var args = arguments;<commit_msg>add WebSocket readyStates<commit_after>/***/
var util = require('util'), events = require('events'), crypto = require('crypto');
var fs = require('fs'), URL = require('url'), path = require('path');

var State = {
  CONNECTING: 0,
  OPEN: 1,
  CLOSING: 2,
  CLOSED: 3
};

module.exports = exports = WebSocket;
for( var i in State)
  WebSocket[i] = State[i];

var EVTS = ['close', '_closing', 'connect', 'error', 'message'], length = EVTS.length;

function WebSocket() {
  //req, socket, upgradeHead, opts
  var self = this;
  events.EventEmitter.call(self);

  self.readyState = State.CONNECTING;

  self.on('error', function(err) {
    self.close(err && err.message);
    if('function' === typeof self.onerror)
      self.onerror(err);
  });

  self.on('close', function(reason) {
    self.readyState = State.CLOSED;
    if('function' === typeof self.onclose)
      self.onclose(reason);
  });

  self.on('open', function(evt) {
    self.readyState = State.OPEN;
    if('function' === typeof self.onopen)
      self.onopen(evt);
  });

  self.on('message', function(evt) {
    if('function' === typeof self.onmessage)
      self.onmessage(evt);
  });

  self.on('_closing', function(reason) {
    self.readyState = State.CLOSING;
    process.nextTick(function() {
      close.call(self, reason);
    });
  });

  self.on('connect', function(evt) {
    self.emit('open', evt);
  });

  var args = arguments;
{'fraction_non_alphanumeric': 0.18736383442265794, 'fraction_numerical': 0.002904865649963689, 'mean_word_length': 3.584026622296173, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1247282', 'n_tokens_mistral': 954, 'n_tokens_neox': 935, 'n_words': 194}