python类OctetString()的实例源码

snmpclient.py 文件源码 项目:check_ruckus_vsz 作者: CygnusNetworks 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __get_json(self, keytype=str):
        json = {}
        for key, value in list(self.get_dict().items()):
            if isinstance(value, univ.OctetString):
                value = str(value)
            elif isinstance(value, univ.Integer):
                value = int(value)  # pylint:disable=R0204
            elif isinstance(value, univ.ObjectIdentifier):
                value = str(value)
            else:
                raise AssertionError("Unknown type %s encountered for oid %s" % (value.__class__.__name__, key))
            json[keytype(key)] = value
        return json
char.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def clone(self, value=noValue, **kwargs):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *clone()* method will replace corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        tagSet: :py:class:`~pyasn1.type.tag.TagSet`
            Object representing non-default ASN.1 tag(s)

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.clone(self, value, **kwargs)
char.py 文件源码 项目:GAMADV-XTD 作者: taers232c 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def subtype(self, value=noValue, **kwargs):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *subtype()* method will be added to the corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        implicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Implicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        explicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Explicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.subtype(self, value, **kwargs)
apc_rackpdu.py 文件源码 项目:virtualpdu 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def value(self):
        return univ.OctetString('Outlet #{}'.format(self.outlet_number))
test_baytech_mrp27.py 文件源码 项目:virtualpdu 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_read_system_description(self):
        self.assertEqual(
            univ.OctetString("Universal RPC Host Module (virtualpdu)"),
            self.pdu.oid_mapping[sysDescr].value
        )
test_apc_rackpdu.py 文件源码 项目:virtualpdu 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_read_outlet_name(self):
        outlet_name = self.pdu.oid_mapping[self.outlet_name_oid]

        self.assertEqual(
            univ.OctetString('Outlet #1'),
            outlet_name.value
        )
test_apc_rackpdu.py 文件源码 项目:virtualpdu 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_read_system_description(self):
        self.assertEqual(
            univ.OctetString("APC Rack PDU (virtualpdu)"),
            self.pdu.oid_mapping[sysDescr].value
        )
char.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def clone(self, value=noValue, **kwargs):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *clone()* method will replace corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        tagSet: :py:class:`~pyasn1.type.tag.TagSet`
            Object representing non-default ASN.1 tag(s)

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.clone(self, value, **kwargs)
char.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def subtype(self, value=noValue, **kwargs):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *subtype()* method will be added to the corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        implicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Implicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        explicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Explicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.subtype(self, value, **kwargs)
char.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def clone(self, value=noValue, tagSet=None, subtypeSpec=None,
              encoding=None, binValue=noValue, hexValue=noValue):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *clone()* method will replace corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        tagSet: :py:class:`~pyasn1.type.tag.TagSet`
            Object representing non-default ASN.1 tag(s)

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.clone(self, value, tagSet, subtypeSpec, encoding, binValue, hexValue)
char.py 文件源码 项目:REMAP 作者: REMAPApp 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def subtype(self, value=noValue, implicitTag=None, explicitTag=None,
                subtypeSpec=None, encoding=None, binValue=noValue, hexValue=noValue):
        """Creates a copy of a |ASN.1| type or object.

        Any parameters to the *subtype()* method will be added to the corresponding
        properties of the |ASN.1| object.

        Parameters
        ----------
        value: :class:`unicode`, :class:`str`, :class:`bytes` or |ASN.1| object
            unicode object (Python 2) or string (Python 3), alternatively string
            (Python 2) or bytes (Python 3) representing octet-stream of serialized
            unicode string (note `encoding` parameter) or |ASN.1| class instance.

        implicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Implicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        explicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Explicitly apply given ASN.1 tag object to caller's
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Object representing non-default ASN.1 subtype constraint(s)

        encoding: :py:class:`str`
            Unicode codec ID to encode/decode :py:class:`unicode` (Python 2) or
            :py:class:`str` (Python 3) the payload when |ASN.1| object is used
            in octet-stream context.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        """
        return univ.OctetString.subtype(self, value, implicitTag, explicitTag, subtypeSpec, encoding, binValue, hexValue)
securityblob.py 文件源码 项目:xunfeng 作者: ysrc 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def generateAuthSecurityBlob(ntlm_data):
    response_token = univ.OctetString(ntlm_data).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))

    n = NegTokenTarg().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))
    n.setComponentByName('responseToken', response_token)

    nt = NegotiationToken()
    nt.setComponentByName('negTokenTarg', n)

    return encoder.encode(nt)
context.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def registerContextName(self, contextName, mibInstrum=None):
        contextName = univ.OctetString(contextName).asOctets()
        if contextName in self.contextNames:
            raise error.PySnmpError(
                'Duplicate contextName %s' % contextName
            )
        debug.logger & debug.flagIns and debug.logger(
            'registerContextName: registered contextName %r, mibInstrum %r' % (contextName, mibInstrum))
        if mibInstrum is None:
            self.contextNames[contextName] = self.contextNames[null]
        else:
            self.contextNames[contextName] = mibInstrum
context.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def unregisterContextName(self, contextName):
        contextName = univ.OctetString(contextName).asOctets()
        if contextName in self.contextNames:
            debug.logger & debug.flagIns and debug.logger(
                'unregisterContextName: unregistered contextName %r' % contextName)
            del self.contextNames[contextName]
context.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def getMibInstrum(self, contextName=null):
        contextName = univ.OctetString(contextName).asOctets()
        if contextName not in self.contextNames:
            debug.logger & debug.flagIns and debug.logger('getMibInstrum: contextName %r not registered' % contextName)
            raise error.PySnmpError(
                'Missing contextName %s' % contextName
            )
        else:
            debug.logger & debug.flagIns and debug.logger(
                'getMibInstrum: contextName %r, mibInstum %r' % (contextName, self.contextNames[contextName]))
            return self.contextNames[contextName]
rfc1155.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def prettyIn(self, value):
        if isinstance(value, str) and len(value) != 4:
            try:
                value = [int(x) for x in value.split('.')]
            except:
                raise error.ProtocolError('Bad IP address syntax %s' % value)
        if len(value) != 4:
            raise error.ProtocolError('Bad IP address syntax')
        return univ.OctetString.prettyIn(self, value)
rfc1902.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def clone(self, *args, **kwargs):
        return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())
rfc1902.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def prettyIn(self, value):
        if isinstance(value, str) and len(value) != 4:
            try:
                value = [int(x) for x in value.split('.')]
            except:
                raise error.ProtocolError('Bad IP address syntax %s' % value)
        value = OctetString.prettyIn(self, value)
        if len(value) != 4:
            raise error.ProtocolError('Bad IP address syntax')
        return value
rfc1902.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, value=univ.noValue, **kwargs):
        if 'namedValues' not in kwargs:
            kwargs['namedValues'] = self.namedValues

        OctetString.__init__(self, value, **kwargs)
rfc1902.py 文件源码 项目:pysnmp 作者: etingof 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def prettyIn(self, bits):
        if not isinstance(bits, (tuple, list)):
            return OctetString.prettyIn(self, bits)  # raw bitstring
        octets = []
        for bit in bits:  # tuple of named bits
            v = self.namedValues.getValue(bit)
            if v is None:
                raise error.ProtocolError('Unknown named bit %s' % bit)
            d, m = divmod(v, 8)
            if d >= len(octets):
                octets.extend([0] * (d - len(octets) + 1))
            octets[d] |= 0x01 << (7 - m)
        return OctetString.prettyIn(self, octets)


问题


面经


文章

微信
公众号

扫码关注公众号