本文整理汇总了Python中snimpy.basictypes.build函数的典型用法代码示例。如果您正苦于以下问题:Python build函数的具体用法?Python build怎么用?Python build使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了build函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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), "")
示例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)
示例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))
示例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),
)
示例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)
示例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)
示例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...")
示例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"))
示例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)>")
示例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")
示例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")
示例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")
示例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]))
示例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)
示例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)