<commit_before>import re
import string

class Interface(object):
    """
    Represents a physical interface on a switch.
    """
    def __init__(self, switch, identifier):
        """
        Construct a new Interface with the given `identifier` located on the given `switch`.
        """
        self.switch = switch
        self.identifier = identifier

    def _get_name(self):
        """
        Get the friendly name configured for this interface.
        """
        run_output = self.switch.execute_command("show running-config interface " + str(self.identifier))
        # Try to extract the interface name, which may also contain spaces. This is achieved by greedily matching
        # whitespace at the end of the line and matching the `   name ` prefix a the beginning and using whatever
        # remains of the string as the interface name. The `name` group is matched in a non-greedy fashion as to not
        # "eat up" all the following whitespace which is not part of the name.
        name_match = re.search(r"^   name \"(?P<name>.*?)\"\s*$", run_output, re.MULTILINE)
        # Only return the name of the interface if a name was found.
        if name_match:
            return name_match.group('name')
        # If no name was configured, return None.
        return None

    def _set_name(self, value):
        """
        Configure the name `value` as the friendly name for this interface.
        """
        # Make sure that the name is legal according to the allowed interface names detailed in section 2-23 of the HP
        # Management and Configuration Guide
        assert(all(map(lambda letter: letter in (string.ascii_letters + string.digits), value)))
        # Issue the commands on the switch to set the new name.
        self.switch.execute_command("config")
        self.switch.execute_command("interface {0} name {1}".format(self.identifier, value))
        self.switch.execute_command("exit")

    def _del_name(self):
        """
        Deconfigure the friendly name on this interface.
        """
        self.switch.execute_command("config")
        self.switch.execute_command("no interface {0} name".format(self.identifier))
        self.switch.execute_command("exit")

    name = property(_get_name, _set_name, _del_name)<commit_msg>Add ability to enable or disable an interface<commit_after>import re
import string

class Interface(object):
    """
    Represents a physical interface on a switch.
    """
    def __init__(self, switch, identifier):
        """
        Construct a new Interface with the given `identifier` located on the given `switch`.
        """
        self.switch = switch
        self.identifier = identifier

    def _get_name(self):
        """
        Get the friendly name configured for this interface.
        """
        run_output = self.switch.execute_command("show running-config interface " + str(self.identifier))
        # Try to extract the interface name, which may also contain spaces. This is achieved by greedily matching
        # whitespace at the end of the line and matching the `   name ` prefix a the beginning and using whatever
        # remains of the string as the interface name. The `name` group is matched in a non-greedy fashion as to not
        # "eat up" all the following whitespace which is not part of the name.
        name_match = re.search(r"^   name \"(?P<name>.*?)\"\s*$", run_output, re.MULTILINE)
        # Only return the name of the interface if a name was found.
        if name_match:
            return name_match.group('name')
        # If no name was configured, return None.
        return None

    def _set_name(self, value):
        """
        Configure the name `value` as the friendly name for this interface.
        """
        # Make sure that the name is legal according to the allowed interface names detailed in section 2-23 of the HP
        # Management and Configuration Guide
        assert(all(map(lambda letter: letter in (string.ascii_letters + string.digits), value)))
        # Issue the commands on the switch to set the new name.
        self.switch.execute_command("config")
        self.switch.execute_command("interface {0} name {1}".format(self.identifier, value))
        self.switch.execute_command("exit")

    def _del_name(self):
        """
        Deconfigure the friendly name on this interface.
        """
        self.switch.execute_command("config")
        self.switch.execute_command("no interface {0} name".format(self.identifier))
        self.switch.execute_command("exit")

    name = property(_get_name, _set_name, _del_name)

    def _get_enabled(self):
        """
        Get the admin status of this interface.
        """
        run_output = self.switch.execute_command("show running-config interface " + str(self.identifier))
        disable_match = re.search(r"^   disable\s*$", run_output, re.MULTILINE)
        # If nothing hinting at a disabled port has been matched, return True, else False.
        return disable_match is None

    def _set_enabled(self, value):
        """
        Set the admin status of this interface.
        """
        self.switch.execute_command("config")
        if value:
            self.switch.execute_command("interface {0} enable".format(self.identifier))
        else:
            self.switch.execute_command("interface {0} disable".format(self.identifier))
        self.switch.execute_command("exit")

    enabled = property(_get_enabled, _set_enabled)
{'fraction_non_alphanumeric': 0.09097552064303982, 'fraction_numerical': 0.0025575447570332483, 'mean_word_length': 2.6306366047745358, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2842905', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1402, 'n_words': 527}