• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python datagram.ERRORDatagram类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_error

 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")
开发者ID:karlzheng,项目名称:bashrc,代码行数:31,代码来源:test_wire_protocol.py


示例2: datagramReceived

    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                "Unknown transfer mode %s, - expected "
                "'netascii' or 'octet' (case-insensitive)" % mode).to_wire(), addr)
        try:
            if datagram.opcode == OP_WRQ:
                fs_interface = self.backend.get_writer(datagram.filename)
            elif datagram.opcode == OP_RRQ:
                fs_interface = self.backend.get_reader(datagram.filename)
        except Unsupported, e:
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                                    str(e)).to_wire(), addr)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:17,代码来源:protocol.py


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


示例4: tftp_DATA

    def tftp_DATA(self, datagram):
        """Handle incoming DATA TFTP datagram

        @type datagram: L{DATADatagram}

        """
        next_blocknum = self.blocknum + 1
        if datagram.blocknum < next_blocknum:
            self.transport.write(ACKDatagram(datagram.blocknum).to_wire())
        elif datagram.blocknum == next_blocknum:
            if self.completed:
                self.transport.write(ERRORDatagram.from_code(
                    ERR_ILLEGAL_OP, b"Transfer already finished").to_wire())
            else:
                return self.nextBlock(datagram)
        else:
            self.transport.write(ERRORDatagram.from_code(
                ERR_ILLEGAL_OP, b"Block number mismatch").to_wire())
开发者ID:mont5piques,项目名称:python-tx-tftp,代码行数:18,代码来源:session.py


示例5: _startSession

 def _startSession(self, datagram, addr, mode):
     try:
         if datagram.opcode == OP_WRQ:
             fs_interface = yield self.backend.get_writer(datagram.filename)
         elif datagram.opcode == OP_RRQ:
             fs_interface = yield self.backend.get_reader(datagram.filename)
     except Unsupported, e:
         self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                                 str(e)).to_wire(), addr)
开发者ID:chronidev,项目名称:python-tx-tftp,代码行数:9,代码来源:protocol.py


示例6: _startSession

 def _startSession(self, datagram, addr, mode):
     # Set up a call context so that we can pass extra arbitrary
     # information to interested backends without adding extra call
     # arguments, or switching to using a request object, for example.
     context = {}
     if self.transport is not None:
         # Add the local and remote addresses to the call context.
         local = self.transport.getHost()
         context["local"] = local.host, local.port
         context["remote"] = addr
     try:
         if datagram.opcode == OP_WRQ:
             fs_interface = yield call(
                 context, self.backend.get_writer, datagram.filename)
         elif datagram.opcode == OP_RRQ:
             fs_interface = yield call(
                 context, self.backend.get_reader, datagram.filename)
     except Unsupported as e:
         self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
             u"{}".format(e).encode("ascii", "replace")).to_wire(), addr)
     except AccessViolation:
         self.transport.write(ERRORDatagram.from_code(ERR_ACCESS_VIOLATION).to_wire(), addr)
     except FileExists:
         self.transport.write(ERRORDatagram.from_code(ERR_FILE_EXISTS).to_wire(), addr)
     except FileNotFound:
         self.transport.write(ERRORDatagram.from_code(ERR_FILE_NOT_FOUND).to_wire(), addr)
     except BackendError as e:
         self.transport.write(ERRORDatagram.from_code(ERR_NOT_DEFINED,
             u"{}".format(e).encode("ascii", "replace")).to_wire(), addr)
     else:
         if datagram.opcode == OP_WRQ:
             if mode == b'netascii':
                 fs_interface = NetasciiReceiverProxy(fs_interface)
             session = RemoteOriginWriteSession(addr, fs_interface,
                                                datagram.options, _clock=self._clock)
             reactor.listenUDP(0, session)
             returnValue(session)
         elif datagram.opcode == OP_RRQ:
             if mode == b'netascii':
                 fs_interface = NetasciiSenderProxy(fs_interface)
             session = RemoteOriginReadSession(addr, fs_interface,
                                               datagram.options, _clock=self._clock)
             reactor.listenUDP(0, session)
             returnValue(session)
开发者ID:aivins,项目名称:python-tx-tftp,代码行数:44,代码来源:protocol.py


示例7: datagramReceived

    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if datagram.mode not in ('netascii', 'octet'):
            return self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                "Unknown transfer mode %s, - expected "
                "'netascii' or 'octet' (case-insensitive)" % mode).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
开发者ID:chronidev,项目名称:python-tx-tftp,代码行数:11,代码来源:protocol.py


示例8: datagramReceived

    def datagramReceived(self, datagram, addr):
        datagram = TFTPDatagramFactory(*split_opcode(datagram))
        log.msg("Datagram received from %s: %s" % (addr, datagram))

        mode = datagram.mode.lower()
        if mode not in (b'netascii', b'octet'):
            errmsg = (
                u"Unknown transfer mode '%s', - expected 'netascii' or 'octet'"
                u"(case-insensitive)" % mode.decode("ascii"))
            return self.transport.write(ERRORDatagram.from_code(
                ERR_ILLEGAL_OP, errmsg.encode("ascii", "replace")).to_wire(), addr)

        self._clock.callLater(0, self._startSession, datagram, addr, mode)
开发者ID:aivins,项目名称:python-tx-tftp,代码行数:13,代码来源:protocol.py


示例9: tftp_ACK

    def tftp_ACK(self, datagram):
        """Handle the incoming ACK TFTP datagram.

        @type datagram: L{ACKDatagram}

        """
        if datagram.blocknum < self.blocknum:
            log.msg("Duplicate ACK for blocknum %s" % datagram.blocknum)
        elif datagram.blocknum == self.blocknum:
            self.timeout_watchdog.cancel()
            if self.completed:
                log.msg("Final ACK received, transfer successful")
                self.cancel()
            else:
                return self.nextBlock()
        else:
            self.transport.write(ERRORDatagram.from_code(
                ERR_ILLEGAL_OP, b"Block number mismatch").to_wire())
开发者ID:mont5piques,项目名称:python-tx-tftp,代码行数:18,代码来源:session.py


示例10: _startSession

 def _startSession(self, datagram, addr, mode):
     # Set up a call context so that we can pass extra arbitrary
     # information to interested backends without adding extra call
     # arguments, or switching to using a request object, for example.
     context = {}
     if self.transport is not None:
         # Add the local and remote addresses to the call context.
         local = self.transport.getHost()
         context["local"] = local.host, local.port
         context["remote"] = addr
     try:
         if datagram.opcode == OP_WRQ:
             fs_interface = yield call(
                 context, self.backend.get_writer, datagram.filename)
         elif datagram.opcode == OP_RRQ:
             fs_interface = yield call(
                 context, self.backend.get_reader, datagram.filename)
     except Unsupported, e:
         self.transport.write(ERRORDatagram.from_code(ERR_ILLEGAL_OP,
                                 str(e)).to_wire(), addr)
开发者ID:alex-com,项目名称:python-tx-tftp,代码行数:20,代码来源:protocol.py


示例11: test_error_codes

 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)
开发者ID:karlzheng,项目名称:bashrc,代码行数:6,代码来源:test_wire_protocol.py


示例12: test_ERROR

 def test_ERROR(self):
     err_dgram = ERRORDatagram.from_code(ERR_NOT_DEFINED, 'no reason')
     self.ws.datagramReceived(err_dgram)
     self.clock.advance(0.1)
     self.failIf(self.transport.value())
     self.failUnless(self.transport.disconnecting)
开发者ID:rvbad,项目名称:python-tx-tftp,代码行数:6,代码来源:test_sessions.py


示例13: test_ERROR

 def test_ERROR(self):
     err_dgram = ERRORDatagram.from_code(ERR_NOT_DEFINED, "no reason")
     yield self.rs.datagramReceived(err_dgram)
     self.failIf(self.transport.value())
     self.failUnless(self.transport.disconnecting)
开发者ID:karlzheng,项目名称:bashrc,代码行数:5,代码来源:test_sessions.py


示例14: blockWriteFailure

 def blockWriteFailure(self, failure):
     """Write failed"""
     log.err(failure)
     self.transport.write(ERRORDatagram.from_code(ERR_DISK_FULL).to_wire())
     self.cancel()
开发者ID:mont5piques,项目名称:python-tx-tftp,代码行数:5,代码来源:session.py


示例15: readFailed

 def readFailed(self, fail):
     """The reader reported an error. Notify the remote end and cancel the transfer"""
     log.err(fail)
     self.transport.write(ERRORDatagram.from_code(ERR_NOT_DEFINED, b"Read failed").to_wire())
     self.cancel()
开发者ID:mont5piques,项目名称:python-tx-tftp,代码行数:5,代码来源:session.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python protocol.TFTP类代码示例发布时间:2022-05-27
下一篇:
Python datagram.split_opcode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap