/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/ftp_server/pyftpdlib_based.py

  • Committer: Martin
  • Date: 2010-05-25 17:27:52 UTC
  • mfrom: (5254 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5257.
  • Revision ID: gzlist@googlemail.com-20100525172752-amm089xcikv968sw
Merge bzr.dev to unite with similar changes already made

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
from bzrlib import (
30
30
    osutils,
31
31
    trace,
32
 
    transport,
33
32
    )
 
33
from bzrlib.tests import test_server
34
34
 
35
35
 
36
36
class AnonymousWithWriteAccessAuthorizer(ftpserver.DummyAuthorizer):
50
50
 
51
51
    def listdir(self, path):
52
52
        """List the content of a directory."""
53
 
        # FIXME: need tests with unicode paths
54
53
        return [osutils.safe_utf8(s) for s in os.listdir(path)]
55
54
 
56
55
    def fs2ftp(self, fspath):
57
 
        p = ftpserver.AbstractedFS.fs2ftp(self, fspath)
58
 
        # FIXME: need tests with unicode paths
 
56
        p = ftpserver.AbstractedFS.fs2ftp(self, osutils.safe_unicode(fspath))
59
57
        return osutils.safe_utf8(p)
60
58
 
 
59
    def ftp2fs(self, ftppath):
 
60
        p = osutils.safe_unicode(ftppath)
 
61
        return ftpserver.AbstractedFS.ftp2fs(self, p)
61
62
 
62
63
class BzrConformingFTPHandler(ftpserver.FTPHandler):
63
64
 
84
85
        line = self.fs.fs2ftp(path)
85
86
        if self.fs.isfile(self.fs.realpath(path)):
86
87
            why = "Not a directory: %s" % line
87
 
            self.log('FAIL SIZE "%s". %s.' % (line, why))
 
88
            self.log('FAIL NLST "%s". %s.' % (line, why))
88
89
            self.respond("550 %s."  %why)
89
90
        else:
90
91
            ftpserver.FTPHandler.ftp_NLST(self, path)
132
133
        self.addr = self.socket.getsockname()
133
134
 
134
135
 
135
 
class FTPTestServer(transport.Server):
 
136
class FTPTestServer(test_server.TestServer):
136
137
    """Common code for FTP server facilities."""
137
138
 
138
139
    def __init__(self):
156
157
        """This is used by ftp_server to log connections, etc."""
157
158
        self.logs.append(message)
158
159
 
159
 
    def setUp(self, vfs_server=None):
160
 
        from bzrlib.transport.local import LocalURLServer
161
 
        if not (vfs_server is None or isinstance(vfs_server, LocalURLServer)):
 
160
    def start_server(self, vfs_server=None):
 
161
        if not (vfs_server is None or isinstance(vfs_server,
 
162
                                                 test_server.LocalURLServer)):
162
163
            raise AssertionError(
163
164
                "FTPServer currently assumes local transport, got %s"
164
165
                % vfs_server)
180
181
        self._port = self._ftp_server.socket.getsockname()[1]
181
182
        self._ftpd_starting = threading.Lock()
182
183
        self._ftpd_starting.acquire() # So it can be released by the server
183
 
        self._ftpd_thread = threading.Thread(
184
 
                target=self._run_server,)
 
184
        self._ftpd_thread = threading.Thread(target=self._run_server,)
185
185
        self._ftpd_thread.start()
186
186
        # Wait for the server thread to start (i.e release the lock)
187
187
        self._ftpd_starting.acquire()
188
188
        self._ftpd_starting.release()
189
189
 
190
 
    def tearDown(self):
191
 
        """See bzrlib.transport.Server.tearDown."""
 
190
    def stop_server(self):
 
191
        """See bzrlib.transport.Server.stop_server."""
192
192
        # Tell the server to stop, but also close the server socket for tests
193
193
        # that start the server but never initiate a connection. Closing the
194
194
        # socket should be done first though, to avoid further connections.
197
197
        self._ftpd_thread.join()
198
198
 
199
199
    def _run_server(self):
200
 
        """Run the server until tearDown is called, shut it down properly then.
 
200
        """Run the server until stop_server is called, shut it down properly then.
201
201
        """
202
202
        self._ftpd_running = True
203
203
        self._ftpd_starting.release()
204
204
        while self._ftpd_running:
205
 
            self._ftp_server.serve_forever(timeout=0.1, count=1)
 
205
            try:
 
206
                self._ftp_server.serve_forever(timeout=0.1, count=1)
 
207
            except select.error, e:
 
208
                if e.args[0] != errno.EBADF:
 
209
                    raise
206
210
        self._ftp_server.close_all(ignore_all=True)
207
211
 
208
212
    def add_user(self, user, password):