<commit_before>#!/usr/bin/env python
""" pyexos """

import difflib

from netmiko import ConnectHandler
from netmiko.ssh_exception import NetMikoTimeoutException
from netmiko.ssh_exception import NetMikoAuthenticationException

from pyEXOS.exceptions import EXOSException


class EXOS(object):
    """
    Establishes a connection with the ESOX device via SSH and provides a number of
    config manipulation methods.
    """

    def __init__(self, hostname, username, password, port=22, timeout=60):
        """
        EXOS device constructor.

        :param hostname:  (str) IP or FQDN of the target device
        :param username:  (str) Username
        :param password:  (str) Password
        :param port:      (int) SSH Port (default: 22)
        :param timeout:   (int) Timeout (default: 60 sec)
        :return: (obj) EXOS object
        """
        self.hostname = str(hostname)
        self.username = str(username)
        self.password = str(password)
        self.port = int(port)
        self.timeout = int(timeout)

        self.device = None
        self.candidate_config = None
        self.running_config = None

    def open(self):
        """
        Open a connection to an EXOS device using SSH.

        :return: None
        :raises: NetMikoTimeoutException, NetMikoAuthenticationException
        """
        try:
            self.device = ConnectHandler(device_type='extreme',
                                         ip=self.hostname,
                                         port=self.port,
                                         username=self.username,
                                         password=self.password)
            self.device.timeout = self.timeout
        except (NetMikoTimeoutException, NetMikoAuthenticationException):
            raise

    def close(self):
        """
        Close the SSH connection to the EXOS device.

        :return: None
        """
        if hasattr(self.device, 'remote_conn'):
            self.device.remote_conn.close()

    def load_candidate_config(self, filename=None, config=None):
        """
        Populate candidate_config from str or file as a list of commands.

        :param filename:  Path to the file containing the desired
                          configuration. Default: None.
        :param config:    String containing the desired configuration.
                          Default: None.

        :return: None
        :raises: EXOSException
        """
<commit_msg>adding ssh config file parameter to exos init<commit_after>#!/usr/bin/env python
""" pyexos """

import difflib

from netmiko import ConnectHandler
from netmiko.ssh_exception import NetMikoTimeoutException
from netmiko.ssh_exception import NetMikoAuthenticationException

from pyEXOS.exceptions import EXOSException


class EXOS(object):
    """
    Establishes a connection with the ESOX device via SSH and provides a number of
    config manipulation methods.
    """

    def __init__(self, hostname, username, password, port=22, timeout=60, ssh_config_file=None):
        """
        EXOS device constructor.

        :param hostname:  (str) IP or FQDN of the target device
        :param username:  (str) Username
        :param password:  (str) Password
        :param port:      (int) SSH Port (default: 22)
        :param timeout:   (int) Timeout (default: 60 sec)
        :param ssh_config_file: (file) Path to SSH config file
        :return: (obj) EXOS object
        """
        self.hostname = str(hostname)
        self.username = str(username)
        self.password = str(password)
        self.port = int(port)
        self.timeout = int(timeout)
        self.ssh_config_file = str(ssh_config_file)

        self.device = None
        self.candidate_config = None
        self.running_config = None

    def open(self):
        """
        Open a connection to an EXOS device using SSH.

        :return: None
        :raises: NetMikoTimeoutException, NetMikoAuthenticationException
        """
        try:
            self.device = ConnectHandler(device_type='extreme',
                                         ip=self.hostname,
                                         port=self.port,
                                         username=self.username,
                                         password=self.password,
                                         ssh_config_file=self.ssh_config_file)
            self.device.timeout = self.timeout
        except (NetMikoTimeoutException, NetMikoAuthenticationException):
            raise

    def close(self):
        """
        Close the SSH connection to the EXOS device.

        :return: None
        """
        if hasattr(self.device, 'remote_conn'):
            self.device.remote_conn.close()

    def load_candidate_config(self, filename=None, config=None):
        """
        Populate candidate_config from str or file as a list of commands.

        :param filename:  Path to the file containing the desired
                          configuration. Default: None.
        :param config:    String containing the desired configuration.
                          Default: None.

        :return: None
        :raises: EXOSException
        """

{'fraction_non_alphanumeric': 0.07764932562620423, 'fraction_numerical': 0.0030828516377649326, 'mean_word_length': 1.8935340022296545, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4960351', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1289, 'n_words': 393}