~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-07 13:49:12 UTC
  • mfrom: (5947.1.3 781140-ftp-test-coverage)
  • Revision ID: pqm@pqm.ubuntu.com-20110607134912-0icu0bcbn5ss4mod
(vila) Support pyftplib-0.6.0 as an ftp test server (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.tests import test_server
35
35
 
36
36
 
 
37
# Convert the pyftplib string version into a tuple to avoid traps in string
 
38
# comparison.
 
39
pyftplib_version = tuple(map(int, ftpserver.__ver__.split('.')))
 
40
 
 
41
 
37
42
class AnonymousWithWriteAccessAuthorizer(ftpserver.DummyAuthorizer):
38
43
 
39
44
    def _check_permissions(self, username, perm):
113
118
            self.log('OK SITE CHMOD 0%03o "%s".' % (mode, ftp_path))
114
119
            self.respond('200 SITE CHMOD succesful.')
115
120
 
116
 
 
117
 
# pyftpdlib says to define SITE commands by declaring ftp_SITE_<CMD> methods,
118
 
# but fails to recognize them.
119
 
ftpserver.proto_cmds['SITE CHMOD'] = ftpserver._CommandProperty(
120
 
    perm='w', # Best fit choice even if not exactly right (can be d, f or m too)
121
 
    auth_needed=True, arg_needed=True, check_path=False,
122
 
    help='Syntax: SITE CHMOD <SP>  octal_mode_bits file-name (chmod file)',
123
 
    )
124
 
# An empty password is valid, hence the arg is neither mandatory not forbidden
125
 
ftpserver.proto_cmds['PASS'].arg_needed = None
 
121
    if pyftplib_version >= (0, 6, 0):
 
122
        def log_cmd(self, cmd, arg, respcode, respstr):
 
123
            # base class version choke on unicode, the alternative is to just
 
124
            # provide an empty implementation and relies on the client to do
 
125
            # the logging for debugging purposes. Not worth the trouble so far
 
126
            # -- vila 20110607
 
127
            if cmd in ("DELE", "RMD", "RNFR", "RNTO", "MKD"):
 
128
                line = '"%s" %s' % (' '.join([cmd, unicode(arg)]).strip(),
 
129
                                    respcode)
 
130
                self.log(line)
 
131
 
 
132
 
 
133
if pyftplib_version < (0, 6,0):
 
134
    # pyftpdlib says to define SITE commands by declaring ftp_SITE_<CMD>
 
135
    # methods, but fails to recognize them.
 
136
    ftpserver.proto_cmds['SITE CHMOD'] = ftpserver._CommandProperty(
 
137
        # Best fit choice even if not exactly right (can be d, f or m too)
 
138
        perm='w',
 
139
        auth_needed=True, arg_needed=True, check_path=False,
 
140
        help='Syntax: SITE CHMOD <SP>  octal_mode_bits file-name (chmod file)',
 
141
        )
 
142
    # An empty password is valid, hence the arg is neither mandatory not
 
143
    # forbidden
 
144
    ftpserver.proto_cmds['PASS'].arg_needed = None
 
145
else:
 
146
    # Same rationale as above (the password should be optional), but the hole
 
147
    # in pyftplib-0.6.0 is narrower
 
148
    ftpserver.proto_cmds['PASS']['arg'] = None
126
149
 
127
150
 
128
151
class ftp_server(ftpserver.FTPServer):