Rev 5948: Support pyftplib-0.6.0 as an ftp test server in file:///home/vila/src/bzr/bugs/781140-ftp-test-coverage/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Jun 7 07:00:23 UTC 2011


At file:///home/vila/src/bzr/bugs/781140-ftp-test-coverage/

------------------------------------------------------------
revno: 5948
revision-id: v.ladeuil+lp at free.fr-20110607070023-h2nr27r9ykckd3se
parent: pqm at pqm.ubuntu.com-20110601091513-vo5m9202wr24rbsl
fixes bug(s): https://launchpad.net/bugs/781140
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 781140-ftp-test-coverage
timestamp: Tue 2011-06-07 09:00:23 +0200
message:
  Support pyftplib-0.6.0 as an ftp test server
-------------- next part --------------
=== modified file 'bzrlib/tests/ftp_server/__init__.py'
--- a/bzrlib/tests/ftp_server/__init__.py	2011-05-11 11:35:28 +0000
+++ b/bzrlib/tests/ftp_server/__init__.py	2011-06-07 07:00:23 +0000
@@ -17,10 +17,20 @@
 Facilities to use ftp test servers.
 """
 
+import sys
+
 from bzrlib import tests
 
 
 try:
+    from bzrlib.tests.ftp_server import medusa_based
+    # medusa is bogus under python2.6
+    medusa_available = sys.version_info < (2, 6)
+except ImportError:
+    medusa_available = False
+
+
+try:
     from bzrlib.tests.ftp_server import pyftpdlib_based
     pyftpdlib_available = True
 except ImportError:
@@ -38,7 +48,7 @@
     """
 
     def _probe(self):
-        return pyftpdlib_available
+        return medusa_available or pyftpdlib_available
 
     def feature_name(self):
         return 'FTPServer'
@@ -69,7 +79,9 @@
         raise tests.UnavailableFeature(FTPServerFeature)
 
 
-if pyftpdlib_available:
+if medusa_available:
+    FTPTestServer = medusa_based.FTPTestServer
+elif pyftpdlib_available:
     FTPTestServer = pyftpdlib_based.FTPTestServer
 else:
     FTPTestServer = UnavailableFTPTestServer

=== modified file 'bzrlib/tests/ftp_server/pyftpdlib_based.py'
--- a/bzrlib/tests/ftp_server/pyftpdlib_based.py	2010-06-30 15:19:36 +0000
+++ b/bzrlib/tests/ftp_server/pyftpdlib_based.py	2011-06-07 07:00:23 +0000
@@ -34,6 +34,11 @@
 from bzrlib.tests import test_server
 
 
+# Convert the pyftplib string version into a tuple to avoid traps in string
+# comparison.
+pyftplib_version = tuple(map(int, ftpserver.__ver__.split('.')))
+
+
 class AnonymousWithWriteAccessAuthorizer(ftpserver.DummyAuthorizer):
 
     def _check_permissions(self, username, perm):
@@ -113,16 +118,34 @@
             self.log('OK SITE CHMOD 0%03o "%s".' % (mode, ftp_path))
             self.respond('200 SITE CHMOD succesful.')
 
-
-# pyftpdlib says to define SITE commands by declaring ftp_SITE_<CMD> methods,
-# but fails to recognize them.
-ftpserver.proto_cmds['SITE CHMOD'] = ftpserver._CommandProperty(
-    perm='w', # Best fit choice even if not exactly right (can be d, f or m too)
-    auth_needed=True, arg_needed=True, check_path=False,
-    help='Syntax: SITE CHMOD <SP>  octal_mode_bits file-name (chmod file)',
-    )
-# An empty password is valid, hence the arg is neither mandatory not forbidden
-ftpserver.proto_cmds['PASS'].arg_needed = None
+    if pyftplib_version >= (0, 6, 0):
+        def log_cmd(self, cmd, arg, respcode, respstr):
+            # base class version choke on unicode, the alternative is to just
+            # provide an empty implementation and relies on the client to do
+            # the logging for debugging purposes. Not worth the trouble so far
+            # -- vila 20110607
+            if cmd in ("DELE", "RMD", "RNFR", "RNTO", "MKD"):
+                line = '"%s" %s' % (' '.join([cmd, unicode(arg)]).strip(),
+                                    respcode)
+                self.log(line)
+
+
+if pyftplib_version < (0, 6,0):
+    # pyftpdlib says to define SITE commands by declaring ftp_SITE_<CMD>
+    # methods, but fails to recognize them.
+    ftpserver.proto_cmds['SITE CHMOD'] = ftpserver._CommandProperty(
+        # Best fit choice even if not exactly right (can be d, f or m too)
+        perm='w',
+        auth_needed=True, arg_needed=True, check_path=False,
+        help='Syntax: SITE CHMOD <SP>  octal_mode_bits file-name (chmod file)',
+        )
+    # An empty password is valid, hence the arg is neither mandatory not
+    # forbidden
+    ftpserver.proto_cmds['PASS'].arg_needed = None
+else:
+    # Same rationale as above (the password should be optional), but the hole
+    # in pyftplib-0.6.0 is narrower
+    ftpserver.proto_cmds['PASS']['arg'] = None
 
 
 class ftp_server(ftpserver.FTPServer):

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-06-01 09:15:13 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-06-07 07:00:23 +0000
@@ -111,6 +111,10 @@
 * Multiple ``selftest --exclude`` options are now combined instead of
   overriding each other. (Vincent Ladeuil, #746991)
 
+* Restore some ``FTPTransport`` test coverage by allowing ``pyftpdlib
+  0.6.0`` to be used. Also restore ``medusa`` support while leaving it
+  disabled to make it easier to use if/when we can in the future.
+  (Vincent Ladeuil, #781140)
 
 bzr 2.4b3
 #########



More information about the bazaar-commits mailing list