<commit_before># -*- coding: utf-8 -*-
"""
    validators.py
    ~~~~~~
        
    :copyright: (c) 2012 by <NAME>
    :license: BSD (See LICENSE for details)
""" 
# Imports outside Bombolone
import re

class GetValue(object):
    
    def __init__(self, dictionary):
        self.dictionary = dictionary
        
    def check_key(self, key):
        try:
            value = self.dictionary[key]
            return value
        except KeyError:
            return ''  
             
class CheckValue(object):
    
    def __init__(self):
        pass
        
    def length(self, data, minimum=-1, maximum=-1):
        """
        Validates the length of a string

        :param min: The minimum required length of the string. 
        :param max: The maximum length of the string
        """
        len_input = len(data)

        if len_input < minimum or maximum != -1 and len_input > maximum:
            return False
        return True
        
    def regexp(self, data, regex, flags=0):
        """
        Validates the data with regexp

        :param regex: The regular expression string to use. 
        :param flags: The regexp flags eg. re.I (case-insensitive)
        """
        regex = re.compile(regex, flags)
        if regex.match(data):
            return True
        return False
    
    def username(self, data):
        """
        Validates the username 

        :param username: The string  
        """
        regex = re.compile(r'^[a-z0-9_]+$', re.I)
        if regex.match(data):
            return True
        return False
    
    def full_name(self, data):
        """
        Validates the full name 

        :param full_name: The string  
        """
        regex = re.compile(r'^[a-z\' ]+$', re.I)
        if regex.match(data):
            return True
        return False
    
    def email(self, data):
        """
        Validates the email 

        :param email: The string  
        """
        regex = re.compile(r'^.+@[^.].*\.[a-z]{2,10}$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False
    
    def url(self, data):
        """
        Validates the url 

        :param url: The string  
        """
        regex = re.compile(ur'^[a-z]+://([^/:]+%s|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]+)?(\/.*)?$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False
        
    def url_two(self, data):
        """
        Validates the url 

        :param url: The string  
        """
        regex = re.compile(r'^[\w\-\.]+[^#?\s]+$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False<commit_msg>Improved check_key in GetValue.<commit_after># -*- coding: utf-8 -*-
"""
    validators.py
    ~~~~~~
        
    :copyright: (c) 2012 by <NAME>
    :license: BSD (See LICENSE for details)
""" 
# Imports outside Bombolone
import re

class GetValue(object):
    
    def __init__(self, dictionary):
        self.dictionary = dictionary
        
    def check_key(self, key):
        return self.dictionary.get(key, '')
             
class CheckValue(object):
    
    def __init__(self):
        pass
        
    def length(self, data, minimum=-1, maximum=-1):
        """
        Validates the length of a string

        :param min: The minimum required length of the string. 
        :param max: The maximum length of the string
        """
        len_input = len(data)

        if len_input < minimum or maximum != -1 and len_input > maximum:
            return False
        return True
        
    def regexp(self, data, regex, flags=0):
        """
        Validates the data with regexp

        :param regex: The regular expression string to use. 
        :param flags: The regexp flags eg. re.I (case-insensitive)
        """
        regex = re.compile(regex, flags)
        if regex.match(data):
            return True
        return False
    
    def username(self, data):
        """
        Validates the username 

        :param username: The string  
        """
        regex = re.compile(r'^[a-z0-9_]+$', re.I)
        if regex.match(data):
            return True
        return False
    
    def full_name(self, data):
        """
        Validates the full name 

        :param full_name: The string  
        """
        regex = re.compile(r'^[a-z\' ]+$', re.I)
        if regex.match(data):
            return True
        return False
    
    def email(self, data):
        """
        Validates the email 

        :param email: The string  
        """
        regex = re.compile(r'^.+@[^.].*\.[a-z]{2,10}$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False
    
    def url(self, data):
        """
        Validates the url 

        :param url: The string  
        """
        regex = re.compile(ur'^[a-z]+://([^/:]+%s|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]+)?(\/.*)?$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False
        
    def url_two(self, data):
        """
        Validates the url 

        :param url: The string  
        """
        regex = re.compile(r'^[\w\-\.]+[^#?\s]+$', re.IGNORECASE)
        if regex.match(data):
            return True
        return False
        
    def integer(self, data):
        """ """
        try:
            tmp = int(data)
            return True
        except:
            return False
    
    def float(self, data):
        """ """
        try:
            tmp = float(data)
            return True
        except:
            return False
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.008608815426997245, 'mean_word_length': 1.3836684448091916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1629664', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1656, 'n_words': 452}