<commit_before>import ipaddress
import paramiko
import re

import route

class Switch(object):
    """
    Represents a generic HP Networking switch.
    """
    def __init__(self, hostname, username, password):
        self.hostname = hostname
        self.username = username
        self.password = password

        # Establish a new SSH connection to the switch.

        # TODO: what happens if the connection drops?
        self._ssh_connection = paramiko.SSHClient()
        self._ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self._ssh_connection.connect(self.hostname,
                username=self.username, password=self.password,
                allow_agent=False)
        # Request a new pseudo-terminal and immediately resize it to something huge. Else, the switch will try to make
        # the output scrollable with a keyboard, which is somewhat hard to emulate in code.
        self._ssh_pty = self._ssh_connection.invoke_shell()
        self._ssh_pty.resize_pty(width = 1000000, height=1000000)
        # Receive the annoying HP welcome message and skip it immediately.
        self._ssh_pty.recv(9000)
        self._ssh_pty.send('\n')
        self._ssh_pty.recv(9000)
<commit_msg>Switch to public-key SSH authentication<commit_after>import ipaddress
import paramiko
import re

import route

class Switch(object):
    """
    Represents a generic HP Networking switch.
    """
    def __init__(self, hostname):
        self.hostname = hostname

        # Establish a new SSH connection to the switch.

        # TODO: what happens if the connection drops?
        self._ssh_connection = paramiko.SSHClient()
        self._ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self._ssh_connection.connect(self.hostname)
        # Request a new pseudo-terminal and immediately resize it to something huge. Else, the switch will try to make
        # the output scrollable with a keyboard, which is somewhat hard to emulate in code.
        self._ssh_pty = self._ssh_connection.invoke_shell()
        self._ssh_pty.resize_pty(width = 1000000, height=1000000)
        # Receive the annoying HP welcome message and skip it immediately.
        self._ssh_pty.recv(9000)
        self._ssh_pty.send('\n')
        self._ssh_pty.recv(9000)

{'fraction_non_alphanumeric': 0.07418655097613883, 'fraction_numerical': 0.01908893709327549, 'mean_word_length': 2.9151103565365024, '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': '4395638', 'n_tokens_mistral': 678, 'n_tokens_neox': 630, 'n_words': 193}