Mike Bayer avatar Mike Bayer committed 284ffd5

- compat.py needs to be in dogpile.cache - we're a namespace package !
- don't import compat's into util if we're going to have compat, keep it clean
- fix imports of new compat module

Comments (0)

Files changed (9)

dogpile/cache/api.py

 import operator
-from dogpile.compat import py3k
+from .compat import py3k
 
 
 class NoValue(object):

dogpile/cache/backends/file.py

 
 from dogpile.cache.api import CacheBackend, NO_VALUE
 from contextlib import contextmanager
+from dogpile.cache import compat
 from dogpile.cache import util
 import os
 import fcntl
                                 util.KeyReentrantMutex.factory)
 
         # TODO: make this configurable
-        if util.py3k:
+        if compat.py3k:
             import dbm
         else:
             import anydbm as dbm
         with self._dbm_file(False) as dbm:
             value = dbm.get(key, NO_VALUE)
             if value is not NO_VALUE:
-                value = util.pickle.loads(value)
+                value = compat.pickle.loads(value)
             return value
 
     def set(self, key, value):
         with self._dbm_file(True) as dbm:
-            dbm[key] = util.pickle.dumps(value)
+            dbm[key] = compat.pickle.dumps(value)
 
     def delete(self, key):
         with self._dbm_file(True) as dbm:
     """
 
     def __init__(self, filename):
-        self._filedescriptor = util.threading.local()
+        self._filedescriptor = compat.threading.local()
         self.filename = filename
 
     def acquire(self, wait=True):

dogpile/cache/backends/memcached.py

 """
 
 from dogpile.cache.api import CacheBackend, NO_VALUE
+from dogpile.cache import compat
 from dogpile.cache import util
 import random
 import time
     @util.memoized_property
     def _clients(self):
         backend = self
-        class ClientPool(util.threading.local):
+        class ClientPool(compat.threading.local):
             def __init__(self):
                 self.memcached = backend._create_client()
 

dogpile/cache/backends/redis.py

 
 from __future__ import absolute_import
 from dogpile.cache.api import CacheBackend, NO_VALUE
-from dogpile.cache.util import pickle
+from dogpile.cache.compat import pickle
 import random
 import time
 

dogpile/cache/compat.py

+import sys
+
+
+py3k = sys.version_info >= (3, 0)
+jython = sys.platform.startswith('java')
+
+
+try:
+    import threading
+except ImportError:
+    import dummy_threading as threading
+
+
+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

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
+from . import compat
 
 
 def coerce_string_conf(d):
     result = {}
     for k, v in d.items():
-        if not isinstance(v, string_types):
+        if not isinstance(v, compat.string_types):
             result[k] = v
             continue
 
                     "function does not accept keyword arguments.")
         if has_self:
             args = args[1:]
-        return namespace + "|" + " ".join(map(text_type, args))
+        return namespace + "|" + " ".join(map(compat.text_type, args))
     return generate_key
 
 def sha1_mangle_key(key):
         return fac
 
     def acquire(self, wait=True):
-        current_thread = threading.current_thread().ident
+        current_thread = compat.threading.current_thread().ident
         keys = self.keys.get(current_thread)
         if keys is not None and \
             self.key not in keys:
             return False
 
     def release(self):
-        current_thread = threading.current_thread().ident
+        current_thread = compat.threading.current_thread().ident
         keys = self.keys.get(current_thread)
         assert keys is not None, "this thread didn't do the acquire"
         assert self.key in keys, "No acquire held for key '%s'" % self.key

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
 [egg_info]
-tag_build = dev
 
 [upload_docs]
 upload-dir = docs/build/output/html
 
+
+[nosetests]
+cover-package = dogpile.cache
+with-coverage = 1
+cover-erase = 1

tests/cache/__init__.py

     except except_cls as e:
         assert re.search(msg, str(e)), "%r !~ %s" % (msg, e)
 
-from dogpile.compat import configparser, io
+from dogpile.cache.compat import configparser, io
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.