Commits

Dhananjay Nene committed 79cbc8b

changed keyword parameter initialisation logic

Comments (0)

Files changed (1)

src/pybuckets/botos3.py

         k.key = name
         return k.set_contents_from_string(value)
 
+def build_kw_from_params_and_object(params,obj,candidates) :
+    kw = {}
+    for key in candidates :
+        if key in params : kw[key] = params[key]
+        elif hasattr(obj,key) : kw[key] = getattr(obj,key)
+    return kw
+
 class BotoS3Server(BucketServer):
     def __init__(self,**config):
         super(BotoS3Server,self).__init__()
-        self.key = config['key']
-        self.password = config['password']
+        for key,val in config.items() :
+            if key in ('key','password','headers','location','policy') :
+                self.__dict__[key] = val
+        
         self.connection = S3Connection(self.key,self.password)
-        for property, default in (('headers',None),('location',''),('policy',None)) :
-            self.config[property] = config.get(property,default)
             
     def keys(self):
         return map(operator.attrgetter('name'),self.connection.get_all_buckets())
     def create_bucket(self,name,**kwargs):
         try :
             bucket = self.connection.create_bucket(name,
-                                kwargs.get('headers',self.config['headers']),
-                                kwargs.get('location',self.config['location']),
-                                kwargs.get('policy',self.config['policy']),
+                                **build_kw_from_params_and_object(kwargs,self,('headers','location','policy'))
                             )
             return self.create_using_boto_bucket(bucket)
         except S3CreateError as s3e :