コード例 #1
0
ファイル: request_test.py プロジェクト: Super-Rad/wpull
 def test_reply(self):
     reply = Reply(213, 'Hello world!\nFerret transfer protocol')
     self.assertEqual(
         b'213-Hello world!\r\n213 Ferret transfer protocol\r\n',
         reply.to_bytes()
     )
     self.assertEqual(213, reply.to_dict()['code'])
     self.assertEqual(
         'Hello world!\nFerret transfer protocol',
         reply.to_dict()['text']
     )
     self.assertEqual((2, 1, 3), reply.code_tuple())
コード例 #2
0
ファイル: request_test.py プロジェクト: fakegit/ludios_wpull
 def test_reply(self):
     reply = Reply(213, 'Hello world!\nFerret transfer protocol')
     self.assertEqual(
         b'213-Hello world!\r\n213 Ferret transfer protocol\r\n',
         reply.to_bytes())
     self.assertEqual(213, reply.to_dict()['code'])
     self.assertEqual('Hello world!\nFerret transfer protocol',
                      reply.to_dict()['text'])
     self.assertEqual((2, 1, 3), reply.code_tuple())
コード例 #3
0
ファイル: stream.py プロジェクト: fakegit/ludios_wpull
    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
コード例 #4
0
ファイル: request_test.py プロジェクト: fakegit/ludios_wpull
    def test_to_dict(self):
        request = Request('ftp://foofle.com')
        request_dict = request.to_dict()

        self.assertEqual('ftp://foofle.com', request_dict['url'])
        self.assertEqual('ftp', request_dict['protocol'])

        response = Response()
        response.request = request
        response.reply = Reply(code=200, text='Success')
        response_dict = response.to_dict()

        self.assertEqual('ftp://foofle.com', response_dict['request']['url'])
        self.assertEqual('ftp', response_dict['protocol'])
        self.assertEqual(200, response_dict['reply']['code'])
        self.assertEqual(200, response_dict['response_code'])
        self.assertEqual('Success', response_dict['reply']['text'])
        self.assertEqual('Success', response_dict['response_message'])
コード例 #5
0
ファイル: request_test.py プロジェクト: Super-Rad/wpull
    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')
コード例 #6
0
ファイル: request_test.py プロジェクト: fakegit/ludios_wpull
    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')