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

Python basictypes.build函数代码示例

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

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



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

示例1: testBits

 def testBits(self):
     """Test bit basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyBits", [1, 2])
     self.assert_(isinstance(a, basictypes.Bits))
     self.assertEqual(a, [2, 1])
     self.assertEqual(a, (1, 2))
     self.assertEqual(a, set([1, 2]))
     self.assertEqual(a, ["second", "third"])
     self.assertEqual(a, set(["second", "third"]))
     self.assertEqual(a, ["second", 2])
     self.assert_(a != ["second"])
     self.assertFalse(a == ["second"])
     self.assertFalse(a != ["second", 2])
     a |= "last"
     a |= ["last", "second"]
     self.assertEqual(a, ["second", "last", "third"])
     self.assertEqual(str(a), "second(1), third(2), last(7)")
     a -= 1
     a -= 1
     self.assertEqual(a, ["last", "third"])
     self.assertEqual(a & "last", True)
     self.assertEqual(a & "second", False)
     self.assertEqual(a & ["last", 2], True)
     self.assertEqual(a & set(["last", 2]), True)
     self.assertEqual(a & ["last", 0], True)
     self.assertEqual(a & ["second", 0], False)
     a = basictypes.build("SNIMPY-MIB", "snimpyBits",
                          set(["first", "second"]))
     self.assertEqual(a, [0, 1])
     a = basictypes.build("SNIMPY-MIB", "snimpyBits", [])
     self.assertEqual(a, [])
     self.assertEqual(str(a), "")
开发者ID:AudricP,项目名称:snimpy,代码行数:32,代码来源:test_basictypes.py


示例2: testOid

 def testOid(self):
     """Test OID basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyObjectId",
                          mib.get("SNIMPY-MIB", "snimpyInteger"))
     self.assert_(isinstance(a, basictypes.Oid))
     self.assertEqual(a, mib.get("SNIMPY-MIB", "snimpyInteger"))
     self.assertEqual(a, mib.get("SNIMPY-MIB", "snimpyInteger").oid)
     # Suboid
     self.assert_((list(mib.get("SNIMPY-MIB",
                                "snimpyInteger").oid) + [2, 3]) in a)
     self.assert_((list(mib.get("SNIMPY-MIB",
                                "snimpyInteger").oid)[:-1] +
                   [29, 3]) not in a)
     # Ability to extract a component
     self.assertEqual(a[0], 1)
     self.assertEqual(a[1], 3)
     self.assertEqual(a[-3], 45121)
     self.assertEqual(a[-1], 3)
     self.assertEqual(a[:3], (1, 3, 6))
     # Also accepts list
     a = basictypes.build("SNIMPY-MIB", "snimpyObjectId",
                          (1, 2, 3, 4))
     self.assertEqual(a, (1, 2, 3, 4))
     self.assert_((1, 2, 3, 4, 5) in a)
     self.assert_((3, 4, 5, 6) not in a)
开发者ID:AudricP,项目名称:snimpy,代码行数:25,代码来源:test_basictypes.py


示例3: testIsInstance

 def testIsInstance(self):
     """Test isinstance results"""
     self.assert_(isinstance(basictypes.build("SNIMPY-MIB",
                                              "snimpyInteger",
                                              18), long))
     self.assert_(isinstance(basictypes.build("SNIMPY-MIB",
                                              "snimpyString",
                                              "4521dgf"), str))
开发者ID:ajufrancis,项目名称:snimpy,代码行数:8,代码来源:testbasictypes.py


示例4: setAndCheck

 def setAndCheck(self, oid, value):
     """Set and check a value"""
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SNIMPY-MIB.mib"))
     ooid = mib.get("SNIMPY-MIB", oid).oid + (0,)
     self.session.set(ooid, basictypes.build("SNIMPY-MIB", oid, value))
     self.assertEqual(
         basictypes.build("SNIMPY-MIB", oid, self.session.get(ooid)[0][1]),
         basictypes.build("SNIMPY-MIB", oid, value),
     )
开发者ID:mirceaulinic,项目名称:snimpy,代码行数:9,代码来源:test_snmp.py


示例5: testString

 def testString(self):
     """Test string basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyString", b"hello")
     self.assert_(isinstance(a, basictypes.String))
     self.assertEqual(a, "hello")
     self.assertEqual(a + " john", "hello john")
     self.assertEqual(a * 2, "hellohello")
     a = basictypes.build("SNIMPY-MIB", "snimpyString", b"hello john")
     self.assert_("john" in a)
     self.assert_("steve" not in a)
     self.assertEqual(a[1], 'e')
     self.assertEqual(a[1:4], 'ell')
     self.assertEqual(len(a), 10)
开发者ID:AudricP,项目名称:snimpy,代码行数:13,代码来源:test_basictypes.py


示例6: testBoolean

 def testBoolean(self):
     """Test boolean basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyBoolean", True)
     self.assert_(isinstance(a, basictypes.Boolean))
     self.assertEqual(a, True)
     self.assert_(a)
     self.assert_(not(not(a)))
     self.assertEqual(not(a), False)
     a = basictypes.build("SNIMPY-MIB", "snimpyBoolean", "false")
     self.assertEqual(a, False)
     b = basictypes.build("SNIMPY-MIB", "snimpyBoolean", True)
     self.assertEqual(a or b, True)
     self.assertEqual(a and b, False)
开发者ID:AudricP,项目名称:snimpy,代码行数:13,代码来源:test_basictypes.py


示例7: testDisplay

 def testDisplay(self):
     """Test string transformation"""
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       18).display(), "0.18")
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       8).display(), "0.08")
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       288).display(), "2.88")
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       28801).display(), "288.01")
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyString",
                                       "test").display(), "test")
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyString",
                                       "tes\x05").display(), "0x74 65 73 05")
     a = basictypes.build("SNIMPY-MIB",
                          "snimpyString",
                          "test")
     self.assertEqual(a._display("255a"), "test")
     self.assertEqual(a._display("1x:"), "74:65:73:74")
     self.assertEqual(a._display("2a:"), "te:st")
     self.assertEqual(a._display("3a:"), "tes:t")
     self.assertEqual(a._display("4a"), "test")
     self.assertEqual(a._display("2o+1a"), "072145+st")
     a = basictypes.build("SNIMPY-MIB",
                          "snimpyString",
                          "\x03testtest...")
     self.assertEqual(a._display("*2a:+255a"), "te:st:te+st...")
开发者ID:ajufrancis,项目名称:snimpy,代码行数:33,代码来源:testbasictypes.py


示例8: testPacking

 def testPacking(self):
     """Test pack() function"""
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyString",
                                       "Hello world").pack(),
                      rfc1902.OctetString("Hello world"))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       18).pack(),
                      rfc1902.Integer(18))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyInteger",
                                       1804).pack(),
                      rfc1902.Integer(1804))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyEnum",
                                       "testing").pack(),
                      rfc1902.Integer(3))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyIpAddress",
                                       "10.11.12.13").pack(),
                      rfc1902.IpAddress("10.11.12.13"))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyObjectId",
                                       (1, 2, 3, 4)).pack(),
                      rfc1902.univ.ObjectIdentifier((1, 2, 3, 4)))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyTimeticks",
                                       timedelta(3, 2)).pack(),
                      rfc1902.TimeTicks(3 * 3600 * 24 * 100 + 2 * 100))
     self.assertEqual(basictypes.build("SNIMPY-MIB",
                                       "snimpyBits",
                                       [1, 7]).pack(),
                      rfc1902.Bits(b"\x41"))
开发者ID:AudricP,项目名称:snimpy,代码行数:34,代码来源:test_basictypes.py


示例9: testRepr

 def testRepr(self):
     """Test representation"""
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyInteger",
                                            18)), "<Integer: 0.18>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyObjectId",
                                            (1, 3, 6, 1, 4, 1,
                                             45, 3, 52, 1))),
                      "<Oid: 1.3.6.1.4.1.45.3.52.1>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyIpAddress",
                                            "124.24.14.3")),
                      "<IpAddress: 124.24.14.3>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyString",
                                            "45754dfgf")),
                      "<String: 45754dfgf>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyEnum",
                                            2)),
                      "<Enum: down(2)>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyBoolean",
                                            False)),
                      "<Boolean: false(2)>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyCounter",
                                            4547)),
                      "<Unsigned32: 4547>")
     self.assertEqual(repr(basictypes.build("SNIMPY-MIB",
                                            "snimpyBits",
                                            ["first", "second"])),
                      "<Bits: first(0), second(1)>")
开发者ID:AudricP,项目名称:snimpy,代码行数:34,代码来源:test_basictypes.py


示例10: testIpAddress

 def testIpAddress(self):
     """Test IP address basic type"""
     self.assertRaises(ValueError,
                       basictypes.build,
                       "SNIMPY-MIB", "snimpyIpAddress", "999.5.6.4")
     a = basictypes.build("SNIMPY-MIB", "snimpyIpAddress", "10.0.4.5")
     self.assert_(isinstance(a, basictypes.IpAddress))
     self.assertEqual(a, "10.0.4.5")
     self.assertEqual(a, "10.00.4.05")
     self.assertEqual(a, [10,0,4,5])
     self.assertEqual(a[2], 4)
     self.assert_(a < "10.1.2.4")
     self.assert_(a > "10.0.0.1")
     a = basictypes.build("SNIMPY-MIB", "snimpyIpAddress", [1, 2, 3, 5])
     self.assertEqual(a, "1.2.3.5")
开发者ID:ajufrancis,项目名称:snimpy,代码行数:15,代码来源:testbasictypes.py


示例11: testGetMacAddress

 def testGetMacAddress(self):
     """Get a MAC address"""
     mib.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SNIMPY-MIB.mib"))
     oid, a = self.session.get((1, 3, 6, 1, 2, 1, 45121, 1, 15, 0))[0]
     self.assertEqual(a, b"\x11\x12\x13\x14\x15\x16")
     b = basictypes.build("SNIMPY-MIB", "snimpyMacAddress", a)
     self.assertEqual(b, "11:12:13:14:15:16")
开发者ID:mirceaulinic,项目名称:snimpy,代码行数:7,代码来源:test_snmp.py


示例12: testStringFromBytes

 def testStringFromBytes(self):
     """Test string basic type when built from bytes"""
     a = basictypes.build("SNIMPY-MIB", "snimpyString", b"hello")
     self.assert_(isinstance(a, basictypes.String))
     self.assertEqual(a, "hello")
     self.assertEqual(a + " john", "hello john")
     self.assertEqual(a * 2, "hellohello")
开发者ID:AudricP,项目名称:snimpy,代码行数:7,代码来源:test_basictypes.py


示例13: testInteger

 def testInteger(self):
     """Test integer basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyInteger", 18)
     self.assert_(isinstance(a, basictypes.Integer))
     self.assertEqual(a, 18)
     self.assertEqual(a+10, 28)
     a = basictypes.build("SNIMPY-MIB", "snimpyInteger", 4)
     self.assertEqual(a, 4)
     self.assertEqual(a*4, 16)
     a = basictypes.build("SNIMPY-MIB", "snimpyInteger", 5)
     self.assertEqual(a, 5)
     self.assert_(a < 6)
     # self.assert_(a > 4.6) # type coercion does not work
     self.assert_(a > 4)
     self.assertRaises(TypeError,
                       basictypes.build, ("SNIMPY-MIB", "snimpyInteger", [1,2,3]))
开发者ID:ajufrancis,项目名称:snimpy,代码行数:16,代码来源:testbasictypes.py


示例14: testEnum

 def testEnum(self):
     """Test enum basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyEnum", 1)
     self.assert_(isinstance(a, basictypes.Enum))
     self.assertEqual(a, 1)
     self.assertEqual(a, "up")
     a = basictypes.build("SNIMPY-MIB", "snimpyEnum", "down")
     self.assertEqual(a, "down")
     self.assert_(a != "up")
     self.assertEqual(a, 2)
     self.assertEqual(str(a), "down(2)")
     self.assertRaises(ValueError,
                       basictypes.build,
                       "SNIMPY-MIB", "snimpyEnum", "unknown")
     self.assertEqual(str(a), "down(2)")
     a = basictypes.build("SNIMPY-MIB", "snimpyEnum", 54)
     self.assertEqual(a, 54)
开发者ID:AudricP,项目名称:snimpy,代码行数:17,代码来源:test_basictypes.py


示例15: testInexistentBits

    def testInexistentBits(self):
        """Check we cannot set inexistent bits"""
        a = basictypes.build("SNIMPY-MIB", "snimpyBits", [1, 2])
        self.assert_(a & 1)

        def nope(a):
            a |= 3
        self.assertRaises(ValueError, nope, a)
开发者ID:AudricP,项目名称:snimpy,代码行数:8,代码来源:test_basictypes.py


示例16: testLikeAString

 def testLikeAString(self):
     """Test String is like str"""
     a = basictypes.build("SNIMPY-MIB",
                          "snimpyString",
                          "4521dgf")
     self.assert_(a.startswith("4521"))
     self.assertEqual(a.upper(), "4521DGF")
     self.assert_(re.match("[0-9]+[defg]+", a))
开发者ID:AudricP,项目名称:snimpy,代码行数:8,代码来源:test_basictypes.py


示例17: testOid

 def testOid(self):
     """Test OID basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyObjectId",
                          mib.get("SNIMPY-MIB", "snimpyInteger"))
     self.assert_(isinstance(a, basictypes.Oid))
     self.assertEqual(a, mib.get("SNIMPY-MIB", "snimpyInteger"))
     self.assertEqual(a, mib.get("SNIMPY-MIB", "snimpyInteger").oid)
     # Suboid
     self.assert_((list(mib.get("SNIMPY-MIB",
                                "snimpyInteger").oid) + [2,3]) in a)
     self.assert_((list(mib.get("SNIMPY-MIB",
                                "snimpyInteger").oid)[:-1] + [29,3]) not in a)
     # Also accepts list
     a = basictypes.build("SNIMPY-MIB", "snimpyObjectId",
                          (1,2,3,4))
     self.assertEqual(a, (1,2,3,4))
     self.assert_((1,2,3,4,5) in a)
     self.assert_((3,4,5,6) not in a)
开发者ID:ajufrancis,项目名称:snimpy,代码行数:18,代码来源:testbasictypes.py


示例18: testTimeticks

 def testTimeticks(self):
     """Test timeticks basic type"""
     a = basictypes.build("SNIMPY-MIB", "snimpyTimeticks", 676544)
     self.assert_(isinstance(a, basictypes.Timeticks))
     # We can compare to int but otherwise, this is a timedelta
     self.assertEqual(a, 676544)
     self.assertEqual(str(a), '1:52:45.440000')
     self.assertEqual(a, timedelta(0, 6765, 440000))
     a = basictypes.build("SNIMPY-MIB", "snimpyTimeticks",
                          timedelta(1, 3))
     self.assertEqual(str(a), '1 day, 0:00:03')
     self.assertEqual(a, (3+3600*24)*100)
     self.assert_(a != (3+3600*24)*100 + 1)
     self.assert_(a < timedelta(1,4))
     self.assert_(a > timedelta(1,1))
     self.assert_(a > 654)
     self.assert_(a >= 654)
     self.assert_(a < (3+3600*24)*100 + 2)
开发者ID:ajufrancis,项目名称:snimpy,代码行数:18,代码来源:testbasictypes.py


示例19: testStringEncoding

 def testStringEncoding(self):
     """Test we can create an UTF-8 encoded string"""
     a = basictypes.build("SNIMPY-MIB", "snimpyString", u"hello")
     self.assertEqual(a, u"hello")
     self.assertEqual(a, "hello")
     a = basictypes.build(
         "SNIMPY-MIB",
         "snimpyUnicodeString",
         u"\U0001F60E Hello")
     self.assertEqual(a, u"\U0001F60E Hello")
     a = basictypes.build(
         "SNIMPY-MIB",
         "snimpyUnicodeString",
         b'\xf0\x9f\x98\x8e Hello')
     self.assertEqual(a, u"\U0001F60E Hello")
     self.assertRaises(UnicodeError,
                       basictypes.build, "SNIMPY-MIB", "snimpyString",
                       b'\xf0\x9f\x98\x8e Hello')
开发者ID:AudricP,项目名称:snimpy,代码行数:18,代码来源:test_basictypes.py


示例20: testInputFormat

    def testInputFormat(self):
        """Test we can input a string with a given format"""
        with mock.patch("snimpy.mib.Node.fmt",
                        new_callable=mock.PropertyMock) as e:
            e.return_value = "255a"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"test")
            self.assertEqual(a.pack(), b"test")
            e.return_value = "1x:"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"74:65:73:74")
            self.assertEqual(a.pack(), b"test")
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"74:6:73:4")
            self.assertEqual(a.pack(), b"t\x06s\x04")
            e.return_value = "2a:"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"te:st")
            self.assertEqual(a.pack(), b"test")
            e.return_value = "3a:"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"tes:t")
            self.assertEqual(a.pack(), b"test")
            e.return_value = "4a"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"test")
            self.assertEqual(a.pack(), b"test")
            e.return_value = "2o+1a"
            a = basictypes.build("SNIMPY-MIB", "snimpyString", u"072145+st")
            self.assertEqual(a.pack(), b"test")

            e.return_value = "*2a:+255a"
            a = basictypes.build(
                "SNIMPY-MIB",
                "snimpyString",
                u"te:st:te+st...")
            self.assertEqual(a.pack(), b"\x03testtest...")

            e.return_value = "2a1x:"
            a = basictypes.build("SNIMPY-MIB", "snimpyString",
                                 u"aa74:65:73:74")
            self.assertEqual(a.pack(), b"aatest")

            e.return_value = "*[email protected]:-*3a?="
            a = basictypes.build("SNIMPY-MIB", "snimpyString",
                                 u"[email protected]?tes=tes?tes?tes")
            self.assertEqual(a.pack(), b"\x04testtestZ\x02testes\x03testestes")
开发者ID:pombredanne,项目名称:snimpy,代码行数:41,代码来源:test_basictypes.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mib.get函数代码示例发布时间:2022-05-27
下一篇:
Python ffi.string函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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