On Wed, Aug 05, 2009 at 02:01:23PM +0100, Guido Trotter wrote:
> 
> If a value is None, there's no point exporting it in the relevant dict
> representation for an object: it will be None again when the object is
> loaded by FromDict. This has the nice side effect of removing
> "deprecated" slots from the config file.
> 
> __getstate__ is also modified to filter out None members.
> 
> Signed-off-by: Guido Trotter <[email protected]>
> ---
>  lib/objects.py |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/objects.py b/lib/objects.py
> index 6be372b..e199a05 100644
> --- a/lib/objects.py
> +++ b/lib/objects.py
> @@ -107,7 +107,7 @@ class ConfigObject(object):
>    def __getstate__(self):
>      state = {}
>      for name in self.__slots__:
> -      if hasattr(self, name):
> +      if hasattr(self, name) and getattr(self, name) is not None:
>          state[name] = getattr(self, name)
if hasattr():
  val = getattr()
  if val is not None:
    state[] = val

>      return state
>  
> @@ -126,7 +126,8 @@ class ConfigObject(object):
>      make sure all objects returned are only standard python types.
>  
>      """
> -    return dict([(k, getattr(self, k, None)) for k in self.__slots__])
> +    return dict([(k, getattr(self, k, None)) for k in self.__slots__
> +                 if getattr(self, k, None) is not None])
>  
>    @classmethod
>    def FromDict(cls, val):
> -- 
> 1.5.6.5
> 

Reply via email to