"""
A framework for implementing ASN.1 data types.
Copyright 1999-2002 by Ilya Etingof <ilya@glas.net>. See LICENSE for
details.
"""
# Module public names
__all__ = [ 'tagClasses', 'tagFormats', 'tagCategories', 'SimpleAsn1Object', \
'RecordTypeAsn1Object', 'ChoiceTypeAsn1Object', \
'VariableTypeAsn1Object' ]
try:
from sys import version_info
except ImportError:
version_info = (0,0)
from operator import getslice, setslice, delslice
try:
enumerate
except NameError:
def enumerate( iterable ):
i = 0
for x in iterable:
yield i,x
i+=1
from types import *
from pysnmp.asn1 import error
from pysnmp.error import PySnmpError
import operator
# ASN.1 tagging
tagClasses = {
'UNIVERSAL' : 0x00,
'APPLICATION' : 0x40,
'CONTEXT' : 0x80,
'PRIVATE' : 0xC0
}
tagFormats = {
'SIMPLE' : 0x00,
'CONSTRUCTED' : 0x20
}
tagCategories = {
'IMPLICIT' : 0x01,
'EXPLICIT' : 0x02,
'UNTAGGED' : 0x04
}
class Asn1Object:
"""Base class for all ASN.1 objects
"""
#
# ASN.1 tags
#
tagClass = tagClasses['UNIVERSAL']
tagFormat = None
tagId = None
tagCategory = tagCategories['IMPLICIT']
#
# Argument type constraint
#
allowedTypes = ()
#
# Subtyping stuff
#
# A list of constraints.Constraint instances for checking values
constraints = ()
def _subtype_constraint(self, value):
"""All constraints checking method
"""
for c in self.constraints:
c( self, value )
return
def _type_constraint(self, value):
"""Constraint checking to see if value is of an acceptable type
"""
if self.allowedTypes:
if not isinstance(value, self.allowedTypes):
raise error.ValueConstraintError('Value type constraint for %s: %s not in %s' % (self.__class__.__name__, type(value), str(self.allowedTypes)))
def getUnderlyingTag(self):
"""
"""
for superClass in self.__class__.__bases__:
if issubclass(self.__class__, superClass):
break
else:
raise error.BadArgumentError('No underlying type for %s' % \
self.__class__.__name__)
return (superClass.tagClass, superClass.tagFormat, superClass.tagId)
class SimpleAsn1Object(Asn1Object):
"""Base class for a simple ASN.1 object. Defines behaviour and
properties of various non-structured ASN.1 objects.
"""
tagFormat = tagFormats['SIMPLE']
tagId = 0x00
initialValue = None
# Disable not applicible constraints
_subtype_inner_subtype_constraint = None
def __init__(self, value=None):
"""Store ASN.1 value
"""
self.set(value)
def __str__(self):
"""Return string representation of class instance
"""
return '%s: %s' % (self.__class__.__name__, str(self.get()))
def __repr__(self):
"""Return native representation of instance payload
"""
return self.__class__.__name__ + '(' + repr(self.get()) + ')'
def __cmp__(self, other):
"""Attempt to compare the payload of instances of the same class
"""
if hasattr(self, '_cmp'):
return self._cmp(other)
if isinstance(other, SimpleAsn1Object):
if not isinstance(other, self.__class__):
try:
other = self.componentFactoryBorrow(other.get())
except PySnmpError:
# Hide coercion errors
return -1
else:
try:
other = self.componentFactoryBorrow(other)
except PySnmpError:
# Hide coercion errors
return -1
return cmp(self.rawAsn1Value, other.rawAsn1Value)
def __hash__(self):
"""Returns hash of the payload value
"""
try:
return hash(self.rawAsn1Value)
except TypeError:
# Attempt to hash sequence value
return reduce(operator.xor, map(hash, self.rawAsn1Value),
hash(None))
def __nonzero__(self):
"""Returns true if value is true
"""
if self.rawAsn1Value:
return 1
else:
return 0
# caching types for _setRawAsn1Value instead of rebuilding tuple
# for each call (minor speedup)
NORMAL_STATIC_TYPES = (IntType,LongType,StringType,NoneType,FloatType,TupleType)
def _setRawAsn1Value(self, value):
self._subtype_constraint(value)
# Supported mutable type
if isinstance( value, list ):
# Copy mutable object
# XXX This line is most of the overhead of the method, doesn't
# seem ammenable to optimisation? Other than possibly watching
# for cases where we could optimise away the copy?
# That would require tracking (boolean) whether we know the value
# has been created anew for us, I'm guessing that in most cases
# it already has been? Something to look at later.
self.rawAsn1Value = value[:]
# Supported immutable types
elif isinstance( value, self.NORMAL_STATIC_TYPES):
self.rawAsn1Value = value
else:
raise error.BadArgumentError('Unsupported value type to hold at %s: %s' % (self.__class__.__name__, valType))
def componentFactoryBorrow(self, value=None):
if not hasattr(self, '_componentCache'):
self._componentCache = self.__class__()
if value is not None: self._componentCache.set(value)
return self._componentCache
#
# Simple ASN.1 object protocol definition
#
def set(self, value):
"""Set a value to object
"""
if value is None:
initial = self.initialValue
if callable(initial):
return initial()
elif initial is None:
self.rawAsn1Value = initial
return
value = initial
# Allow initalization from instances
if isinstance(value, SimpleAsn1Object):
# Save on same-type instances
if isinstance(value, self.__class__):
self._setRawAsn1Value(value.rawAsn1Value)
else:
self.set(value.get())
return
self._type_constraint(value)
if hasattr(self, '_iconv'):
value = self._iconv(value)
self._setRawAsn1Value(value)
def get(self):
"""Get a value from object
"""
if hasattr(self, '_oconv'):
return self._oconv(self.rawAsn1Value)
return self.rawAsn1Value
# XXX left for compatibility
def getTerminal(self): return self
class StructuredAsn1Object(Asn1Object):
"""Base class for structured ASN.1 objects
"""
tagFormat = tagFormats['CONSTRUCTED']
# Disable not applicible constraints
_subtype_value_range_constraint = None
_subtype_permitted_alphabet_constraint = None
class FixedTypeAsn1Object(StructuredAsn1Object):
"""Base class for fixed-type ASN.1 objects
"""
# Disable not applicible constraints
_subtype_size_constraint = None
def __init__(self):
"""Initialize object internals
"""
# Dictionary emulation (for strict ordering)
self._names = []
self._components = {}
def __str__(self):
"""Return string representation of class instance
"""
s = ', '.join( [
'%s: %s' % (name, self._components[name])
for name in self._names
])
return '%s: %s' % (self.__class__.__name__, s)
def __repr__(self):
"""Return nativ
没有合适的资源?快使用搜索试试~ 我知道了~
pysnmp-se-3.5.2.tar.gz_SNMP_SNMP Agent_pysnmp_pysnmp-apps_snmp m
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 161 浏览量
2022-09-20
14:15:10
上传
评论
收藏 92KB GZ 举报
温馨提示
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共153个文件
py:76个
html:72个
changes:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
实现snmp协议的agent 和manager
资源推荐
资源详情
资源评论
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 153 条
- 1
- 2
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/2416af5c19524431b870352d943af459_weixin_42659196.jpg!1)
周楷雯
- 粉丝: 80
- 资源: 1万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)