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

Python octets.str2octs函数代码示例

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

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



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

示例1: testCount

 def testCount(self):
     self.s1.clear()
     for x in ['abc', 'def', 'abc']:
         self.s1.append(x)
     assert self.s1.count(str2octs('abc')) == 2
     assert self.s1.count(str2octs('def')) == 1
     assert self.s1.count(str2octs('ghi')) == 0
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例2: testSort

 def testSort(self):
     self.s1.clear()
     self.s1[0] = 'b'
     self.s1[1] = 'a'
     assert list(self.s1) == [str2octs('b'), str2octs('a')]
     self.s1.sort()
     assert list(self.s1) == [str2octs('a'), str2octs('b')]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例3: testIndex

 def testIndex(self):
     self.s1.clear()
     for x in ['abc', 'def', 'abc']:
         self.s1.append(x)
     assert self.s1.index(str2octs('abc')) == 0
     assert self.s1.index(str2octs('def')) == 1
     assert self.s1.index(str2octs('abc'), 1) == 2
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例4: testUpdate

 def testUpdate(self):
     self.s1.clear()
     assert list(self.s1.values()) == [str2octs(''), str2octs(''), 34]
     self.s1.update(**{'name': 'abc', 'nick': 'def', 'age': 123})
     assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'abc'), ('nick', 'def')]] + [('age', 123)]
     self.s1.update(('name', 'ABC'))
     assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'ABC'), ('nick', 'def')]] + [('age', 123)]
     self.s1.update(name='CBA')
     assert list(self.s1.items()) == [(x[0], str2octs(x[1])) for x in [('name', 'CBA'), ('nick', 'def')]] + [('age', 123)]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:9,代码来源:test_univ.py


示例5: testExtend

 def testExtend(self):
     self.s1.clear()
     self.s1.setComponentByPosition(0, univ.OctetString('abc'))
     assert len(self.s1) == 1
     self.s1.extend(['def', 'ghi'])
     assert len(self.s1) == 3
     assert list(self.s1) == [str2octs(x) for x in ['abc', 'def', 'ghi']]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例6: testOuterByTypeWithInstanceValue

 def testOuterByTypeWithInstanceValue(self):
     self.s1.setComponentByType(
         univ.OctetString.tagSet, univ.OctetString('abc')
     )
     assert self.s1.getComponentByType(
         univ.OctetString.tagSet
     ) == str2octs('abc')
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例7: searchRecordByOid

def searchRecordByOid(oid, fileObj, textParser, eol=str2octs('\n')):
    lo = mid = 0; prev_mid = -1
    fileObj.seek(0, 2)
    hi = sz = fileObj.tell()
    while lo < hi:
        mid = (lo+hi)//2
        fileObj.seek(mid)
        while mid:
            c = fileObj.read(1)
            if c == eol:
                mid = mid + 1
                break
            mid = mid - 1    # pivot stepping back in search for full line
            fileObj.seek(mid)
        if mid == prev_mid:  # loop condition due to stepping back pivot
            break
        if mid >= sz:
            return sz
        line, _, skippedOffset = getRecord(fileObj)
        if not line:
            return hi
        midval, _ = textParser.evaluate(line, oidOnly=True)
        if midval < oid:
            lo = mid + skippedOffset + len(line)
        elif midval > oid:
            hi = mid
        else:
            return mid
        prev_mid = mid
    if lo == mid:
        return lo
    else:
        return hi
开发者ID:woodyle,项目名称:snmpsim,代码行数:33,代码来源:file.py


示例8: testIndefModeChunkedSubst

 def testIndefModeChunkedSubst(self):
     assert decoder.decode(
         ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111,
                    120, 0, 0)),
         substrateFun=lambda a, b, c: (b, str2octs(''))
     ) == (ints2octs(
         (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), str2octs(''))
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_decoder.py


示例9: testIndefModeChunked

 def testIndefModeChunked(self):
     assert decoder.decode(
         ints2octs(
             (
                 36,
                 128,
                 4,
                 4,
                 81,
                 117,
                 105,
                 99,
                 4,
                 4,
                 107,
                 32,
                 98,
                 114,
                 4,
                 4,
                 111,
                 119,
                 110,
                 32,
                 4,
                 3,
                 102,
                 111,
                 120,
                 0,
                 0,
             )
         )
     ) == (str2octs("Quick brown fox"), null)
开发者ID:shobull,项目名称:hue,代码行数:34,代码来源:test_decoder.py


示例10: __searchOid

 def __searchOid(self, oid, eol=str2octs('\n')):
     lo = mid = 0; prev_mid = -1;
     self.__text.seek(0, 2)
     hi = sz = self.__text.tell()
     while lo < hi:
         mid = (lo+hi)//2
         self.__text.seek(mid)
         while mid:
             c = self.__text.read(1)
             if c == eol:
                 mid = mid + 1
                 break
             mid = mid - 1    # pivot stepping back in search for full line
             self.__text.seek(mid)
         if mid == prev_mid:  # loop condition due to stepping back pivot
             break
         if mid >= sz:
             return sz
         line = self.__text.readline()
         midval, _ = self.__textParser.evaluate(line, oidOnly=True)
         if midval < oid:
             lo = mid + len(line)
         elif midval > oid:
             hi = mid
         else:
             return mid
         prev_mid = mid
     if lo == mid:
         return lo
     else:
         return hi
开发者ID:richb-hanover,项目名称:websnmpsim,代码行数:31,代码来源:snmpsimd.py


示例11: testAppend

 def testAppend(self):
     self.s1.clear()
     self.s1.setComponentByPosition(0, univ.OctetString('abc'))
     assert len(self.s1) == 1
     self.s1.append('def')
     assert len(self.s1) == 2
     assert list(self.s1) == [str2octs(x) for x in ['abc', 'def']]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例12: testWithoutSchema

 def testWithoutSchema(self):
     s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))
     s2, r = decoder.decode(
         ints2octs((163, 15, 48, 13, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110))
     )
     assert not r
     assert s2 == [str2octs('quick brown')]
     assert s.tagSet == s2.tagSet
开发者ID:luke-chang,项目名称:gecko-1,代码行数:8,代码来源:test_decoder.py


示例13: testTypeCheckOnAssignment

    def testTypeCheckOnAssignment(self):

        self.s.clear()

        self.s['blob'] = univ.Any(str2octs('xxx'))

        # this should succeed because Any is untagged and unconstrained
        self.s['blob'] = univ.Integer(123)
开发者ID:etingof,项目名称:pyasn1,代码行数:8,代码来源:test_opentype.py


示例14: testStaticDef

    def testStaticDef(self):

        class SequenceOf(univ.SequenceOf):
            componentType = univ.OctetString('')

        s = SequenceOf()
        s[0] = 'abc'
        assert len(s) == 1
        assert s == [str2octs('abc')]
开发者ID:luke-chang,项目名称:gecko-1,代码行数:9,代码来源:test_univ.py


示例15: getRecord

def getRecord(fileObj, lineNo=None, offset=0):
    line = fileObj.readline()
    if lineNo is not None and line: lineNo += 1
    while line:
        tline = line.strip()
        # skip comment or blank line
        if not tline or tline.startswith(str2octs('#')):
            offset += len(line)
            line = fileObj.readline()
            if lineNo is not None and line: lineNo += 1
        else:
            break
    return line, lineNo, offset
开发者ID:woodyle,项目名称:snmpsim,代码行数:13,代码来源:file.py


示例16: testSubtypeSpec

 def testSubtypeSpec(self):
     s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion(
         constraint.SingleValueConstraint(str2octs('abc'))
         ))
     try:
         s.setComponentByPosition(0, univ.OctetString('abc'))
     except:
         assert 0, 'constraint fails'
     try:
         s.setComponentByPosition(1, univ.OctetString('Abc'))
     except:
         pass
     else:
         assert 0, 'constraint fails'
开发者ID:dmbaggett,项目名称:pyasn1,代码行数:14,代码来源:univ.py


示例17: lookup

    def lookup(self, oid):
        """ Returns the record which oid is exactly the given one or None if the record doesn't exist """

        # Issue #4: Synchronizes access to the database
        self.__lock.acquire(True);
        try:
            oid, is_subtree, tag, val = self.__db[oid].split(str2octs(','), 3)
        finally:
            self.__lock.release();

        try:
            tag_class = self.str2class(tag);
        except Exception:
            logger.error ( 'Could not interpret tag %s', tag, exc_info=True );
            raise
        return univ.ObjectIdentifier(oid), is_subtree, tag_class, tag_class(val)
开发者ID:GillesBouissac,项目名称:agentcluster,代码行数:16,代码来源:database.py


示例18: 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


示例19: testComponentConstraintsMatching

 def testComponentConstraintsMatching(self):
     s = self.s1.clone()
     o = univ.OctetString().subtype(
         subtypeSpec=constraint.ConstraintsUnion(constraint.SingleValueConstraint(str2octs('cba'))))
     s.strictConstraints = True
     try:
         s.setComponentByName('name', o.clone('cba'))
     except PyAsn1Error:
         pass
     else:
         assert 0, 'inner supertype constraint allowed'
     s.strictConstraints = False
     try:
         s.setComponentByName('name', o.clone('cba'))
     except PyAsn1Error:
         assert 0, 'inner supertype constraint disallowed'
     else:
         pass
开发者ID:lanconnected,项目名称:pyasn1,代码行数:18,代码来源:test_univ.py


示例20: testSubtypeSpec

 def testSubtypeSpec(self):
     s = self.s1.clone(subtypeSpec=constraint.ConstraintsUnion(
         constraint.SingleValueConstraint(str2octs('abc'))
     ))
     try:
         s.setComponentByPosition(0, univ.OctetString('abc'))
     except PyAsn1Error:
         assert 0, 'constraint fails'
     try:
         s.setComponentByPosition(1, univ.OctetString('Abc'))
     except PyAsn1Error:
         try:
             s.setComponentByPosition(1, univ.OctetString('Abc'),
                                      verifyConstraints=False)
         except PyAsn1Error:
             assert 0, 'constraint failes with verifyConstraints=True'
     else:
         assert 0, 'constraint fails'
开发者ID:luke-chang,项目名称:gecko-1,代码行数:18,代码来源:test_univ.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pem.readBase64fromText函数代码示例发布时间:2022-05-25
下一篇:
Python octets.oct2int函数代码示例发布时间: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