<commit_before>import pysnmp.entity.rfc3413.oneliner.cmdgen as cmdgen
from pysnmp.smi import builder, view
from pysnmp.smi.error import SmiError


class Snmpy(object):
    '''
    Simple pysnmp wrapper.
    '''
    ERROR_MSG = 'SNMP%s of %s on %s failed.'
    PREVIOUS_EXPORT = 'already exported'
    VERSION_2_2C = 1

    def __init__(self, host, public, private, port=161, timeout=1, retries=2):
        '''
        Create the snmpy object.
        :param host: hostname or IP address of the device to communicate with
        :type host: str
        :param public: public community string
        :type public: str
        :param private: private community string
        :type private: str
        :param port: port number to connect on (default 161)
        :type port: int
        :param timeout: timeout, in seconds (default 1s)
        :type timeout: int
        :param retries: number of retries (default 2)
        :type retries: int
        :returns:
        '''
        self._host = host
        self._port = port
        self._timeout = timeout
        self._retries = retries
        self._transport = cmdgen.UdpTransportTarget((self._host, self._port),
                                                    timeout=self._timeout,
                                                    retries=self._retries)
        self._public = cmdgen.CommunityData(public, self.VERSION_2_2C)
        self._private = cmdgen.CommunityData(private, self.VERSION_2_2C)

        self._mibBuilder = builder.MibBuilder()
        self._mibViewController = view.MibViewController(self._mibBuilder)

        # Preload some commonly used modules.
        self.load_mibs('SNMPv2-MIB', 'IF-MIB', 'IP-MIB',
                       'HOST-RESOURCES-MIB', 'FIBRE-CHANNEL-FE-MIB')

    def add_mib_path(self, *path):
        '''
        Add an additional directory to the MIB search path.
        :param path: path to additional MIBs
        '''
        mibPath = self._mibBuilder.getMibPath() + path
        self._mibBuilder.setMibPath(*mibPath)

    def load_mibs(self, *modules):
        '''
        Load one or more additional MIBs.
        :param modules: modules to load
        '''
        for module in modules:
            try:
                self._mibBuilder.loadModules(module)
            except SmiError, e:
                if self.PREVIOUS_EXPORT in str(e):
                    continue
                raise<commit_msg>Setting `mpModel` explicitly. Without it, authentication does not work correctly using `pysnmp==4.3.0`.<commit_after>import pysnmp.entity.rfc3413.oneliner.cmdgen as cmdgen
from pysnmp.smi import builder, view
from pysnmp.smi.error import SmiError


class Snmpy(object):
    '''
    Simple pysnmp wrapper.
    '''
    ERROR_MSG = 'SNMP%s of %s on %s failed.'
    PREVIOUS_EXPORT = 'already exported'
    VERSION_2_2C = 1

    def __init__(self, host, public, private, port=161, timeout=1, retries=2):
        '''
        Create the snmpy object.
        :param host: hostname or IP address of the device to communicate with
        :type host: str
        :param public: public community string
        :type public: str
        :param private: private community string
        :type private: str
        :param port: port number to connect on (default 161)
        :type port: int
        :param timeout: timeout, in seconds (default 1s)
        :type timeout: int
        :param retries: number of retries (default 2)
        :type retries: int
        :returns:
        '''
        self._host = host
        self._port = port
        self._timeout = timeout
        self._retries = retries
        self._transport = cmdgen.UdpTransportTarget((self._host, self._port),
                                                    timeout=self._timeout,
                                                    retries=self._retries)
        self._public = cmdgen.CommunityData(public, mpModel=self.VERSION_2_2C)
        self._private = cmdgen.CommunityData(private, mpModel=self.VERSION_2_2C)

        self._mibBuilder = builder.MibBuilder()
        self._mibViewController = view.MibViewController(self._mibBuilder)

        # Preload some commonly used modules.
        self.load_mibs('SNMPv2-MIB', 'IF-MIB', 'IP-MIB',
                       'HOST-RESOURCES-MIB', 'FIBRE-CHANNEL-FE-MIB')

    def add_mib_path(self, *path):
        '''
        Add an additional directory to the MIB search path.
        :param path: path to additional MIBs
        '''
        mibPath = self._mibBuilder.getMibPath() + path
        self._mibBuilder.setMibPath(*mibPath)

    def load_mibs(self, *modules):
        '''
        Load one or more additional MIBs.
        :param modules: modules to load
        '''
        for module in modules:
            try:
                self._mibBuilder.loadModules(module)
            except SmiError, e:
                if self.PREVIOUS_EXPORT in str(e):
                    continue
                raise
{'fraction_non_alphanumeric': 0.08819951338199514, 'fraction_numerical': 0.009529602595296026, 'mean_word_length': 1.950358851674641, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5646532', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1393, 'n_words': 390}