当前位置: 首页>>代码示例>>Python>>正文


Python protocol.TFTP类代码示例

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


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

示例1: 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)
开发者ID:deepakhajare,项目名称:maas,代码行数:7,代码来源:test_protocol.py

示例2: 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)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:7,代码来源:test_protocol.py

示例3: BackendCallingContext

class BackendCallingContext(unittest.TestCase):

    def setUp(self):
        super(BackendCallingContext, self).setUp()
        self.backend = ContextCapturingBackend("local", "remote")
        self.tftp = TFTP(self.backend)
        self.tftp.transport = HostTransport(("12.34.56.78", 1234))

    @inlineCallbacks
    def test_context_rrq(self):
        rrq_datagram = RRQDatagram('nonempty', 'NetASCiI', {})
        rrq_addr = ('127.0.0.1', 1069)
        error = yield self.assertFailure(
            self.tftp._startSession(rrq_datagram, rrq_addr, "octet"),
            CapturedContext)
        self.assertEqual(("get_reader", rrq_datagram.filename), error.args)
        self.assertEqual(
            {"local": self.tftp.transport.host, "remote": rrq_addr},
            error.context)

    @inlineCallbacks
    def test_context_wrq(self):
        wrq_datagram = WRQDatagram('nonempty', 'NetASCiI', {})
        wrq_addr = ('127.0.0.1', 1069)
        error = yield self.assertFailure(
            self.tftp._startSession(wrq_datagram, wrq_addr, "octet"),
            CapturedContext)
        self.assertEqual(("get_writer", wrq_datagram.filename), error.args)
        self.assertEqual(
            {"local": self.tftp.transport.host, "remote": wrq_addr},
            error.context)
开发者ID:deepakhajare,项目名称:maas,代码行数:31,代码来源:test_protocol.py

示例4: SuccessfulAsyncDispatch

class SuccessfulAsyncDispatch(unittest.TestCase):

    def setUp(self):
        self.clock = Clock()
        self.tmp_dir_path = tempfile.mkdtemp()
        with FilePath(self.tmp_dir_path).child('nonempty').open('w') as fd:
            fd.write('Something uninteresting')
        self.backend = FilesystemAsyncBackend(self.tmp_dir_path, self.clock)
        self.tftp = TFTP(self.backend, self.clock)

    def test_get_reader_defers(self):
        rrq_datagram = RRQDatagram('nonempty', 'NetASCiI', {})
        rrq_addr = ('127.0.0.1', 1069)
        rrq_mode = "octet"
        d = self.tftp._startSession(rrq_datagram, rrq_addr, rrq_mode)
        self.assertFalse(d.called)
        self.clock.advance(1)
        self.assertTrue(d.called)
        self.assertTrue(IReader.providedBy(d.result.backend))

    def test_get_writer_defers(self):
        wrq_datagram = WRQDatagram('foobar', 'NetASCiI', {})
        wrq_addr = ('127.0.0.1', 1069)
        wrq_mode = "octet"
        d = self.tftp._startSession(wrq_datagram, wrq_addr, wrq_mode)
        self.assertFalse(d.called)
        self.clock.advance(1)
        self.assertTrue(d.called)
        self.assertTrue(IWriter.providedBy(d.result.backend))
开发者ID:deepakhajare,项目名称:maas,代码行数:29,代码来源:test_protocol.py

示例5: test_non_rq_datagram

 def test_non_rq_datagram(self):
     tftp = TFTP(DummyBackend(), _clock=self.clock)
     tftp.transport = self.transport
     ack_datagram = ACKDatagram(14)
     tftp.datagramReceived(ack_datagram.to_wire(), ("127.0.0.1", 1111))
     self.failIf(self.transport.disconnecting)
     self.failIf(self.transport.value())
开发者ID:shylent,项目名称:python-tx-tftp,代码行数:7,代码来源:test_protocol.py

示例6: SuccessfulAsyncDispatch

class SuccessfulAsyncDispatch(unittest.TestCase):
    def setUp(self):
        self.clock = Clock()
        self.temp_dir = FilePath(tempfile.mkdtemp()).asBytesMode()
        with self.temp_dir.child(b"nonempty").open("w") as fd:
            fd.write(b"Something uninteresting")
        self.backend = FilesystemAsyncBackend(self.temp_dir, self.clock)
        self.tftp = TFTP(self.backend, self.clock)

    def test_get_reader_defers(self):
        rrq_datagram = RRQDatagram(b"nonempty", b"NetASCiI", {})
        rrq_addr = ("127.0.0.1", 1069)
        rrq_mode = b"octet"
        d = self.tftp._startSession(rrq_datagram, rrq_addr, rrq_mode)
        self.assertFalse(d.called)
        self.clock.advance(1)
        self.assertTrue(d.called)
        self.assertTrue(IReader.providedBy(d.result.backend))

    def test_get_writer_defers(self):
        wrq_datagram = WRQDatagram(b"foobar", b"NetASCiI", {})
        wrq_addr = ("127.0.0.1", 1069)
        wrq_mode = b"octet"
        d = self.tftp._startSession(wrq_datagram, wrq_addr, wrq_mode)
        self.assertFalse(d.called)
        self.clock.advance(1)
        self.assertTrue(d.called)
        self.assertTrue(IWriter.providedBy(d.result.backend))
开发者ID:shylent,项目名称:python-tx-tftp,代码行数:28,代码来源:test_protocol.py

示例7: 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)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:7,代码来源:test_protocol.py

示例8: setUp

 def setUp(self):
     self.clock = Clock()
     self.tmp_dir_path = tempfile.mkdtemp()
     with FilePath(self.tmp_dir_path).child('nonempty').open('w') as fd:
         fd.write('Something uninteresting')
     self.backend = FilesystemAsyncBackend(self.tmp_dir_path, self.clock)
     self.tftp = TFTP(self.backend, self.clock)
开发者ID:deepakhajare,项目名称:maas,代码行数:7,代码来源:test_protocol.py

示例9: setUp

 def setUp(self):
     self.clock = Clock()
     self.temp_dir = FilePath(tempfile.mkdtemp()).asBytesMode()
     with self.temp_dir.child(b"nonempty").open("w") as fd:
         fd.write(b"Something uninteresting")
     self.backend = FilesystemAsyncBackend(self.temp_dir, self.clock)
     self.tftp = TFTP(self.backend, self.clock)
开发者ID:shylent,项目名称:python-tx-tftp,代码行数:7,代码来源:test_protocol.py

示例10: _startSession

    def _startSession(self, *args, **kwargs):
        d = TFTP._startSession(self, *args, **kwargs)

        def save_session(session):
            self.session = session
            return session

        d.addCallback(save_session)
        return d
开发者ID:deepakhajare,项目名称:maas,代码行数:9,代码来源:test_protocol.py

示例11: 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)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:13,代码来源:test_protocol.py

示例12: 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)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:13,代码来源:test_protocol.py

示例13: 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)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:13,代码来源:test_protocol.py

示例14: test_malformed_datagram

 def test_malformed_datagram(self):
     tftp = TFTP(BackendFactory(), _clock=self.clock)
     tftp.datagramReceived(b"foobar", ("127.0.0.1", 1111))
     self.assertFalse(self.transport.disconnecting)
     self.assertFalse(self.transport.value())
开发者ID:shylent,项目名称:python-tx-tftp,代码行数:5,代码来源:test_protocol.py

示例15: test_malformed_datagram

 def test_malformed_datagram(self):
     tftp = TFTP(BackendFactory(), _clock=self.clock)
     tftp.datagramReceived('foobar', ('127.0.0.1', 1111))
     self.failIf(self.transport.disconnecting)
     self.failIf(self.transport.value())
开发者ID:deepakhajare,项目名称:maas,代码行数:5,代码来源:test_protocol.py


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