Commits

Mike Bayer  committed 72ceb05

Added py2.6 compatibility for unsupported ``total_seconds()`` call
in region.py

  • Participants
  • Parent commits ceaad7c

Comments (0)

Files changed (3)

File docs/build/changelog.rst

     :version: 0.5.2
 
     .. change::
+        :tags: bug
+
+      Added py2.6 compatibility for unsupported ``total_seconds()`` call
+      in region.py
+
+    .. change::
         :tags: feature
         :tickets: 44
 

File dogpile/cache/compat.py

 py2k = sys.version_info < (3, 0)
 py3k = sys.version_info >= (3, 0)
 py32 = sys.version_info >= (3, 2)
+py27 = sys.version_info >= (2, 7)
 jython = sys.platform.startswith('java')
 
-
 try:
     import threading
 except ImportError:
 if py3k or jython:
     import pickle
 else:
-    import cPickle as pickle
+    import cPickle as pickle
+
+
+def timedelta_total_seconds(td):
+    if py27:
+        return td.total_seconds()
+    else:
+        return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 1e6) / 1e6
+
+

File dogpile/cache/region.py

         if not expiration_time or isinstance(expiration_time, Number):
             self.expiration_time = expiration_time
         elif isinstance(expiration_time, datetime.timedelta):
-            self.expiration_time = int(expiration_time.total_seconds())
+            self.expiration_time = int(compat.timedelta_total_seconds(expiration_time))
         else:
             raise exception.ValidationError(
                 'expiration_time is not a number or timedelta.')