예제 #1
0
    def read_reply(self) -> Reply:
        '''Read a reply from the stream.

        Returns:
            .ftp.request.Reply: The reply

        Coroutine.
        '''
        _logger.debug('Read reply')
        reply = Reply()

        while True:
            line = yield from self._connection.readline()

            if line[-1:] != b'\n':
                raise NetworkError('Connection closed.')

            self._data_event_dispatcher.notify_read(line)
            reply.parse(line)

            if reply.code is not None:
                break

        return reply
예제 #2
0
    def test_parse_reply(self):
        reply = Reply()
        reply.parse(b'200 Hello\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello', reply.text)

        reply = Reply()
        reply.parse(b'200-Hello\r\n')
        reply.parse(b'200 World!\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello\r\nWorld!', reply.text)

        reply = Reply()
        reply.parse(b'200-Hello\r\n')
        reply.parse(b'F\r\n')
        reply.parse(b' T\r\n')
        reply.parse(b'200-P\r\n')
        reply.parse(b'200 World!\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello\r\nF\r\nT\r\nP\r\nWorld!', reply.text)

        self.assertRaises(AssertionError, reply.parse, b'200 Hello again')
예제 #3
0
    def test_parse_reply(self):
        reply = Reply()
        reply.parse(b'200 Hello\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello', reply.text)

        reply = Reply()
        reply.parse(b'200-Hello\r\n')
        reply.parse(b'200 World!\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello\r\nWorld!', reply.text)

        reply = Reply()
        reply.parse(b'200-Hello\r\n')
        reply.parse(b'F\r\n')
        reply.parse(b' T\r\n')
        reply.parse(b'200-P\r\n')
        reply.parse(b'200 World!\r\n')

        self.assertEqual(200, reply.code)
        self.assertEqual('Hello\r\nF\r\nT\r\nP\r\nWorld!', reply.text)

        self.assertRaises(AssertionError, reply.parse, b'200 Hello again')