本文整理匯總了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)