<commit_before>//- JavaScript source code

//- service.js ~~
//                                                      ~~ (c) SRW, 10 Nov 2012
//                                                  ~~ last updated 12 Nov 2012

(function () {
    'use strict';

 // Pragmas

    /*jslint indent: 4, maxlen: 80, node: true */

 // Declarations

    var cluster, configure, corser, http, launch_service, RESTful_Service,
        restful_service;

 // Definitions

    cluster = require('cluster');

    configure = function (user_input, default_values) {
     // This function needs documentation.
        if ((user_input instanceof Object) === false) {
            user_input = {};
        }
        var key, y;
        y = (default_values instanceof Array) ? [] : {};
        for (key in default_values) {
            if (default_values.hasOwnProperty(key)) {
                if (user_input.hasOwnProperty(key)) {
                    y[key] = user_input[key];
                } else {
                    y[key] = default_values[key];
                }
            }
        }
        return y;
    };

    corser = require('corser');

    http = require('http');

    launch_service = function (obj) {
     // This function needs documentation.
        var backends, config, defs_api, defs_www, i, prepost, service;
        backends = ['couch', 'mongo', 'postgres', 'sqlite'];
        config = configure(obj, {
            api:            {},
            hostname:       '0.0.0.0',
            max_fu_size:    1048576,    //- 1024 * 1024 bytes = 1 Megabyte
            max_sockets:    500,
            max_workers:    1,
            port:           8177,
            public_html:    'public_html/',
            www:            {}
        });
        prepost = function (f) {
         // This function is a higher-order wrapper function that simplifies
         // the implementation of the `post_box_key` methods.
            return function (request, response, params) {
             // This function needs documentation.
                var fu_size;
                if (request.headers.hasOwnProperty('content-length')) {
                    fu_size = request.headers['content-length'];
                    if (fu_size < config.max_fu_size) {
                        return f(request, response, params);
                    }
                }
             // If we land here, then the user is either using incorrect
             // headers or he/she is uploading a file that is too big. Don't
             // fool with it either way. QMachine is not a free hard drive for
             // people who are too cheap to buy storage, because we didn't buy
             // storage, either ;-)
                response.writeHead(444);
                response.end();
                return;
            };
        };
        service = restful_service();
        service.def({
            method: 'OPTIONS',
            pattern: /^\//,
            handler: function (request, response) {
             // This function needs documentation.
                response.writeHead(204);
                response.end();
                return;
            }
        });
        for (i = 0; i < backends.length; i += 1) {
            if ((config.api instanceof Object) &&
                    (config.api.hasOwnProperty(backends[i]))) {
             // This arm needs documentation.
                defs_api = require('./defs-' + backends[i])
                    .init(config.api[backends[i]]);
                service.def({
                    method:     'GET',
                    pattern:    /^\/box\/([\w\-]+)\?key=([A-z0-9]+)$/,
                    handler:    defs_api.get_box_key
                });
                service.def({
                    method:     'GET',
                    pattern:    /^\/box\/([\w\-]+)\?status=([A-z0-9]+)$/,
                    handler:    defs_api.get_box_status
                });
                service.def({
                    method:     'POST',
                    pattern:    /^\/box\/([\w\-]+)\?key=([A-z0-9]+)$/,
                    handler:    prepost(defs_api.post_box_key)
                });
            }
            if ((config.www instanceof Object) &&
                    (config.www.hasOwnProperty(backends[i]))) {
             // This arm needs documentation.
                defs_www = require('./defs-' + backends[i])
                    .init(config.www[backends[i]]);
                service.def({
                    method:     'GET',
                    pattern:    /^\//,
                    handler:    defs_www.get_static_content
                });
                defs_www.set_static_content(config.public_html);
            }
        }
        if (service.rules.length > 1) {
            service.launch(config);
        } else {
            console.log('No servers were specified.');
        }
        return;
    };

    RESTful_Service = function RESTful_Service() {
     // This function needs documentation.
        var that = this;
        that.rules = [];
        return that;
    };

    restful_service = function (obj) {
     // This function needs documentation.
        return new RESTful_Service(obj);
    };

 // Prototype definitions

    RESTful_Service.prototype.def = function (obj) {
     // This function needs documentation.
        //  1.  Validate input.
        //  2.  Ensure the rule hasn't already been added. (TO-DO!)
        //  3.  Add the rule.
        if ((obj instanceof Object) === false) {<commit_msg>Comments to keep me from outsmarting myself in the future<commit_after>//- JavaScript source code

//- service.js ~~
//                                                      ~~ (c) SRW, 10 Nov 2012
//                                                  ~~ last updated 13 Nov 2012

(function () {
    'use strict';

 // Pragmas

    /*jslint indent: 4, maxlen: 80, node: true */

 // Declarations

    var cluster, configure, corser, http, launch_service, RESTful_Service,
        restful_service;

 // Definitions

    cluster = require('cluster');

    configure = function (user_input, default_values) {
     // This function needs documentation.
        if ((user_input instanceof Object) === false) {
            user_input = {};
        }
        var key, y;
        y = (default_values instanceof Array) ? [] : {};
        for (key in default_values) {
            if (default_values.hasOwnProperty(key)) {
                if (user_input.hasOwnProperty(key)) {
                    y[key] = user_input[key];
                } else {
                    y[key] = default_values[key];
                }
            }
        }
        return y;
    };

    corser = require('corser');

    http = require('http');

    launch_service = function (obj) {
     // This function needs documentation.
        var backends, config, defs_api, defs_www, i, prepost, service;
        backends = ['couch', 'mongo', 'postgres', 'sqlite'];
        config = configure(obj, {
            api:            {},
            hostname:       '0.0.0.0',
            max_fu_size:    1048576,    //- 1024 * 1024 bytes = 1 Megabyte
            max_sockets:    500,
            max_workers:    1,
            port:           8177,
            public_html:    'public_html/',
            www:            {}
        });
        prepost = function (f) {
         // This function is a higher-order wrapper function that simplifies
         // the implementation of the `post_box_key` methods.
            return function (request, response, params) {
             // This function needs documentation.
                var fu_size;
                if (request.headers.hasOwnProperty('content-length')) {
                    fu_size = request.headers['content-length'];
                    if (fu_size < config.max_fu_size) {
                        return f(request, response, params);
                    }
                }
             // If we land here, then the user is either using incorrect
             // headers or he/she is uploading a file that is too big. Don't
             // fool with it either way. QMachine is not a free hard drive for
             // people who are too cheap to buy storage, because we didn't buy
             // storage, either ;-)
                response.writeHead(444);
                response.end();
                return;
            };
        };
        service = restful_service();
        service.def({
            method: 'OPTIONS',
            pattern: /^\//,
            handler: function (request, response) {
             // This function needs documentation.
                response.writeHead(204);
                response.end();
                return;
            }
        });
        for (i = 0; i < backends.length; i += 1) {
            if ((config.api instanceof Object) &&
                    (config.api.hasOwnProperty(backends[i]))) {
             // This arm needs documentation.
                defs_api = require('./defs-' + backends[i])
                    .init(config.api[backends[i]]);
                service.def({
                    method:     'GET',
                    pattern:    /^\/box\/([\w\-]+)\?key=([A-z0-9]+)$/,
                    handler:    defs_api.get_box_key
                });
                service.def({
                    method:     'GET',
                    pattern:    /^\/box\/([\w\-]+)\?status=([A-z0-9]+)$/,
                    handler:    defs_api.get_box_status
                });
                service.def({
                    method:     'POST',
                    pattern:    /^\/box\/([\w\-]+)\?key=([A-z0-9]+)$/,
                    handler:    prepost(defs_api.post_box_key)
                });
            }
            if ((config.www instanceof Object) &&
                    (config.www.hasOwnProperty(backends[i]))) {
             // This arm needs documentation.
                defs_www = require('./defs-' + backends[i])
                    .init(config.www[backends[i]]);
                service.def({
                    method:     'GET',
                    pattern:    /^\//,
                    handler:    defs_www.get_static_content
                });
             // NOTE: Don't try to streamline the initial static content load
             // by restricting it to `cluster.isMaster` -- it doesn't seem to
             // work with SQLite in-memory databases.
                defs_www.set_static_content(config.public_html);
            }
        }
        if (service.rules.length > 1) {
            service.launch(config);
        } else {
            console.log('No servers were specified.');
        }
        return;
    };

    RESTful_Service = function RESTful_Service() {
     // This function needs documentation.
        var that = this;
        that.rules = [];
        return that;
    };

    restful_service = function (obj) {
     // This function needs documentation.
        return new RESTful_Service(obj);
    };

 // Prototype definitions

    RESTful_Service.prototype.def = function (obj) {
     // This function needs documentation.
        //  1.  Validate input.
        //  2.  Ensure the rule hasn't already been added. (TO-DO!)
        //  3.  Add the rule.
        if ((obj instanceof Object) === false) {
{'fraction_non_alphanumeric': 0.11797153024911032, 'fraction_numerical': 0.010854092526690392, 'mean_word_length': 1.2681598062953996, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6250548', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2880, 'n_words': 739}