<commit_before>var _          = require('_'),
    overload   = require('overload'),
    O          = overload.O,

    _SUPPORTS  = require('../supports'),
    _NODE_TYPE = require('../nodeType'),

    _utils     = require('../utils'),
    _cache     = require('../cache'),

    _selector  = require('./Fizzle/selector/selector-parse'),

    _isDataKeyCache       = _cache(),
    _sanitizeDataKeyCache = _cache(),
    _trimDataKeyCache     = _cache(),
    _attrNameLowerCache   = _cache();

var _isDataKey = function(key) {
        return _isDataKeyCache.getOrSet(key, function() {
            return (key || '').substr(0, 5) === 'data-';
        });
    },

    _sanitizeDataKey = function(key) {
        return _sanitizeDataKeyCache.getOrSet(key, function() {
            return _isDataKey(key) ? key : 'data-' + key.toLowerCase();
        });
    },

    _trimDataKey = function(key) {
        return _trimDataKeyCache.getOrSet(key, function() {
            return key.substr(0, 5);
        });
    },

    _getDataAttrKeys = function(elem) {
        var attrs = elem.attributes,
            idx   = attr.length, keys = [];
        while (idx--) {
            key = attrs[idx];
            if (_isDataKey(key)) {
                keys.push(key);
            }
        }

        return keys;
    };

var _boolHook = {
    is: function(attrName) {
        return _selector.isBooleanAttribute(attrName);
    },
    get: function(elem, attrName) {
        if (elem.hasAttribute(attrName)) {
            return _attrNameLowerCache.getOrSet(attrName, function() {
                return attrName.toLowerCase();
            });
        }
        return undefined;
    },
    set: function(elem, value, attrName) {
        if (value === false) {
            // Remove boolean attributes when set to false
            return elem.removeAttribute(attrName);
        }

        elem.setAttribute(attrName, attrName);
    }
};

var _hooks = {
        tabindex: {
            get: function(elem) {
                var tabindex = elem.getAttribute('tabindex');
                if (!_.exists(tabindex) || tabindex === '') { return; }
                return tabindex;
            }
        },

        type: {
            set: function(elem, value) {
                if (!_SUPPORTS.radioValue && value === 'radio' && _utils.isNodeName(elem, 'input')) {
                    // Setting the type on a radio button after the value resets the value in IE6-9
                    // Reset value to default in case type is set after value during creation
                    var oldValue = elem.value;
                    elem.setAttribute('type', value);
                    if (oldValue) { elem.value = oldValue; }
                }
            }
        },

        value: {
            get: function(elem) {
                var val = elem.value;
                if (val === null || val === undefined) {
                    val = elem.getAttribute('value');
                }
                return _utils.normalizeNewlines(val);
            },
            set: function(elem, value) {
                elem.setAttribute('value', value);
            }
        }
    },

    _isElementNode = function(elem) {
        return elem && elem.nodeType === _NODE_TYPE.ELEMENT;
    },

    _getAttribute = function(elem, attr) {
        if (!_isElementNode(elem) || !elem.hasAttribute(attr)) { return; }

        if (_boolHook.is(attr)) {
            return _boolHook.get(elem, attr);
        }
<commit_msg>Fixed failing tests<commit_after>var _          = require('_'),
    overload   = require('overload'),
    O          = overload.O,

    _SUPPORTS  = require('../supports'),
    _NODE_TYPE = require('../nodeType'),

    _utils     = require('../utils'),
    _cache     = require('../cache'),

    _selector  = require('./Fizzle/selector/selector-parse'),

    _isDataKeyCache       = _cache(),
    _sanitizeDataKeyCache = _cache(),
    _trimDataKeyCache     = _cache(),
    _attrNameLowerCache   = _cache();

var _isDataKey = function(key) {
        return _isDataKeyCache.getOrSet(key, function() {
            return (key || '').substr(0, 5) === 'data-';
        });
    },

    _sanitizeDataKey = function(key) {
        return _sanitizeDataKeyCache.getOrSet(key, function() {
            return _isDataKey(key) ? key : 'data-' + key.toLowerCase();
        });
    },

    _trimDataKey = function(key) {
        return _trimDataKeyCache.getOrSet(key, function() {
            return key.substr(0, 5);
        });
    },

    _getDataAttrKeys = function(elem) {
        var attrs = elem.attributes,
            idx   = attr.length, keys = [];
        while (idx--) {
            key = attrs[idx];
            if (_isDataKey(key)) {
                keys.push(key);
            }
        }

        return keys;
    };

var _boolHook = {
    is: function(attrName) {
        return _selector.isBooleanAttribute(attrName);
    },
    get: function(elem, attrName) {
        if (elem.hasAttribute(attrName)) {
            return _attrNameLowerCache.getOrSet(attrName, function() {
                return attrName.toLowerCase();
            });
        }
        return undefined;
    },
    set: function(elem, value, attrName) {
        if (value === false) {
            // Remove boolean attributes when set to false
            return elem.removeAttribute(attrName);
        }

        elem.setAttribute(attrName, attrName);
    }
};

var _hooks = {
        tabindex: {
            get: function(elem) {
                var tabindex = elem.getAttribute('tabindex');
                if (!_.exists(tabindex) || tabindex === '') { return; }
                return tabindex;
            }
        },

        type: {
            set: function(elem, value) {
                if (!_SUPPORTS.radioValue && value === 'radio' && _utils.isNodeName(elem, 'input')) {
                    // Setting the type on a radio button after the value resets the value in IE6-9
                    // Reset value to default in case type is set after value during creation
                    var oldValue = elem.value;
                    elem.setAttribute('type', value);
                    elem.value = oldValue;
                }
                else {
                    elem.setAttribute('type', value);
                }
            }
        },

        value: {
            get: function(elem) {
                var val = elem.value;
                if (val === null || val === undefined) {
                    val = elem.getAttribute('value');
                }
                return _utils.normalizeNewlines(val);
            },
            set: function(elem, value) {
                elem.setAttribute('value', value);
            }
        }
    },

    _isElementNode = function(elem) {
        return elem && elem.nodeType === _NODE_TYPE.ELEMENT;
    },

    _getAttribute = function(elem, attr) {
        if (!_isElementNode(elem) || !elem.hasAttribute(attr)) { return; }

        if (_boolHook.is(attr)) {
            return _boolHook.get(elem, attr);
        }

{'fraction_non_alphanumeric': 0.12771700525642846, 'fraction_numerical': 0.001704787611876687, 'mean_word_length': 1.6083734716561688, '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': '1506216', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1947, 'n_words': 413}