[tor-commits] [bridgedb/master] Revise bridgedb.Time.Schedule to use a zope.interface.

isis at torproject.org isis at torproject.org
Fri May 16 18:52:53 UTC 2014


commit fb7492d021e6037e8ef7452ac248bed84314d8f9
Author: Isis Lovecruft <isis at torproject.org>
Date:   Mon May 12 21:23:29 2014 +0000

    Revise bridgedb.Time.Schedule to use a zope.interface.
    
     * REMOVE old-style class bridgedb.Time.Schedule.
     * ADD zope.interface.Interface specification, bridgedb.Time.ISchedule.
     * ADD bridgedb.Time.ScheduleBase class that implements the ISchedule
       interface and does what the original bridgedb.Time.Schedule class was
       supposed to do.
---
 lib/bridgedb/Time.py |   40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/lib/bridgedb/Time.py b/lib/bridgedb/Time.py
index 2b7b02b..6062b98 100644
--- a/lib/bridgedb/Time.py
+++ b/lib/bridgedb/Time.py
@@ -12,17 +12,41 @@
 import calendar
 import time
 
+from zope import interface
+from zope.interface import implements
+
 KNOWN_INTERVALS = [ "hour", "day", "week", "month" ]
 
-class Schedule:
+
+class ISchedule(interface.Interface):
+    """A ``Interface`` specification for a Schedule."""
+
+    def intervalStart(when):
+        """Set the start time of the current interval to **when**."""
+
+    def getInterval(when=None):
+        """Get the interval which includes an arbitrary **when**."""
+
+    def nextIntervalStarts():
+        """Get the start time for the next interval."""
+
+
+class ScheduleBase(object):
+    """Base class for all ``Schedule`` classes."""
+
+    implements(ISchedule)
+
     def intervalStart(self, when):
-        raise NotImplementedError
-    def getInterval(self, when):
-        raise NotImplementedError
-    def nextIntervalStarts(self, when):
-        raise NotImplementedError
+        pass
+
+    def getInterval(self, when=None):
+        pass
+
+    def nextIntervalStarts(self):
+        pass
+
 
-class IntervalSchedule(Schedule):
+class IntervalSchedule(ScheduleBase):
     """An IntervalSchedule splits time into somewhat natural periods,
        based on hours, days, weeks, or months.
     """
@@ -118,7 +142,7 @@ class IntervalSchedule(Schedule):
         elif self.itype == 'hour':
             return self.intervalStart(when) + 3600 * self.count
 
-class NoSchedule(Schedule):
+class NoSchedule(ScheduleBase):
     """A stub-implementation of Schedule that has only one period for
        all time."""
     def __init__(self):





More information about the tor-commits mailing list