本文整理汇总了Python中tftp.datagram.ERRORDatagram.from_wire方法的典型用法代码示例。如果您正苦于以下问题:Python ERRORDatagram.from_wire方法的具体用法?Python ERRORDatagram.from_wire怎么用?Python ERRORDatagram.from_wire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tftp.datagram.ERRORDatagram
的用法示例。
在下文中一共展示了ERRORDatagram.from_wire方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error
# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_wire [as 别名]
def test_error(self):
# Zero-length payload
self.assertRaises(WireProtocolError, ERRORDatagram.from_wire, '')
# One byte payload
self.assertRaises(WireProtocolError, ERRORDatagram.from_wire, '\x00')
# Errorcode only (maybe this should fail)
dgram = ERRORDatagram.from_wire('\x00\x01')
self.assertEqual(dgram.errorcode, 1)
self.assertEqual(dgram.errmsg, errors[1])
# Errorcode with errstring - not terminated
dgram = ERRORDatagram.from_wire('\x00\x01foobar')
self.assertEqual(dgram.errorcode, 1)
self.assertEqual(dgram.errmsg, 'foobar')
# Errorcode with errstring - terminated
dgram = ERRORDatagram.from_wire('\x00\x01foobar\x00')
self.assertEqual(dgram.errorcode, 1)
self.assertEqual(dgram.errmsg, 'foobar')
# Unknown errorcode
self.assertRaises(WireProtocolError, ERRORDatagram.from_wire, '\x00\x0efoobar')
# Unknown errorcode in from_code
self.assertRaises(WireProtocolError, ERRORDatagram.from_code, 13)
# from_code with custom message
dgram = ERRORDatagram.from_code(3, "I've accidentally the whole message")
self.assertEqual(dgram.errorcode, 3)
self.assertEqual(dgram.errmsg, "I've accidentally the whole message")
self.assertEqual(dgram.to_wire(), "\x00\x05\x00\x03I've accidentally the whole message\x00")
# from_code default message
dgram = ERRORDatagram.from_code(3)
self.assertEqual(dgram.errorcode, 3)
self.assertEqual(dgram.errmsg, "Disk full or allocation exceeded")
self.assertEqual(dgram.to_wire(), "\x00\x05\x00\x03Disk full or allocation exceeded\x00")
示例2: test_error_codes
# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_wire [as 别名]
def test_error_codes(self):
# Error codes 0 to 8 are formally defined for TFTP (as of 2015-02-04).
for errorcode in range(0, 9):
data = struct.pack("!H", errorcode) + "message\x00"
dgram = ERRORDatagram.from_wire(data)
self.assertEqual(dgram.errorcode, errorcode)