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


Python ERRORDatagram.from_code方法代码示例

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


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

示例1: test_error

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [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")
开发者ID:karlzheng,项目名称:bashrc,代码行数:33,代码来源:test_wire_protocol.py

示例2: datagramReceived

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
    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,代码行数:19,代码来源:protocol.py

示例3: datagramReceived

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:10,代码来源:bootstrap.py

示例4: tftp_DATA

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
    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,代码行数:20,代码来源:session.py

示例5: _startSession

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:11,代码来源:protocol.py

示例6: _startSession

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:46,代码来源:protocol.py

示例7: datagramReceived

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
    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,代码行数:13,代码来源:protocol.py

示例8: datagramReceived

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
    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,代码行数:15,代码来源:protocol.py

示例9: tftp_ACK

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
    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,代码行数:20,代码来源:session.py

示例10: _startSession

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:22,代码来源:protocol.py

示例11: readFailed

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:7,代码来源:session.py

示例12: blockWriteFailure

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:7,代码来源:session.py

示例13: test_ERROR

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:8,代码来源:test_sessions.py

示例14: test_ERROR

# 需要导入模块: from tftp.datagram import ERRORDatagram [as 别名]
# 或者: from tftp.datagram.ERRORDatagram import from_code [as 别名]
 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,代码行数:7,代码来源:test_sessions.py


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