Commits

Alex...@winwork  committed cbd44bb

python 3.2 compatible
some tests fixes

  • Participants
  • Parent commits e74575b

Comments (0)

Files changed (5)

File dogpile/cache/api.py

 import operator
-from . import util
+from dogpile.compat import py3k
+
 
 class NoValue(object):
     """Describe a missing cache value.
     def payload(self):
         return self
 
-    if util.py3k:
+    if py3k:
         def __bool__(self):
             return False
     else:

File dogpile/cache/util.py

 import sys
 import re
 import collections
+from dogpile.compat import string_types, text_type, pickle
+
 
 try:
     import threading
 except ImportError:
     import dummy_threading as threading
 
-py3k = sys.version_info >= (3, 0)
-jython = sys.platform.startswith('java')
-
-if py3k or jython:
-    import pickle
-else:
-    import cPickle as pickle
-
-if py3k:
-    tounicode = str
-else:
-    tounicode = unicode
-
 
 def coerce_string_conf(d):
     result = {}
     for k, v in d.items():
-        if not isinstance(v, basestring):
+        if not isinstance(v, string_types):
             result[k] = v
             continue
 
                     "function does not accept keyword arguments.")
         if has_self:
             args = args[1:]
-        return namespace + "|" + " ".join(map(tounicode, args))
+        return namespace + "|" + " ".join(map(text_type, args))
     return generate_key
 
 def sha1_mangle_key(key):

File dogpile/compat.py

+import sys
+
+
+py3k = sys.version_info >= (3, 0)
+jython = sys.platform.startswith('java')
+
+
+if py3k: # pragma: no cover
+    string_types = str,
+    text_type = str
+
+    import configparser
+    import io
+else:
+    string_types = basestring,
+    text_type = unicode
+
+    import ConfigParser as configparser
+    import StringIO as io
+
+if py3k or jython:
+    import pickle
+else:
+    import cPickle as pickle

File tests/cache/__init__.py

 import re
 
+
 def eq_(a, b, msg=None):
     """Assert a == b, with repr messaging on failure."""
     assert a == b, msg or "%r != %r" % (a, b)
     except except_cls as e:
         assert re.search(msg, str(e)), "%r !~ %s" % (msg, e)
 
-
-from dogpile.cache.util import py3k
-
-if py3k:
-    import configparser
-    import io
-else:
-    import ConfigParser as configparser
-    import StringIO as io
+from dogpile.compat import configparser, io

File tests/cache/test_region.py

+import pprint
 from unittest import TestCase
 from dogpile.cache.api import CacheBackend, CachedValue, NO_VALUE
 from dogpile.cache import make_region, register_backend, CacheRegion, util
         def creator():
             return "some value %d" % next(counter)
         eq_(reg.get_or_create("some key", creator), "some value 1")
-        time.sleep(1)
+        time.sleep(2)
         eq_(reg.get("some key"), "some value 1")
         eq_(reg.get_or_create("some key", creator), "some value 2")
         eq_(reg.get("some key"), "some value 2")
             return "some value %d" % next(counter)
         eq_(reg.get_or_create("some key", creator, expiration_time=1), 
                     "some value 1")
-        time.sleep(1)
+        time.sleep(2)
         eq_(reg.get("some key"), "some value 1")
         eq_(reg.get_or_create("some key", creator, expiration_time=1), 
                     "some value 2")