当前位置: 首页>>代码示例>>Python>>正文


Python octets.oct2int函数代码示例

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


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

示例1: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]        
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not substrate:
             raise error.PyAsn1Error('Missing initial octet')
         trailingBits = oct2int(substrate[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         substrate = substrate[1:]
         lsb = p = 0; l = len(substrate)-1; b = ()
         while p <= l:
             if p == l:
                 lsb = trailingBits
             j = 7                    
             o = oct2int(substrate[p])
             while j >= lsb:
                 b = b + ((o>>j)&0x01,)
                 j = j - 1
             p = p + 1
         return self._createComponent(asn1Spec, tagSet, b), ''
     r = self._createComponent(asn1Spec, tagSet, ())
     if not decodeFun:
         return r, substrate
     while substrate:
         component, substrate = decodeFun(substrate)
         r = r + component
     return r, substrate
开发者ID:bullseyestudio,项目名称:guns-game,代码行数:30,代码来源:decoder.py

示例2: valueDecoder

    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                     state, decodeFun, substrateFun):
        head, tail = substrate[:length], substrate[length:]
        if not head:
            raise error.PyAsn1Error('Empty substrate')

        # Get the first subid
        subId = oct2int(head[0])
        oid = divmod(subId, 40)

        index = 1
        substrateLen = len(head)
        while index < substrateLen:
            subId = oct2int(head[index])
            index = index + 1
            if subId == 128:
                # ASN.1 spec forbids leading zeros (0x80) in sub-ID OID
                # encoding, tolerating it opens a vulnerability.
                # See http://www.cosic.esat.kuleuven.be/publications/article-1432.pdf page 7
                raise error.PyAsn1Error('Invalid leading 0x80 in sub-OID')
            elif subId > 128:
                # Construct subid from a number of octets
                nextSubId = subId
                subId = 0
                while nextSubId >= 128:
                    subId = (subId << 7) + (nextSubId & 0x7F)
                    if index >= substrateLen:
                        raise error.SubstrateUnderrunError(
                            'Short substrate for sub-OID past %s' % (oid,)
                            )
                    nextSubId = oct2int(head[index])
                    index = index + 1
                subId = (subId << 7) + nextSubId
            oid = oid + (subId,)
        return self._createComponent(asn1Spec, tagSet, oid), tail
开发者ID:andviro,项目名称:pyasn1,代码行数:35,代码来源:decoder.py

示例3: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not head:
             raise error.PyAsn1Error('Empty substrate')
         trailingBits = oct2int(head[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         head = head[1:]
         lsb = p = 0; l = len(head)-1; b = []
         while p <= l:
             if p == l:
                 lsb = trailingBits
             j = 7
             o = oct2int(head[p])
             while j >= lsb:
                 b.append((o>>j)&0x01)
                 j -= 1
             p += 1
         return self._createComponent(asn1Spec, tagSet, b), tail
     r = self._createComponent(asn1Spec, tagSet, ())
     if substrateFun:
         return substrateFun(r, substrate, length)
     while head:
         component, head = decodeFun(head, self.protoComponent)
         r = r + component
     return r, tail
开发者ID:mmattice,项目名称:pyasn1,代码行数:30,代码来源:decoder.py

示例4: __asSocketAddress

 def __asSocketAddress(self):
     if not hasattr(self, '__tuple_value'):
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET, v[:4]),
             oct2int(v[4]) << 8 | oct2int(v[5])
         )
     return self.__tuple_value
开发者ID:etingof,项目名称:pysnmp,代码行数:8,代码来源:SNMPv2-TM.py

示例5: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET, v[:4]),
             oct2int(v[4]) << 8 | oct2int(v[5])
         )
     return self.__tuple_value[i]
开发者ID:BoundaryDev,项目名称:boundary-plugin-mongodb-enterprise-dev,代码行数:8,代码来源:SNMPv2-TM.py

示例6: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         if AF_INET6 is None:
             raise error.PySnmpError('IPv6 not supported by platform')
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(AF_INET6, v[:16]),
             oct2int(v[16]) << 8 | oct2int(v[17]),
             0,
             0)
     return self.__tuple_value[i]
开发者ID:carmackjia,项目名称:pysnmp,代码行数:11,代码来源:TRANSPORT-ADDRESS-MIB.py

示例7: __getitem__

 def __getitem__(self, i):
     if not hasattr(self, '__tuple_value'):
         if not has_ipv6:
             raise error.PySnmpError('IPv6 not supported by platform')
         v = self.asOctets()
         self.__tuple_value = (
             inet_ntop(socket.AF_INET6, v[:16]),
             oct2int(v[16]) << 8 | oct2int(v[17]),
             0,  # flowinfo
             0)  # scopeid
     return self.__tuple_value[i]
开发者ID:bbmorten,项目名称:pysnmp,代码行数:11,代码来源:TRANSPORT-ADDRESS-MIB.py

示例8: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
                  length, state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if not head:
         raise error.SubstrateUnderrunError('Short substrate for Real')
     fo = oct2int(head[0]); head = head[1:]
     if fo & 0x40:  # infinite value
         value = fo & 0x01 and '-inf' or 'inf'
     elif fo & 0x80:  # binary enoding
         n = (fo & 0x03) + 1
         if n == 4:
             n = oct2int(head[0])
         eo, head = head[:n], head[n:]
         if not eo or not head:
             raise error.PyAsn1Error('Real exponent screwed')
         e = oct2int(eo[0]) & 0x80 and -1 or 0
         while eo:         # exponent
             e <<= 8
             e |= oct2int(eo[0])
             eo = eo[1:]
         p = 0
         while head:  # value
             p <<= 8
             p |= oct2int(head[0])
             head = head[1:]
         if fo & 0x40:    # sign bit
             p = -p
         value = (p, 2, e)
     elif fo & 0xc0 == 0:  # character encoding
         try:
             if fo & 0x3 == 0x1:  # NR1
                 value = (int(head), 10, 0)
             elif fo & 0x3 == 0x2:  # NR2
                 value = float(head)
             elif fo & 0x3 == 0x3:  # NR3
                 value = float(head)
             else:
                 raise error.SubstrateUnderrunError(
                     'Unknown NR (tag %s)' % fo
                     )
         except ValueError:
             raise error.SubstrateUnderrunError(
                 'Bad character Real syntax'
                 )
     elif fo & 0xc0 == 0x40:  # special real value
         pass
     else:
         raise error.SubstrateUnderrunError(
             'Unknown encoding (tag %s)' % fo
             )
     return self._createComponent(asn1Spec, tagSet, value), tail
开发者ID:2flcastro,项目名称:ka-lite,代码行数:51,代码来源:decoder.py

示例9: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]
     if not substrate:
         raise error.PyAsn1Error('Empty substrate')
     if substrate in self.precomputedValues:
         value = self.precomputedValues[substrate]
     else:
         firstOctet = oct2int(substrate[0])
         if firstOctet & 0x80:
             value = -1
         else:
             value = 0
         for octet in substrate:
             value = value << 8 | oct2int(octet)
     return self._createComponent(asn1Spec, tagSet, value), substrate
开发者ID:404minds,项目名称:quiz-forest,代码行数:16,代码来源:decoder.py

示例10: valueDecoder

    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                     state, decodeFun, substrateFun):
        head, tail = substrate[:length], substrate[length:]
        if tagSet[0].tagFormat == tag.tagFormatSimple:  # XXX what tag to check?
            if not head:
                raise error.PyAsn1Error('Empty substrate')
            trailingBits = oct2int(head[0])
            if trailingBits > 7:
                raise error.PyAsn1Error(
                    'Trailing bits overflow %s' % trailingBits
                )
            head = head[1:]
            value = self.protoComponent.fromOctetString(head, trailingBits)
            return self._createComponent(asn1Spec, tagSet, value), tail

        if not self.supportConstructedForm:
            raise error.PyAsn1Error('Constructed encoding form prohibited at %s' % self.__class__.__name__)

        bitString = self._createComponent(asn1Spec, tagSet)

        if substrateFun:
            return substrateFun(bitString, substrate, length)

        while head:
            component, head = decodeFun(head, self.protoComponent)
            bitString += component

        return bitString, tail
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:28,代码来源:decoder.py

示例11: from_bytes

    def from_bytes(octets, signed=False):
        value = long(b2a_hex(str(octets)), 16)

        if signed and oct2int(octets[0]) & 0x80:
            return value - (1 << len(octets) * 8)

        return value
开发者ID:0-vortex,项目名称:ZeroNet,代码行数:7,代码来源:integer.py

示例12: from_bytes

    def from_bytes(octets, signed=False):
        if not octets:
            return 0

        value = long(b2a_hex(ensureString(octets)), 16)

        if signed and oct2int(octets[0]) & 0x80:
            return value - (1 << len(octets) * 8)

        return value
开发者ID:danacton,项目名称:appengine-endpoints-modules-lnkr,代码行数:10,代码来源:integer.py

示例13: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun):
     substrate = substrate[:length]
     if not substrate:
         raise error.PyAsn1Error('Empty substrate')
     byte = oct2int(substrate[0])
     if byte == 0xff:
         value = 1
     elif byte == 0x00:
         value = 0
     else:
         raise error.PyAsn1Error('Boolean CER violation: %s' % byte)
     return self._createComponent(asn1Spec, tagSet, value), substrate[1:]
开发者ID:404minds,项目名称:quiz-forest,代码行数:13,代码来源:decoder.py

示例14: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
                  state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if tagSet[0][1] == tag.tagFormatSimple:    # XXX what tag to check?
         if not head:
             raise error.PyAsn1Error('Empty substrate')
         trailingBits = oct2int(head[0])
         if trailingBits > 7:
             raise error.PyAsn1Error(
                 'Trailing bits overflow %s' % trailingBits
                 )
         head = head[1:]
         if BITPATTERN:
             # Use faster method with lookup table
             p = 0; l = len(head)-1; b = []
             while p < l:
                 b.extend(BITPATTERN[oct2int(head[p])])
                 p += 1
             b.extend(BITPATTERN[oct2int(head[p])][0:8-trailingBits])
         else:
             # Use original, slower method
             lsb = p = 0; l = len(head)-1; b = ()
             while p <= l:
                 if p == l:
                     lsb = trailingBits
                 j = 7                    
                 o = oct2int(head[p])
                 while j >= lsb:
                     b = b + ((o>>j)&0x01,)
                     j = j - 1
                 p = p + 1
         return self._createComponent(asn1Spec, tagSet, b), tail
     r = self._createComponent(asn1Spec, tagSet, ())
     if substrateFun:
         return substrateFun(r, substrate, length)
     while head:
         component, head = decodeFun(head)
         r = r + component
     return r, tail
开发者ID:dmbaggett,项目名称:pyasn1,代码行数:39,代码来源:decoder.py

示例15: valueDecoder

 def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun):
     head, tail = substrate[:length], substrate[length:]
     if not head or length != 1:
         raise error.PyAsn1Error("Not single-octet Boolean payload")
     byte = oct2int(head[0])
     # CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while
     # BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1
     # in http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
     if byte == 0xFF:
         value = 1
     elif byte == 0x00:
         value = 0
     else:
         raise error.PyAsn1Error("Unexpected Boolean payload: %s" % byte)
     return self._createComponent(asn1Spec, tagSet, value), tail
开发者ID:vmurashev,项目名称:crystax-dev-utils,代码行数:15,代码来源:decoder.py


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