def _build_namespace_dict(cls, obj, dots=False):
        """Recursively replaces all argparse.Namespace and optparse.Values
        with dicts and drops any keys with None values.

        Additionally, if dots is True, will expand any dot delimited
        keys.

        :param obj: Namespace, Values, or dict to iterate over. Other
            values will simply be returned.
        :type obj: argparse.Namespace or optparse.Values or dict or *
        :param dots: If True, any properties on obj that contain dots (.)
            will be broken down into child dictionaries.
        :return: A new dictionary or the value passed if obj was not a
            dict, Namespace, or Values.
        :rtype: dict or *
        """
        # We expect our root object to be a dict, but it may come in as
        # a namespace
        obj = namespace_to_dict(obj)
        # We only deal with dictionaries
        if not isinstance(obj, dict):
            return obj

        # Get keys iterator
        keys = obj.keys() if PY3 else obj.iterkeys()
        if dots:
            # Dots needs sorted keys to prevent parents from
            # clobbering children
            keys = sorted(list(keys))

        output = {}
        for key in keys:
            value = obj[key]
            if value is None:  # Avoid unset options.
                continue

            save_to = output
            result = cls._build_namespace_dict(value, dots)
            if dots:
                # Split keys by dots as this signifies nesting
                split = key.split('.')
                if len(split) > 1:
                    # The last index will be the key we assign result to
                    key = split.pop()
                    # Build the dict tree if needed and change where
                    # we're saving to
                    for child_key in split:
                        if child_key in save_to and \
                                isinstance(save_to[child_key], dict):
                            save_to = save_to[child_key]
                        else:
                            # Clobber or create
                            save_to[child_key] = {}
                            save_to = save_to[child_key]

            # Save
            if key in save_to:
                save_to[key].update(result)
            else:
                save_to[key] = result
        return output
Recursively replaces all argparse.Namespace and optparse.Values
        with dicts and drops any keys with None values.

        Additionally, if dots is True, will expand any dot delimited
        keys.

        :param obj: Namespace, Values, or dict to iterate over. Other
            values will simply be returned.
        :type obj: argparse.Namespace or optparse.Values or dict or *
        :param dots: If True, any properties on obj that contain dots (.)
            will be broken down into child dictionaries.
        :return: A new dictionary or the value passed if obj was not a
            dict, Namespace, or Values.
        :rtype: dict or *