Ejemplo n.º 1
0
 def test_parse_address(self):
     self.assertEqual(
         ('127.0.0.1', 34805),
         parse_address('227 Now Entering Passive Mode (127,0,0,1,135,245)'))
     self.assertEqual(
         ('127.0.0.1', 254),
         parse_address('227 Passive Mode! (127, 000, 000, 001, 000, 254)'))
Ejemplo n.º 2
0
 def test_parse_address(self):
     self.assertEqual(
         ('127.0.0.1', 34805),
         parse_address('227 Now Entering Passive Mode (127,0,0,1,135,245)')
     )
     self.assertEqual(
         ('127.0.0.1', 254),
         parse_address('227 Passive Mode! (127, 000, 000, 001, 000, 254)')
     )
Ejemplo n.º 3
0
    def test_control_stream(self):
        def log_cb(data_type, data):
            _logger.debug(__('{0}={1}', data_type, data))

        connection = Connection(('127.0.0.1', self.server_port()))
        yield From(connection.connect())

        control_stream = ControlStream(connection)
        control_stream.data_observer.add(log_cb)

        reply = yield From(control_stream.read_reply())
        self.assertEqual(220, reply.code)

        yield From(control_stream.write_command(Command('USER', 'smaug')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(331, reply.code)

        yield From(control_stream.write_command(Command('PASS', 'gold1')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(230, reply.code)

        yield From(control_stream.write_command(Command('PASV')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(227, reply.code)
        address = parse_address(reply.text)

        data_connection = Connection(address)
        yield From(data_connection.connect())

        data_stream = DataStream(data_connection)

        yield From(
            control_stream.write_command(Command('RETR',
                                                 'example (copy).txt')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(150, reply.code)

        my_file = io.BytesIO()

        yield From(data_stream.read_file(my_file))

        reply = yield From(control_stream.read_reply())
        self.assertEqual(226, reply.code)

        self.assertEqual('The real treasure is in Smaug’s heart 💗.\n',
                         my_file.getvalue().decode('utf-8'))
Ejemplo n.º 4
0
    def test_control_stream(self):
        def log_cb(data_type, data):
            _logger.debug(__('{0}={1}', data_type, data))

        connection = Connection(('127.0.0.1', self.server_port()))
        yield From(connection.connect())

        control_stream = ControlStream(connection)
        control_stream.data_observer.add(log_cb)

        reply = yield From(control_stream.read_reply())
        self.assertEqual(220, reply.code)

        yield From(control_stream.write_command(Command('USER', 'smaug')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(331, reply.code)

        yield From(control_stream.write_command(Command('PASS', 'gold1')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(230, reply.code)

        yield From(control_stream.write_command(Command('PASV')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(227, reply.code)
        address = parse_address(reply.text)

        data_connection = Connection(address)
        yield From(data_connection.connect())

        data_stream = DataStream(data_connection)

        yield From(control_stream.write_command(Command('RETR', 'example (copy).txt')))
        reply = yield From(control_stream.read_reply())
        self.assertEqual(150, reply.code)

        my_file = io.BytesIO()

        yield From(data_stream.read_file(my_file))

        reply = yield From(control_stream.read_reply())
        self.assertEqual(226, reply.code)

        self.assertEqual(
            'The real treasure is in Smaug’s heart 💗.\n',
            my_file.getvalue().decode('utf-8')
            )