[CalendarServer-changes] [12101] twext/trunk/twext/python

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:24:04 PDT 2014


Revision: 12101
          http://trac.calendarserver.org//changeset/12101
Author:   wsanchez at apple.com
Date:     2013-12-13 19:02:31 -0800 (Fri, 13 Dec 2013)
Log Message:
-----------
More cleanup

Modified Paths:
--------------
    twext/trunk/twext/python/clsprop.py
    twext/trunk/twext/python/filepath.py

Modified: twext/trunk/twext/python/clsprop.py
===================================================================
--- twext/trunk/twext/python/clsprop.py	2013-12-14 02:44:35 UTC (rev 12100)
+++ twext/trunk/twext/python/clsprop.py	2013-12-14 03:02:31 UTC (rev 12101)
@@ -18,6 +18,10 @@
 A small utility for defining static class properties.
 """
 
+__all__ = ["classproperty"]
+
+
+
 class classproperty(object):
     """
     Decorator for a method that wants to return a static class property.  The
@@ -38,11 +42,13 @@
     def __get__(self, instance, owner):
         if not self.cache:
             return self.thunk(owner)
+
         cc = self._classcache
+
         if owner in cc:
             cached = cc[owner]
         else:
             cached = self.thunk(owner)
             cc[owner] = cached
+
         return cached
-

Modified: twext/trunk/twext/python/filepath.py
===================================================================
--- twext/trunk/twext/python/filepath.py	2013-12-14 02:44:35 UTC (rev 12100)
+++ twext/trunk/twext/python/filepath.py	2013-12-14 03:02:31 UTC (rev 12101)
@@ -20,32 +20,29 @@
 calendar server.
 """
 
-from os import listdir as _listdir
+__all__ = ["CachingFilePath"]
 
-from os.path import (join as _joinpath,
-                     basename as _basename,
-                     exists as _exists,
-                     dirname as _dirname)
-
-from time import sleep as _sleep
+from os import listdir as listdir
+from os.path import join, basename, exists, dirname
+from time import sleep
 from types import FunctionType, MethodType
 from errno import EINVAL
+from stat import S_ISDIR
 
 from twisted.python.filepath import FilePath as _FilePath
 
-from stat import S_ISDIR
 
+
 class CachingFilePath(_FilePath, object):
     """
     A descendent of L{_FilePath} which implements a more aggressive caching
     policy.
     """
 
-    _listdir = _listdir         # integration points for tests
-    _sleep = _sleep
+    _listdir = listdir  # integration points for tests
+    _sleep = sleep
 
-    BACKOFF_MAX = 5.0           # Maximum time to wait between calls to
-                                # listdir()
+    BACKOFF_MAX = 5.0  # Maximum time to wait between calls to listdir()
 
     def __init__(self, path, alwaysCreate=False):
         super(CachingFilePath, self).__init__(path, alwaysCreate)
@@ -56,16 +53,22 @@
     @property
     def siblingExtensionSearch(self):
         """
-        Dynamically create a version of L{_FilePath.siblingExtensionSearch} that
-        uses a pluggable 'listdir' implementation.
+        Dynamically create a version of L{_FilePath.siblingExtensionSearch}
+        that uses a pluggable L{listdir} implementation.
         """
-        return MethodType(FunctionType(
+        return MethodType(
+            FunctionType(
                 _FilePath.siblingExtensionSearch.im_func.func_code,
-                {'listdir': self._retryListdir,
-                 'basename': _basename,
-                 'dirname': _dirname,
-                 'joinpath': _joinpath,
-                 'exists': _exists}), self, self.__class__)
+                {
+                    "listdir": self._retryListdir,
+                    "basename": basename,
+                    "dirname": dirname,
+                    "joinpath": join,
+                    "exists": exists
+                }
+            ),
+            self, self.__class__
+        )
 
 
     def changed(self):
@@ -84,6 +87,7 @@
         C{siblingExtensionSearch}.
         """
         delay = 0.1
+
         while True:
             try:
                 return self._listdir(pathname)
@@ -93,9 +97,10 @@
                     delay = min(self.BACKOFF_MAX, delay * 2.0)
                 else:
                     raise
-        raise RuntimeError("unreachable code.")
 
+        raise AssertionError("unreachable code.")
 
+
     def listdir(self):
         """
         List the directory which C{self.path} points to, compensating for
@@ -126,9 +131,11 @@
         """
         result = super(CachingFilePath, self).moveTo(destination, followLinks)
         self.changed()
-        # Work with vanilla FilePath destinations to pacify the tests. 
+
+        # Work with vanilla FilePath destinations to pacify the tests.
         if hasattr(destination, "changed"):
             destination.changed()
+
         return result
 
 
@@ -142,6 +149,6 @@
         finally:
             self.changed()
 
+
+
 CachingFilePath.clonePath = CachingFilePath
-
-__all__ = ["CachingFilePath"]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/59007c98/attachment.html>


More information about the calendarserver-changes mailing list