Commits

Matthew Frazier committed f7bf834

allowed classes to prevent inheritance of config options

  • Participants
  • Parent commits c099b57

Comments (0)

Files changed (3)

File cartero/sender.py

     Note that the base sender class does not handle locking or any form of
     thread-safety. It is the job of its subclasses to lock as appropriate.
     
+    This is a `~cartero.config.ClassWithOptions`.
+    
     :param config: The sender's configuration options.
     """
     __metaclass__ = ClassWithOptions
     
-    #: This contains the options this sender takes as a
-    #: `cartero.utils.config.Options` instance.
-    options = Options()
+    #: This contains the options this sender takes. You use a `dict` when
+    #: creating it, and it gets transformed into an `~cartero.config.Options`
+    #: instance.
+    options = {}
     
     #: Whether this sender supports using custom headers (with the
     #: `~cartero.message.Message.headers` attribute) or not.

File cartero/utils/config.py

     """
     def __new__(mcls, name, bases, attrs):
         option_bases = [b.options for b in bases if hasattr(b, 'options')]
-        if option_bases:
-            if 'options' in attrs:
-                option_bases.append(attrs['options'])
-            od = {}
-            for options in option_bases:
-                od.update(options)
-            attrs['options'] = Options(**od)
+        if 'options' in attrs:
+            option_bases.append(attrs['options'])
+        od = {}
+        for options in option_bases:
+            od.update(options)
+        attrs['options'] = Options(**dict(p for p in od.items()
+                                          if p[1] is not None))
         return type.__new__(mcls, name, bases, attrs)
 
 

File tests/test-config.py

     def test_class_with_options(self):
         class BaseClass(object):
             __metaclass__ = config.ClassWithOptions
-            options = config.Options()
+            options = {}
         
         class SubClass(BaseClass):
-            options = config.Options(hostname=config.String(),
-                                     port=config.Integer())
+            options = dict(hostname=config.String(), port=config.Integer(),
+                           use_ipv6=config.Boolean())
         
         class MixinClass(BaseClass):
-            options = config.Options(username=config.String(),
-                                     password=config.String())
+            options = dict(username=config.String(), password=config.String())
         
         class CompleteClass(SubClass, MixinClass):
-            options = config.Options(use_tls=config.Boolean(),
-                                     port=config.Port())
+            options = dict(use_tls=config.Boolean(), port=config.Port(),
+                           use_ipv6=None)
         
         assert_options(BaseClass)
-        assert_options(SubClass, hostname=config.String, port=config.Integer)
+        assert_options(SubClass, hostname=config.String, port=config.Integer,
+                                 use_ipv6=config.Boolean)
         assert_options(MixinClass, username=config.String,
                        password=config.String)
         assert_options(CompleteClass, hostname=config.String,