Commits

Dhananjay Nene committed 3858f2c

Added support for memcached

  • Participants
  • Parent commits c52a4d9

Comments (0)

Files changed (3)

File docs/source/index.rst

 
 **pybuckets** is an open source library to help you quickly and easily access cloud based storage services eg. `Amazon S3 <http://aws.amazon.com/s3>`_, `Rackspace Cloudfiles <http://www.rackspacecloud.com/cloud_hosting_products/files>`_. 
 
+*pybuckets* source can be accessed on `bitbucket.org <http://bitbucket.org/dnene/pybuckets>`_
+
 Characteristics
 ---------------
 

File src/pybuckets/memcached.py

+from pybuckets import Bucket, MethodNotSupportedException, bucket_registry
+import memcache
+
+class MemcacheBucket(Bucket):
+    def __init__(self,urls):
+        self.memc = memcache.Client(urls)
+        
+    def __iter__(self):
+        return self.keys().__iter__()
+        
+    def __str__(self):
+        return 'MemcacheBucket(%s,%s)' % (self.key, str(self.server))
+    
+    def keys(self):
+        return MethodNotSupportedException(self.keys)
+#        
+    def get_data(self,key):
+        return self.memc.get(key)
+#    
+    def set_data(self,key,value):
+        self.memc.set(key,value)
+    
+    def delete_key(self,key):
+        self.memc.delete(key)
+        
+bucket_registry['localfs'] = MemcacheBucket
+
+    
+

File src/pybuckets/pybuckets.py

 server_registry = {}
 """Registry for autoregistration of various component libraries"""
 
+bucket_registry = {}
+""" Registry for autoregistration of various component libraries supporting just a bucket"""
+
 class BucketsException(Exception):
     """Exception class to wrap various exceptions"""
     def __init__(self,e):
     def __repr__(self):
         return 'DuplicateBucketNameException(%s)' % str(self.name)
 
+class MethodNotSupportedException(BucketsException):
+    """A exception indicating that the particular method is not supported 
+    by the underlying component library"""
+    def __init__(self,method):
+        super(MethodNotSupportedException,self).__init__(None)
+        self.method = method
+    def __str__(self):
+        return 'MethodNotSupportedException(%s)' % str(self.method)
+    def __repr__(self):
+        return 'MethodNotSupportedException(%s)' % str(self.method)
+
 class BucketDataReader(object):
     "Reader class to allow controlled access to reading data streams"
     def __init__(self,pointer,reader):
         return self.delete_key(key)
     def __str__(self):
         return 'Bucket(%s,%s)' % (self.name, str(self.server))
+    @classmethod
+    def get_bucket(cls,name,**creds):
+        return bucket_registry[name](**creds)
         
 class BucketServerIterator(object):
     "A bucket server iterator"