Permalink
Browse files

Refactor for being a proper Python package.

  • Loading branch information...
bbangert committed May 22, 2010
1 parent 0e2b7d2 commit ce097c988ada5365c8a9b355b0406cc0af62b808
View
@@ -0,0 +1,3 @@
+*.py?
+*.egg-info
+*.swp
View
@@ -1,51 +0,0 @@
-import logging
-from beaker_nosql import *
-
-try:
- from dynomite import Dynomite
- from dynomite.ttypes import *
-except ImportError:
- raise InvalidCacheBackendError("Dynomite cache backend requires the 'dynomite' library")
-
-try:
- from thrift import Thrift
- from thrift.transport import TSocket
- from thrift.transport import TTransport
- from thrift.protocol import TBinaryProtocol
-except ImportError:
- raise InvalidCacheBackendError("Dynomite cache backend requires the 'thrift' library")
-
-log = logging.getLogger(__name__)
-
-class DynomiteManager(NoSqlManager):
- def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
- NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
-
- def open_connection(self, host, port):
- self.transport = TSocket.TSocket(host, int(port))
- self.transport = TTransport.TBufferedTransport(transport)
- self.protocol = TBinaryProtocol.TBinaryProtocol(transport)
- self.db_conn = Dynomite.Client(protocol)
- self.transport.open()
-
- def __contains__(self, key):
- return self.db_conn.has(self._format_key(key))
-
- def has_key(self, key):
- return key in self
-
- def set_value(self, key, value):
- self.db_conn.put(self._format_key(key), None, value)
-
- def __delitem__(self, key):
- self.db_conn.remove(self._format_key(key))
-
- def do_remove(self):
- raise Exception("Unimplemented")
-
- def keys(self):
- raise Exception("Unimplemented")
-
-
-class DynomiteContainer(Container):
- namespace_manager = DynomiteManager
@@ -0,0 +1 @@
+#
@@ -0,0 +1,53 @@
+import logging
+from beaker_extensions.nosql import Container
+from beaker_extensions.nosql import InvalidCacheBackendError
+from beaker_extensions.nosql import NoSqlManager
+
+try:
+ from dynomite import Dynomite
+ from dynomite.ttypes import *
+except ImportError:
+ raise InvalidCacheBackendError("Dynomite cache backend requires the 'dynomite' library")
+
+try:
+ from thrift import Thrift
+ from thrift.transport import TSocket
+ from thrift.transport import TTransport
+ from thrift.protocol import TBinaryProtocol
+except ImportError:
+ raise InvalidCacheBackendError("Dynomite cache backend requires the 'thrift' library")
+
+log = logging.getLogger(__name__)
+
+class DynomiteManager(NoSqlManager):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+
+ def open_connection(self, host, port):
+ self.transport = TSocket.TSocket(host, int(port))
+ self.transport = TTransport.TBufferedTransport(transport)
+ self.protocol = TBinaryProtocol.TBinaryProtocol(transport)
+ self.db_conn = Dynomite.Client(protocol)
+ self.transport.open()
+
+ def __contains__(self, key):
+ return self.db_conn.has(self._format_key(key))
+
+ def has_key(self, key):
+ return key in self
+
+ def set_value(self, key, value):
+ self.db_conn.put(self._format_key(key), None, value)
+
+ def __delitem__(self, key):
+ self.db_conn.remove(self._format_key(key))
+
+ def do_remove(self):
+ raise Exception("Unimplemented")
+
+ def keys(self):
+ raise Exception("Unimplemented")
+
+
+class DynomiteContainer(Container):
+ namespace_manager = DynomiteManager
View
@@ -0,0 +1,70 @@
+import logging
+
+from beaker.container import NamespaceManager, Container
+from beaker.synchronization import file_synchronizer
+from beaker.util import verify_directory
+from beaker.exceptions import MissingCacheParameter
+
+try:
+ import cPickle as pickle
+except:
+ import pickle
+
+log = logging.getLogger(__name__)
+
+class NoSqlManager(NamespaceManager):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NamespaceManager.__init__(self, namespace)
+
+ if not url:
+ raise MissingCacheParameter("url is required")
+
+ if lock_dir:
+ self.lock_dir = lock_dir
+ elif data_dir:
+ self.lock_dir = data_dir + "/container_tcd_lock"
+ if self.lock_dir:
+ verify_directory(self.lock_dir)
+
+ host, port = url.split(':')
+
+ self.open_connection(host, int(port))
+
+ def open_connection(self, host, port):
+ self.db_conn = None
+
+ def get_creation_lock(self, key):
+ return file_synchronizer(
+ identifier ="tccontainer/funclock/%s" % self.namespace,
+ lock_dir = self.lock_dir)
+
+ def _format_key(self, key):
+ return self.namespace + '_'
+
+ def __getitem__(self, key):
+ return pickle.loads(self.db_conn.get(self._format_key(key)))
+
+ def __contains__(self, key):
+ return self.db_conn.has_key(self._format_key(key))
+
+ def has_key(self, key):
+ return key in self
+
+ def set_value(self, key, value):
+ self.db_conn[self._format_key(key)] = pickle.dumps(value)
+
+ def __setitem__(self, key, value):
+ self.set_value(key, value)
+
+ def __delitem__(self, key):
+ del self.db_conn[self._format_key(key)]
+
+ def do_remove(self):
+ self.db_conn.clear()
+
+ def keys(self):
+ return self.db_conn.keys()
+
+
+class NoSqlManagerContainer(Container):
+ namespace_manager = NoSqlManager
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,38 @@
+import logging
+from beaker_extensions.nosql import Container
+from beaker_extensions.nosql import InvalidCacheBackendError
+from beaker_extensions.nosql import NoSqlManager
+from beaker_extensions.nosql import pickle
+
+try:
+ from redis import Redis
+except ImportError:
+ raise InvalidCacheBackendError("PyTyrant cache backend requires the 'pytyrant' library")
+
+log = logging.getLogger(__name__)
+
+class RedisManager(NoSqlManager):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+
+ def open_connection(self, host, port):
+ self.db_conn = Redis(host=host, port=int(port))
+
+ def __contains__(self, key):
+ return self.db_conn.exists(self._format_key(key))
+
+ def set_value(self, key, value):
+ self.db_conn.set(key, pickle.dumps(value))
+
+ def __delitem__(self, key):
+ self.db_conn.delete(self._format_key(key))
+
+ def do_remove(self):
+ self.db_conn.flush(all_dbs=True)
+
+ def keys(self):
+ raise self.db_conn.keys('*')
+
+
+class RedisContainer(Container):
+ namespace_manager = RedisManager
View
@@ -0,0 +1,42 @@
+import logging
+from beaker_extensions.nosql import Container
+from beaker_extensions.nosql import InvalidCacheBackendError
+from beaker_extensions.nosql import NoSqlManager
+from beaker_extensions.nosql import pickle
+
+try:
+ from ringogw import Ringo
+except ImportError:
+ raise InvalidCacheBackendError("Ringo cache backend requires the 'ringo' library")
+
+log = logging.getLogger(__name__)
+
+class RingoManager(NoSqlManager):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+
+ def open_connection(self, host, port):
+ self.domain = 'default'
+ self.db_conn = Ringo("%s:%s" % (host, port))
+
+ def __contains__(self, key):
+ raise Exception("Unimplemented")
+
+ def __getitem__(self, key):
+ return pickle.loads(self.db_conn.get(self.domain, self._format_key(key)))
+
+ def set_value(self, key, value):
+ self.db_conn.put(self.domain, self._format_key(key), pickle.dumps(value))
+
+ def __delitem__(self, key):
+ raise Exception("Unimplemented")
+
+ def do_remove(self):
+ raise Exception("Unimplemented")
+
+ def keys(self):
+ raise Exception("Unimplemented")
+
+
+class RingoContainer(Container):
+ namespace_manager = RingoManager
File renamed without changes.
@@ -0,0 +1,39 @@
+# Courtesy of: http://www.jackhsu.com/2009/05/27/pylons-with-tokyo-cabinet-beaker-sessions
+import logging
+from beaker_extensions.nosql import Container
+from beaker_extensions.nosql import InvalidCacheBackendError
+from beaker_extensions.nosql import NoSqlManager
+from beaker_extensions.nosql import pickle
+
+try:
+ from pytyrant import PyTyrant
+except ImportError:
+ raise InvalidCacheBackendError("PyTyrant cache backend requires the 'pytyrant' library")
+
+log = logging.getLogger(__name__)
+
+class TokyoTyrantManager(NoSqlManager):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ NoSqlManager.__init__(self, namespace, url=url, data_dir=data_dir, lock_dir=lock_dir, **params)
+
+ def open_connection(self, host, port):
+ self.db_conn = PyTyrant.open(host, int(port))
+
+ def __contains__(self, key):
+ return self.db_conn.has_key(self._format_key(key))
+
+ def set_value(self, key, value):
+ self.db_conn[self._format_key(key)] = pickle.dumps(value)
+
+ def __delitem__(self, key):
+ del self.db_conn[self._format_key(key)]
+
+ def do_remove(self):
+ self.db_conn.clear()
+
+ def keys(self):
+ return self.db_conn.keys()
+
+
+class TokyoTyrantContainer(Container):
+ namespace_manager = TokyoTyrantManager
View
@@ -1,70 +0,0 @@
-import logging
-
-from beaker.container import NamespaceManager, Container
-from beaker.synchronization import file_synchronizer
-from beaker.util import verify_directory
-from beaker.exceptions import MissingCacheParameter
-
-try:
- import cPickle as pickle
-except:
- import pickle
-
-log = logging.getLogger(__name__)
-
-class NoSqlManager(NamespaceManager):
- def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
- NamespaceManager.__init__(self, namespace)
-
- if not url:
- raise MissingCacheParameter("url is required")
-
- if lock_dir:
- self.lock_dir = lock_dir
- elif data_dir:
- self.lock_dir = data_dir + "/container_tcd_lock"
- if self.lock_dir:
- verify_directory(self.lock_dir)
-
- host, port = url.split(':')
-
- self.open_connection(host, int(port))
-
- def open_connection(self, host, port):
- self.db_conn = None
-
- def get_creation_lock(self, key):
- return file_synchronizer(
- identifier ="tccontainer/funclock/%s" % self.namespace,
- lock_dir = self.lock_dir)
-
- def _format_key(self, key):
- return self.namespace + '_'
-
- def __getitem__(self, key):
- return pickle.loads(self.db_conn.get(self._format_key(key)))
-
- def __contains__(self, key):
- return self.db_conn.has_key(self._format_key(key))
-
- def has_key(self, key):
- return key in self
-
- def set_value(self, key, value):
- self.db_conn[self._format_key(key)] = pickle.dumps(value)
-
- def __setitem__(self, key, value):
- self.set_value(key, value)
-
- def __delitem__(self, key):
- del self.db_conn[self._format_key(key)]
-
- def do_remove(self):
- self.db_conn.clear()
-
- def keys(self):
- return self.db_conn.keys()
-
-
-class NoSqlManagerContainer(Container):
- namespace_manager = NoSqlManager
Oops, something went wrong.

0 comments on commit ce097c9

Please sign in to comment.