⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfc1155.py

📁 实现snmp协议的agent 和manager
💻 PY
字号:
"""An implementation of high-level API to SNMP data types (RFC1155)"""from types import InstanceTypefrom pysnmp.proto import rfc1155from pysnmp.proto.api import errorfrom pysnmp.asn1.error import BadArgumentErrorclass SequenceMixIn:    def apiAlphaSetSimpleComponent(self, key, value):        if type(value) == InstanceType:            self[key] = value        else:            self[key].set(value)        class ChoiceMixIn:    def apiAlphaGetCurrentComponent(self):        if len(self):            return self.values()[0]        raise error.BadArgumentError('No initialized component at %s' % \                                     self.__class__.__name__)    def apiAlphaGetTerminalValue(self):        if len(self):                    component = self.apiAlphaGetCurrentComponent()            if hasattr(component, 'apiAlphaGetTerminalValue'):                return component.apiAlphaGetTerminalValue()            return component        raise error.BadArgumentError('No initialized value at %s'\                                     % (self.__class__.__name__))    # XXX left for compatibility    getTerminal = apiAlphaGetTerminalValue    def apiAlphaSetTerminalValue(self, value):        # Start with current key        for key in self.keys() + self.choiceNames:  # XXX sort is more eff.            comp = self.componentFactoryBorrow(key)            if hasattr(comp, 'apiAlphaSetTerminalValue'):                try:                    comp.apiAlphaSetTerminalValue(value)                except error.BadArgumentError:                    continue                self[key] = comp            else:                try:                    self[key] = value                except BadArgumentError, why:                    continue            break        else:            raise error.BadArgumentError('Unapplicable component %s at %s'\                                         % (value, self.__class__.__name__))mixInComps = [ (rfc1155.Sequence, SequenceMixIn),                              (rfc1155.Choice, ChoiceMixIn) ]for (baseClass, mixIn) in mixInComps:    if mixIn not in baseClass.__bases__:        baseClass.__bases__ = (mixIn, ) + baseClass.__bases__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -