當前位置: 首頁>>代碼示例>>Python>>正文


Python datagram.ERRORDatagram類代碼示例

本文整理匯總了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;未經允許,請勿轉載。