def __init__(self, **args):
<EOL>defaults = {<EOL>"<STR_LIT>"     : os.path.splitext(os.path.basename(sys.argv[<NUM_LIT:0>]))[<NUM_LIT:0>],<EOL>"<STR_LIT>"  : None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>"   : True,<EOL>"<STR_LIT>"      : None,<EOL>"<STR_LIT>"    : None,<EOL>}<EOL>for key in defaults:<EOL><INDENT>setattr(self, key, args.get(key, defaults[key]))<EOL><DEDENT>if self.UseMIBFiles and self.MIBFiles is not None and type(self.MIBFiles) not in (list, tuple):<EOL><INDENT>self.MIBFiles = (self.MIBFiles,)<EOL><DEDENT>self._status = netsnmpAgentStatus.REGISTRATION<EOL>def _py_log_handler(majorID, minorID, serverarg, clientarg):<EOL><INDENT>logmsg = ctypes.cast(serverarg, snmp_log_message_p)<EOL>priorities = {<EOL>LOG_EMERG: "<STR_LIT>",<EOL>LOG_ALERT: "<STR_LIT>",<EOL>LOG_CRIT: "<STR_LIT>",<EOL>LOG_ERR: "<STR_LIT>",<EOL>LOG_WARNING: "<STR_LIT>",<EOL>LOG_NOTICE: "<STR_LIT>",<EOL>LOG_INFO: "<STR_LIT>",<EOL>LOG_DEBUG: "<STR_LIT>"<EOL>}<EOL>msgprio = priorities[logmsg.contents.priority]<EOL>msgtext = re.sub(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>u(logmsg.contents.msg.rstrip(b"<STR_LIT:\n>"))<EOL>)<EOL>if  msgprio == "<STR_LIT>"or  msgprio == "<STR_LIT>"and re.match("<STR_LIT>", msgtext):<EOL><INDENT>if self._status == netsnmpAgentStatus.FIRSTCONNECT:<EOL><INDENT>self._status = netsnmpAgentStatus.CONNECTFAILED<EOL>return <NUM_LIT:0><EOL><DEDENT><DEDENT>elif msgprio == "<STR_LIT>"and  re.match("<STR_LIT>", msgtext):<EOL><INDENT>self._status = netsnmpAgentStatus.CONNECTED<EOL><DEDENT>elif msgprio == "<STR_LIT>"and  re.match("<STR_LIT>", msgtext):<EOL><INDENT>self._status = netsnmpAgentStatus.RECONNECTING<EOL><DEDENT>if self.LogHandler:<EOL><INDENT>self.LogHandler(msgprio, msgtext)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>".format(msgprio, msgtext))<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>self._log_handler = SNMPCallback(_py_log_handler)<EOL>if libnsa.snmp_register_callback(<EOL>SNMP_CALLBACK_LIBRARY,<EOL>SNMP_CALLBACK_LOGGING,<EOL>self._log_handler,<EOL>None<EOL>) != SNMPERR_SUCCESS:<EOL><INDENT>raise netsnmpAgentException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>libnsa.snmp_enable_calllog()<EOL>def _py_index_stop_callback(majorID, minorID, serverarg, clientarg):<EOL><INDENT>if minorID == SNMPD_CALLBACK_INDEX_STOP:<EOL><INDENT>self._status = netsnmpAgentStatus.RECONNECTING<EOL><DEDENT>return <NUM_LIT:0><EOL><DEDENT>self._index_stop_callback = SNMPCallback(_py_index_stop_callback)<EOL>if libnsa.snmp_register_callback(<EOL>SNMP_CALLBACK_APPLICATION,<EOL>SNMPD_CALLBACK_INDEX_STOP,<EOL>self._index_stop_callback,<EOL>None<EOL>) != SNMPERR_SUCCESS:<EOL><INDENT>raise netsnmpAgentException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if libnsa.netsnmp_ds_set_boolean(<EOL>NETSNMP_DS_APPLICATION_ID,<EOL>NETSNMP_DS_AGENT_ROLE,<EOL><NUM_LIT:1><EOL>) != SNMPERR_SUCCESS:<EOL><INDENT>raise netsnmpAgentException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if self.MasterSocket:<EOL><INDENT>if libnsa.netsnmp_ds_set_string(<EOL>NETSNMP_DS_APPLICATION_ID,<EOL>NETSNMP_DS_AGENT_X_SOCKET,<EOL>b(self.MasterSocket)<EOL>) != SNMPERR_SUCCESS:<EOL><INDENT>raise netsnmpAgentException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if self.PersistenceDir:<EOL><INDENT>if libnsa.netsnmp_ds_set_string(<EOL>NETSNMP_DS_LIBRARY_ID,<EOL>NETSNMP_DS_LIB_PERSISTENT_DIR,<EOL>b(self.PersistenceDir)<EOL>) != SNMPERR_SUCCESS:<EOL><INDENT>raise netsnmpAgentException(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if libnsa.init_agent(b(self.AgentName)) != <NUM_LIT:0>:<EOL><INDENT>raise netsnmpAgentException("<STR_LIT>")<EOL><DEDENT>if self.UseMIBFiles:<EOL><INDENT>libnsa.netsnmp_init_mib()<EOL><DEDENT>if self.UseMIBFiles and self.MIBFiles:<EOL><INDENT>for mib in self.MIBFiles:<EOL><INDENT>if libnsa.read_mib(b(mib)) == <NUM_LIT:0>:<EOL><INDENT>raise netsnmpAgentException("<STR_LIT>" +<EOL>"<STR_LIT>".format(mib))<EOL><DEDENT><DEDENT><DEDENT>self._objs = defaultdict(dict)<EOL>for vartype_cls in [<EOL>m[<NUM_LIT:1>]<EOL>for m<EOL>in inspect.getmembers(sys.modules["<STR_LIT>"])<EOL>if not m[<NUM_LIT:0>].startswith("<STR_LIT:_>")<EOL>and inspect.isclass(m[<NUM_LIT:1>])<EOL>and issubclass(m[<NUM_LIT:1>], netsnmpvartypes._VarType)<EOL>]:<EOL><INDENT>argspec = inspect.getargspec(vartype_cls.__init__)<EOL>default_initval = argspec[<NUM_LIT:3>][list(filter(lambda e: e != "<STR_LIT>", argspec[<NUM_LIT:0>])).index("<STR_LIT>")]<EOL>cls_wrapper = self._generateVarTypeClassWrapper(vartype_cls, default_initval)<EOL>setattr(self, vartype_cls.__name__, cls_wrapper)<EOL><DEDENT>
Initializes a new netsnmpAgent instance.

        "args" is a dictionary that can contain the following
        optional parameters:

        - AgentName     : The agent's name used for registration with net-snmp.
        - MasterSocket  : The transport specification of the AgentX socket of
                          the running snmpd instance to connect to (see the
                          "LISTENING ADDRESSES" section in the snmpd(8) manpage).
                          Change this if you want to use eg. a TCP transport or
                          access a custom snmpd instance, eg. as shown in
                          run_simple_agent.sh, or for automatic testing.
        - PersistenceDir: The directory to use to store persistence information.
                          Change this if you want to use a custom snmpd
                          instance, eg. for automatic testing.
        - MIBFiles      : A list of filenames of MIBs to be loaded. Required if
                          the OIDs, for which variables will be registered, do
                          not belong to standard MIBs and the custom MIBs are not
                          located in net-snmp's default MIB path
                          (/usr/share/snmp/mibs).
        - UseMIBFiles   : Whether to use MIB files at all or not. When False,
                          the parser for MIB files will not be initialized, so
                          neither system-wide MIB files nor the ones provided
                          in the MIBFiles argument will be in use.
        - LogHandler    : An optional Python function that will be registered
                          with net-snmp as a custom log handler. If specified,
                          this function will be called for every log message
                          net-snmp itself generates, with parameters as follows:
                          1. a string indicating the message's priority: one of
                          "Emergency", "Alert", "Critical", "Error", "Warning",
                          "Notice", "Info" or "Debug".
                          2. the actual log message. Note that heading strings
                          such as "Warning: " and "Error: " will be stripped off
                          since the priority level is explicitly known and can
                          be used to prefix the log message, if desired.
                          Trailing linefeeds will also have been stripped off.
                          If undefined, log messages will be written to stderr
                          instead.