<commit_before>import re


class RequestBase(object):
    pass


class Address(object):

    _validators = {'address': r'^(.{1,200})$',
                   'city': r'^(.{1,20})$',
                   'postal_code': r'^([\d -]{1,10})$',
                   'first_name': r'^(.{0,20})$',
                   'last_name': r'^(.{0,20})$',
                   'phone': r'^([\d\+\-\(\) ]{5,19})$|^$',
                   'country_code': r'^.{0,10}$',
                   }

    def __init__(self, address, city, postal_code,
                 first_name=None, last_name=None, phone=None,
                 country_code=None):

        self.address = address
        self.city = city
        self.postal_code = postal_code
        self.first_name = first_name
        self.last_name = last_name
        self.phone = phone
        self.country_code = country_code

        super(Address, self).__init__()

    def validate_attr(self, name, value, pattern):
        if not re.match(pattern, value, re.DOTALL):
            raise ValueError(
                "{attr_name} did not pass validation. ("
                "Expression: {validation_expr} | "
                "Value: {attr_value})".format(
                    attr_name=name,
                    validation_expr=pattern,
                    attr_value=value))

    def validate_all(self):
        ''' Validates all of the current instance's properties.
        If one of the instances does not validate, then a ValueError
        will be thrown on the first failure.
        '''
        for attr_name in self._validators:
            # in the event of None, we're switching to "" to validate
            value = getattr(attr_name) or ''
            validator = self._validators[attr_name]
            self.validate_attr('attr_name', value, validator)<commit_msg>Refactored request entity validation logic into a base class<commit_after>import re


class RequestEntityBase(object):

    def validate_attr(self, name, value, pattern):
        if not re.match(pattern, value, re.DOTALL):
            raise ValueError(
                "{attr_name} did not pass validation. ("
                "Expression: {validation_expr} | "
                "Value: {attr_value})".format(
                    attr_name=name,
                    validation_expr=pattern,
                    attr_value=value))

    def validate_all(self):
        ''' Validates all of the current instance's properties.
        If one of the instances does not validate, then a ValueError
        will be thrown on the first failure.
        '''
        for attr_name in self._validators:
            # in the event of None, we're switching to "" to validate
            value = getattr(attr_name) or ''
            validator = self._validators[attr_name]
            self.validate_attr('attr_name', value, validator)


class Address(RequestEntityBase):

    _validators = {'address': r'^(.{1,200})$',
                   'city': r'^(.{1,20})$',
                   'postal_code': r'^([\d -]{1,10})$',
                   'first_name': r'^(.{0,20})$',
                   'last_name': r'^(.{0,20})$',
                   'phone': r'^([\d\+\-\(\) ]{5,19})$|^$',
                   'country_code': r'^.{0,10}$',
                   }

    def __init__(self, address, city, postal_code,
                 first_name=None, last_name=None, phone=None,
                 country_code=None):

        self.address = address
        self.city = city
        self.postal_code = postal_code
        self.first_name = first_name
        self.last_name = last_name
        self.phone = phone
        self.country_code = country_code

        super(Address, self).__init__()
{'fraction_non_alphanumeric': 0.12866137421297563, 'fraction_numerical': 0.012044894607172188, 'mean_word_length': 1.815100154083205, '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': '5275688', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1015, 'n_words': 250}