• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python octets.int2oct函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyasn1.compat.octets.int2oct函数的典型用法代码示例。如果您正苦于以下问题:Python int2oct函数的具体用法?Python int2oct怎么用?Python int2oct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了int2oct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: prettyIn

 def prettyIn(self, value):
     if isinstance(value, tuple):
         # Wild hack -- need to implement TextualConvention.prettyIn
         value = inet_pton(AF_INET, value[0]) + \
                 int2oct((value[1] >> 8) & 0xff) + \
                 int2oct(value[1] & 0xff)
     return OctetString.prettyIn(self, value)
开发者ID:BoundaryDev,项目名称:boundary-plugin-mongodb-enterprise-dev,代码行数:7,代码来源:SNMPv2-TM.py


示例2: prettyIn

 def prettyIn(self, value):
     if AF_INET6 is None:
         raise error.PySnmpError('IPv6 not supported by platform')
     if isinstance(value, tuple):
         value = inet_pton(AF_INET6, value[0]) + \
                 int2oct((value[1] >> 8) & 0xff) + \
                 int2oct(value[1] & 0xff)
     return OctetString.prettyIn(self, value)
开发者ID:carmackjia,项目名称:pysnmp,代码行数:8,代码来源:TRANSPORT-ADDRESS-MIB.py


示例3: encodeLength

 def encodeLength(self, length, defMode):
     if not defMode and self.supportIndefLenMode:
         return int2oct(0x80)
     if length < 0x80:
         return int2oct(length)
     else:
         substrate = null
         while length:
             substrate = int2oct(length&0xff) + substrate
             length = length >> 8
         substrateLen = len(substrate)
         if substrateLen > 126:
             raise Error('Length octets overflow (%d)' % substrateLen)
         return int2oct(0x80 | substrateLen) + substrate
开发者ID:18600597055,项目名称:hue,代码行数:14,代码来源:encoder.py


示例4: encodeTag

 def encodeTag(self, t, isConstructed):
     tagClass, tagFormat, tagId = t.asTuple()  # this is a hotspot
     v = tagClass | tagFormat
     if isConstructed:
         v = v|tag.tagFormatConstructed
     if tagId < 31:
         return int2oct(v|tagId)
     else:
         s = int2oct(tagId&0x7f)
         tagId = tagId >> 7
         while tagId:
             s = int2oct(0x80|(tagId&0x7f)) + s
             tagId = tagId >> 7
         return int2oct(v|0x1F) + s
开发者ID:18600597055,项目名称:hue,代码行数:14,代码来源:encoder.py


示例5: encodeValue

    def encodeValue(self, value, asn1Spec, encodeFun, **options):
        if asn1Spec is not None:
            # TODO: try to avoid ASN.1 schema instantiation
            value = asn1Spec.clone(value)

        valueLength = len(value)
        if valueLength % 8:
            alignedValue = value << (8 - valueLength % 8)
        else:
            alignedValue = value

        maxChunkSize = options.get('maxChunkSize', 0)
        if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
            substrate = alignedValue.asOctets()
            return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True

        baseTag = value.tagSet.baseTag

        # strip off explicit tags
        if baseTag:
            tagSet = tag.TagSet(baseTag, baseTag)
        else:
            tagSet = tag.TagSet()

        alignedValue = alignedValue.clone(tagSet=tagSet)

        stop = 0
        substrate = null
        while stop < valueLength:
            start = stop
            stop = min(start + maxChunkSize * 8, valueLength)
            substrate += encodeFun(alignedValue[start:stop], asn1Spec, **options)

        return substrate, True, True
开发者ID:AndreaBuffa,项目名称:trenordsaga,代码行数:34,代码来源:encoder.py


示例6: encodeValue

    def encodeValue(self, value, encodeFun, **options):
        valueLength = len(value)
        if valueLength % 8:
            alignedValue = value << (8 - valueLength % 8)
        else:
            alignedValue = value

        maxChunkSize = options.get('maxChunkSize', 0)
        if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
            substrate = alignedValue.asOctets()
            return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True

        # strip off explicit tags
        alignedValue = alignedValue.clone(
            tagSet=tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
        )

        stop = 0
        substrate = null
        while stop < valueLength:
            start = stop
            stop = min(start + maxChunkSize * 8, valueLength)
            substrate += encodeFun(alignedValue[start:stop], **options)

        return substrate, True, True
开发者ID:aaronlifshin,项目名称:whysaurus,代码行数:25,代码来源:encoder.py


示例7: encodeValue

 def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
     if value.isPlusInfinity():
         return int2oct(0x40), 0
     if value.isMinusInfinity():
         return int2oct(0x41), 0
     m, b, e = value
     if not m:
         return null, 0
     if b == 10:
         return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), 0
     elif b == 2:
         fo = 0x80                 # binary enoding
         if m < 0:
             fo = fo | 0x40  # sign bit
             m = -m
         while int(m) != m: # drop floating point
             m *= 2
             e -= 1
         while m & 0x1 == 0: # mantissa normalization
             m >>= 1
             e += 1
         eo = null
         while e not in (0, -1):
             eo = int2oct(e&0xff) + eo
             e >>= 8
         if e == 0 and eo and oct2int(eo[0]) & 0x80:
             eo = int2oct(0) + eo
         n = len(eo)
         if n > 0xff:
             raise error.PyAsn1Error('Real exponent overflow')
         if n == 1:
             pass
         elif n == 2:
             fo |= 1
         elif n == 3:
             fo |= 2
         else:
             fo |= 3
             eo = int2oct(n//0xff+1) + eo
         po = null
         while m:
             po = int2oct(m&0xff) + po
             m >>= 8
         substrate = int2oct(fo) + eo + po
         return substrate, 0
     else:
         raise error.PyAsn1Error('Prohibited Real base %s' % b)
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:47,代码来源:encoder.py


示例8: encodeValue

    def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
        valueLength = len(value)
        if valueLength % 8:
            alignedValue = value << (8 - valueLength % 8)
        else:
            alignedValue = value

        if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
            substrate = alignedValue.asOctets()
            return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True

        stop = 0
        substrate = null
        while stop < valueLength:
            start = stop
            stop = min(start + maxChunkSize * 8, valueLength)
            substrate += encodeFun(alignedValue[start:stop], defMode, maxChunkSize)

        return substrate, True, True
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:19,代码来源:encoder.py


示例9: encodeValue

 def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
     if not maxChunkSize or len(value) <= maxChunkSize*8:
         r = {}; l = len(value); p = 0; j = 7
         while p < l:
             i, j = divmod(p, 8)
             r[i] = r.get(i,0) | value[p]<<(7-j)
             p = p + 1
         keys = list(r); keys.sort()
         return int2oct(7-j) + ints2octs([r[k] for k in keys]), 0
     else:
         pos = 0; substrate = null
         while 1:
             # count in octets
             v = value.clone(value[pos*8:pos*8+maxChunkSize*8])
             if not v:
                 break
             substrate = substrate + encodeFun(v, defMode, maxChunkSize)
             pos = pos + maxChunkSize
         return substrate, 1
开发者ID:404minds,项目名称:quiz-forest,代码行数:19,代码来源:encoder.py


示例10: encodeValue

 def encodeValue(self, encodeFun, value, defMode, maxChunkSize):
     if not maxChunkSize or len(value) <= maxChunkSize*8:
         out_len = (len(value) + 7) // 8
         out_list = out_len * [0]
         j = 7
         i = -1
         for val in value:
             j += 1
             if j == 8:
                 i += 1
                 j = 0
             out_list[i] = out_list[i] | val << (7-j)
         return int2oct(7-j) + ints2octs(out_list), 0
     else:
         pos = 0; substrate = null
         while 1:
             # count in octets
             v = value.clone(value[pos*8:pos*8+maxChunkSize*8])
             if not v:
                 break
             substrate = substrate + encodeFun(v, defMode, maxChunkSize)
             pos = pos + maxChunkSize
         return substrate, 1
开发者ID:18600597055,项目名称:hue,代码行数:23,代码来源:encoder.py


示例11: encodeValue

 def encodeValue(self, encodeFun, client, defMode, maxChunkSize):
     if client == 0:
         substrate = int2oct(0)
     else:
         substrate = int2oct(255)
     return substrate, 0
开发者ID:03013405yujiangfeng,项目名称:XX-Net,代码行数:6,代码来源:encoder.py


示例12: prettyIn

 def prettyIn(self, value):
     if not has_ipv6:
         raise error.PySnmpError("IPv6 not supported by platform")
     if isinstance(value, tuple):
         value = inet_pton(socket.AF_INET6, value[0]) + int2oct((value[1] >> 8) & 0xFF) + int2oct(value[1] & 0xFF)
     return OctetString.prettyIn(self, value)
开发者ID:ww9rivers,项目名称:pysnmp,代码行数:6,代码来源:TRANSPORT-ADDRESS-MIB.py


示例13: test_int2oct

 def test_int2oct(self):
     assert [12] == list(octets.int2oct(12))
开发者ID:catapult-project,项目名称:catapult,代码行数:2,代码来源:test_octets.py


示例14: encodeValue

    def encodeValue(self, value, asn1Spec, encodeFun, **options):
        if asn1Spec is not None:
            value = asn1Spec.clone(value)

        if value.isPlusInf:
            return (0x40,), False, False

        if value.isMinusInf:
            return (0x41,), False, False

        m, b, e = value

        if not m:
            return null, False, True

        if b == 10:
            if LOG:
                LOG('encoding REAL into character form')

            return str2octs('\x03%dE%s%d' % (m, e == 0 and '+' or '', e)), False, True

        elif b == 2:
            fo = 0x80  # binary encoding
            ms, m, encbase, e = self._chooseEncBase(value)

            if ms < 0:  # mantissa sign
                fo |= 0x40  # sign bit

            # exponent & mantissa normalization
            if encbase == 2:
                while m & 0x1 == 0:
                    m >>= 1
                    e += 1

            elif encbase == 8:
                while m & 0x7 == 0:
                    m >>= 3
                    e += 1
                fo |= 0x10

            else:  # encbase = 16
                while m & 0xf == 0:
                    m >>= 4
                    e += 1
                fo |= 0x20

            sf = 0  # scale factor

            while m & 0x1 == 0:
                m >>= 1
                sf += 1

            if sf > 3:
                raise error.PyAsn1Error('Scale factor overflow')  # bug if raised

            fo |= sf << 2
            eo = null
            if e == 0 or e == -1:
                eo = int2oct(e & 0xff)

            else:
                while e not in (0, -1):
                    eo = int2oct(e & 0xff) + eo
                    e >>= 8

                if e == 0 and eo and oct2int(eo[0]) & 0x80:
                    eo = int2oct(0) + eo

                if e == -1 and eo and not (oct2int(eo[0]) & 0x80):
                    eo = int2oct(0xff) + eo

            n = len(eo)
            if n > 0xff:
                raise error.PyAsn1Error('Real exponent overflow')

            if n == 1:
                pass

            elif n == 2:
                fo |= 1

            elif n == 3:
                fo |= 2

            else:
                fo |= 3
                eo = int2oct(n & 0xff) + eo

            po = null

            while m:
                po = int2oct(m & 0xff) + po
                m >>= 8

            substrate = int2oct(fo) + eo + po

            return substrate, False, True

        else:
            raise error.PyAsn1Error('Prohibited Real base %s' % b)
开发者ID:KernelPanicAUS,项目名称:got-your-back,代码行数:100,代码来源:encoder.py


示例15: __bitsFilter

 def __bitsFilter(value):
     return ''.join([int2oct(int(y, 16)) for y in value.split(' ')])
开发者ID:richb-hanover,项目名称:websnmpsim,代码行数:2,代码来源:walk.py



注:本文中的pyasn1.compat.octets.int2oct函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python octets.ints2octs函数代码示例发布时间:2022-05-25
下一篇:
Python encoder.encode函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap