本文整理汇总了Python中tftp.datagram.split_opcode函数的典型用法代码示例。如果您正苦于以下问题:Python split_opcode函数的具体用法?Python split_opcode怎么用?Python split_opcode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_opcode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_access_violation
def test_access_violation(self):
tftp = TFTP(BackendFactory(AccessViolation("No!")), _clock=self.clock)
tftp.transport = self.transport
wrq_datagram = WRQDatagram('foobar', 'netascii', {})
tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)
self.transport.clear()
rrq_datagram = RRQDatagram('foobar', 'octet', {})
tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_ACCESS_VIOLATION)
示例2: test_generic_backend_error
def test_generic_backend_error(self):
tftp = TFTP(BackendFactory(BackendError("A backend that couldn't")), _clock=self.clock)
tftp.transport = self.transport
rrq_datagram = RRQDatagram('foobar', 'netascii', {})
tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)
self.transport.clear()
rrq_datagram = RRQDatagram('foobar', 'octet', {})
tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)
示例3: test_unsupported
def test_unsupported(self):
tftp = TFTP(BackendFactory(Unsupported("I don't support you")), _clock=self.clock)
tftp.transport = self.transport
wrq_datagram = WRQDatagram('foobar', 'netascii', {})
tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
self.transport.clear()
rrq_datagram = RRQDatagram('foobar', 'octet', {})
tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
示例4: test_file_exists
def test_file_exists(self):
tftp = TFTP(BackendFactory(FileExists("Already have one")), _clock=self.clock)
tftp.transport = self.transport
wrq_datagram = WRQDatagram('foobar', 'netascii', {})
tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_FILE_EXISTS)
示例5: test_ACK_invalid_blocknum
def test_ACK_invalid_blocknum(self):
ack_datagram = ACKDatagram(3)
yield self.rs.datagramReceived(ack_datagram)
self.failIf(self.transport.disconnecting)
err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assert_(isinstance(err_dgram, ERRORDatagram))
self.addCleanup(self.rs.cancel)
示例6: test_file_not_found
def test_file_not_found(self):
tftp = TFTP(BackendFactory(FileNotFound("Not found")), _clock=self.clock)
tftp.transport = self.transport
rrq_datagram = RRQDatagram('foobar', 'netascii', {})
tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_FILE_NOT_FOUND)
示例7: test_invalid_tid
def test_invalid_tid(self):
self.rs.startProtocol()
data_datagram = DATADatagram(1, 'foobar')
yield self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
self.addCleanup(self.rs.cancel)
示例8: test_bad_mode
def test_bad_mode(self):
tftp = TFTP(DummyBackend(), _clock=self.clock)
tftp.transport = self.transport
wrq_datagram = WRQDatagram('foobar', 'badmode', {})
tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
error_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
示例9: test_invalid_tid
def test_invalid_tid(self):
data_datagram = DATADatagram(1, b'foobar')
self.rs.datagramReceived(data_datagram, ('127.0.0.1', 11111))
self.clock.advance(0.1)
err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(err_dgram.errorcode, ERR_TID_UNKNOWN)
self.addCleanup(self.rs.cancel)
示例10: cb
def cb(ign):
self.clock.advance(0.1)
self.failIf(self.transport.disconnecting)
data_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(data_datagram.data, 'line1')
self.failIf(self.rs.completed,
"Got enough bytes from the reader, there is no reason to stop")
示例11: cb_
def cb_(ign):
self.clock.advance(0.1)
self.failIf(self.transport.disconnecting)
ack_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assertEqual(ack_dgram.blocknum, 2)
self.failIf(self.ws.completed,
"Data length is equal to blocksize, no reason to stop")
示例12: datagramReceived
def datagramReceived(self, datagram, addr):
if self.remote[1] != addr[1]:
self.transport.write(ERRORDatagram.from_code(ERR_TID_UNKNOWN).to_wire())
return# Does not belong to this transfer
datagram = TFTPDatagramFactory(*split_opcode(datagram))
if datagram.opcode == OP_ERROR:
return self.tftp_ERROR(datagram)
return self._datagramReceived(datagram)
示例13: test_failed_write
def test_failed_write(self):
self.writer.cancel()
self.ws.writer = FailingWriter()
data_datagram = DATADatagram(1, 'foobar')
yield self.ws.datagramReceived(data_datagram)
self.flushLoggedErrors()
self.clock.advance(0.1)
err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.failUnless(isinstance(err_datagram, ERRORDatagram))
self.failUnless(self.transport.disconnecting)
示例14: test_DATA_invalid_blocknum
def test_DATA_invalid_blocknum(self):
self.ws.block_size = 6
data_datagram = DATADatagram(3, 'foobar')
yield self.ws.datagramReceived(data_datagram)
self.writer.finish()
self.failIf(self.target.open('r').read())
self.failIf(self.transport.disconnecting)
err_dgram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.assert_(isinstance(err_dgram, ERRORDatagram))
self.addCleanup(self.ws.cancel)
示例15: test_failed_read
def test_failed_read(self):
self.reader.finish()
self.rs.reader = FailingReader()
self.rs.blocknum = 1
ack_datagram = ACKDatagram(1)
yield self.rs.datagramReceived(ack_datagram)
self.flushLoggedErrors()
self.clock.advance(0.1)
err_datagram = TFTPDatagramFactory(*split_opcode(self.transport.value()))
self.failUnless(isinstance(err_datagram, ERRORDatagram))
self.failUnless(self.transport.disconnecting)