[Zope3-checkins] SVN: Zope3/trunk/ Merge bug fixes to the FTP server from the mkerrin-remove_trial_tests

Michael Kerrin michael.kerrin at openapp.biz
Tue Apr 4 06:02:51 EDT 2006


Log message for revision 66373:
  Merge bug fixes to the FTP server from the mkerrin-remove_trial_tests
  branch. This patch also includes code to integrate the Twisted trial tests
  ,needed to test the ftp server, with the the Zope testrunner.
  
  
  ------------------------------------------------------------------------
  r66355 | mkerrin | 2006-04-03 18:49:47 +0100 (Mon, 03 Apr 2006) | 3 lines
  
  Finally got all the FTP trial tests to run within the
  Zope testrunner.
  
  ------------------------------------------------------------------------
  r41780 | mkerrin | 2006-02-24 20:55:54 +0000 (Fri, 24 Feb 2006) | 3 lines
  
  fix timezone related bug in handling of the last
  modified time
  
  ------------------------------------------------------------------------
  r41769 | mkerrin | 2006-02-24 12:52:30 +0000 (Fri, 24 Feb 2006) | 3 lines
  
  Fixed two bugs in FTP reported by Roger which pushed
  me to finishing this work.
  
  ------------------------------------------------------------------------
  r41729 | mkerrin | 2006-02-21 14:46:49 +0000 (Tue, 21 Feb 2006) | 3 lines
  
  Integrate the trial ftp tests with the Zope testrunner and
  remove the trial tests from Zope
  
  ------------------------------------------------------------------------
  r41495 | mkerrin | 2006-01-30 14:54:33 +0000 (Mon, 30 Jan 2006) | 3 lines
  
  create branch to integrate some trial tests back into the zope testing
  framework so has they get run in the buildbot.
  
  ------------------------------------------------------------------------
  
  

Changed:
  U   Zope3/trunk/src/zope/app/twisted/ftp/ftp.py
  D   Zope3/trunk/src/zope/app/twisted/ftp/test/
  U   Zope3/trunk/src/zope/app/twisted/ftp/tests/demofs.py
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py
  A   Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py
  U   Zope3/trunk/test.py

-=-
Modified: Zope3/trunk/src/zope/app/twisted/ftp/ftp.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/ftp.py	2006-04-04 08:46:11 UTC (rev 66372)
+++ Zope3/trunk/src/zope/app/twisted/ftp/ftp.py	2006-04-04 10:02:50 UTC (rev 66373)
@@ -15,6 +15,7 @@
 """
 __docformat__="restructuredtext"
 
+import calendar
 from cStringIO import StringIO
 from types import StringTypes
 
@@ -22,6 +23,8 @@
 
 from zope.publisher.interfaces import NotFound
 from zope.security.interfaces import Unauthorized
+from zope.exceptions import DuplicationError
+from zope.app.copypastemove import ItemNotFoundError
 
 from twisted.internet import threads, defer
 from twisted.protocols import ftp
@@ -107,33 +110,41 @@
     def _path(self, path):
         return '/' + '/'.join(path)
 
+    def _perm_failed(self, failure):
+        raise ftp.PermissionDeniedError(self._path(path))
+
     def makeDirectory(self, path):
-        def failed(failure):
-            raise ftp.PermissionDeniedError(self._path(path))
-        d = threads.deferToThread(self.fs_access.mkdir, self._path(path))
-        d.addErrback(failed)
+        p = self._path(path)
 
+        d = threads.deferToThread(self.fs_access.mkdir, p)
+        d.addErrback(self._perm_failed, p)
+
         return d
 
     def removeDirectory(self, path):
-        def failed(failure):
-            raise ftp.PermissionDeniedError(self._path(path))
-        d = threads.deferToThread(self.fs_access.rmdir, self._path(path))
-        d.addErrback(failed)
+        p = self._path(path)
 
+        d = threads.deferToThread(self.fs_access.rmdir, p)
+        d.addErrback(self._perm_failed, p)
+
         return d
 
     def removeFile(self, path):
-        def failed(failure):
-            raise ftp.PermissionDeniedError(self._path(path))
-        d = threads.deferToThread(self.fs_access.remove, self._path(path))
-        d.addErrback(failed)
+        p = self._path(path)
 
+        d = threads.deferToThread(self.fs_access.remove, p)
+        d.addErrback(self._perm_failed, p)
+
         return d
 
     def rename(self, fromPath, toPath):
         def failed(failure):
-            raise ftp.PermissionDeniedError(self._path(path))
+            if failure.type is DuplicationError:
+                raise ftp.PermissionDeniedError(self._path(toPath))
+            elif failure.type is ItemNotFoundError:
+                raise ftp.FileNotFoundError(self._path(fromPath))
+            raise ftp.PermissionDeniedError(self._path(fromPath))
+
         d = threads.deferToThread(self.fs_access.rename,
                                   self._path(fromPath),
                                   self._path(toPath))
@@ -170,13 +181,21 @@
                 ent.append(val)
         return result['name'].encode('utf-8'), ent
 
-    def _stat(self, path, keys):
-        result = self._gotlisting(self.fs_access.lsinfo(path), keys)
-        return result[1]
-
     def stat(self, path, keys=()):
-        return threads.deferToThread(self._stat, self._path(path), keys)
+        p = self._path(path)
 
+        d = threads.deferToThread(self.fs_access.lsinfo, p)
+        d.addCallback(self._gotlisting, keys)
+        d.addCallback(lambda result: result[1])
+        d.addErrback(self._perm_failed, p)
+        
+        return d
+
+    def _list(self, path):
+        if self.fs_access.type(path) == 'd':
+            return self.fs_access.ls(path)
+        return [self.fs_access.lsinfo(path)]
+
     def list(self, path, keys=()):
         def gotresults(results, keys):
             ret = []
@@ -189,7 +208,7 @@
                 raise ftp.FileNotFoundError(self._path(path))
             raise ftp.PermissionDeniedError(self._path(path))
 
-        d = threads.deferToThread(self.fs_access.ls, self._path(path))
+        d = threads.deferToThread(self._list, self._path(path))
         d.addCallback(gotresults, keys)
         d.addErrback(goterror)
 
@@ -213,7 +232,7 @@
     def _list_modified(self, value):
         mtime = value.get('mtime', None)
         if mtime:
-            return int(mtime.strftime('%s'))
+            return calendar.timegm(mtime.utctimetuple())
         return 0
 
     def _list_permissions(self, value):
@@ -242,24 +261,33 @@
             ret |= 0040000
         return ret
 
-    def _checkFileReadAccess(self, fs_access, p):
-        # run all these methods within the one thread.
-        readable = fs_access.readable(p)
+    def _checkFileReadAccess(self, fs_access, path):
+        # run all these methods within the application thread
+        readable = fs_access.readable(path)
         if not readable:
-            raise ftp.PermissionDeniedError(p)
+            raise ftp.PermissionDeniedError(path)
 
-        filetype = fs_access.type(p)
+        filetype = fs_access.type(path)
         if filetype == 'd':
-            raise ftp.FileNotFoundError(p)
+            raise ftp.FileNotFoundError(path)
 
-        return ReadFileObj(fs_access, p)
+        return ReadFileObj(fs_access, path)
 
     def openForReading(self, path):
         p = self._path(path)
 
-        return threads.deferToThread(self._checkFileReadAccess,
-                                     self.fs_access, p)
+        def failed(failure):
+            if isinstance(failure.type, ftp.FTPCmdError):
+                raise failure
+            elif isinstance(failure.type, NotFound):
+                raise ftp.FileNotFoundError(p)
+            raise ftp.PermissionDeniedError(p)
 
+        d = threads.deferToThread(self._checkFileReadAccess, self.fs_access, p)
+        d.addErrback(failed)
+
+        return d
+
     def openForWriting(self, path):
         p = self._path(path)
 
@@ -268,11 +296,8 @@
                 return WriteFileObj(self.fs_access, p)
             raise ftp.PermissionDeniedError(p)
 
-        def failed(failure):
-            raise ftp.PermissionDeniedError(p)
-
         d = threads.deferToThread(self.fs_access.writable, p)
         d.addCallback(succeed)
-        d.addErrback(failed)
+        d.addErrback(self._perm_failed, p)
 
         return d

Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/demofs.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/demofs.py	2006-04-04 08:46:11 UTC (rev 66372)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/demofs.py	2006-04-04 10:02:50 UTC (rev 66373)
@@ -17,6 +17,9 @@
 from zope.security.interfaces import Unauthorized
 from zope.publisher.interfaces import NotFound
 
+from zope.exceptions import DuplicationError
+from zope.app.copypastemove import ItemNotFoundError
+
 from zope.app.twisted.interfaces import IFileSystem
 from zope.interface import implements
 
@@ -155,7 +158,14 @@
 
     def ls(self, path, filter=None):
         "See zope.server.interfaces.ftp.IFileSystem"
-        f = self.getdir(path)
+        if self.type(path) == 'd':
+            f = self.getdir(path)
+        else:
+            path = path.split('/')
+            name = path.pop()
+            f = self.getdir('/'.join(path))
+            return [self._lsinfo(name, f.files[name])]
+
         if filter is None:
             return [self._lsinfo(name, f.files[name])
                     for name in f
@@ -236,9 +246,11 @@
         newdir = self.getwdir(newpath)
 
         if oldname not in olddir.files:
-            raise OSError("Not exists:", oldname)
+            ## raise exception that we are likely to get in Zope3
+            raise ItemNotFoundError(olddir, oldname)
         if newname in newdir.files:
-            raise OSError("Already exists:", newname)
+            ## raise exception that we are likely to get in Zope3
+            raise DuplicationError("%s is already in use" % newname)
 
         newdir.files[newname] = olddir.files[oldname]
         del olddir.files[oldname]

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/test_zope_ftp.py)

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/test_zopetrial.py)

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/trial.txt)

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/trialtest.py)

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/trialtestfs.py)

Copied: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py (from rev 66355, Zope3/branches/mkerrin-remove_trial_tests/src/zope/app/twisted/ftp/tests/trialtestft.py)

Modified: Zope3/trunk/test.py
===================================================================
--- Zope3/trunk/test.py	2006-04-04 08:46:11 UTC (rev 66372)
+++ Zope3/trunk/test.py	2006-04-04 10:02:50 UTC (rev 66373)
@@ -57,6 +57,9 @@
 # Get rid of twisted.conch.ssh warning
 warnings.filterwarnings(
     'ignore', 'PyCrypto', RuntimeWarning, 'twisted[.]conch[.]ssh')
+warnings.filterwarnings(
+    'ignore', '', DeprecationWarning,
+    '(zope[.]app[.]twisted[.]ftp|twisted[.]test[.]test_ftp)')
 
 result = testrunner.run(defaults)
 



More information about the Zope3-Checkins mailing list