[master/rhel7 1/2] Add DataHolder class (#1034427)

Vratislav Podzimek vpodzime at redhat.com
Mon Jan 20 11:55:04 UTC 2014


On Fri, 2014-01-17 at 16:21 -0800, Brian C. Lane wrote:
> This add a dictionary-like class that allows the keys to also be
> accessed via dot notation. You can set an initial set using keyword args
> in the initializer.
> 
> Related: rhbz#1034427
> ---
>  pyanaconda/iutil.py | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
> index 4c1995b..32dbe4f 100644
> --- a/pyanaconda/iutil.py
> +++ b/pyanaconda/iutil.py
> @@ -739,3 +739,21 @@ def upcase_first_letter(text):
>          return text.upper()
>      else:
>          return text[0].upper() + text[1:]
> +
> +class DataHolder(dict):
> +    """ A dict that lets you also access keys using dot notation. """
> +    def __init__(self, **kwargs):
> +        """ kwargs are set as keys for the dict. """
> +        dict.__init__(self)
> +
> +        for attr, value in kwargs.items():
> +            self[attr] = value
> +
> +    def __getattr__(self, attr):
> +        return self[attr]
> +
> +    def __setattr__(self, attr, value):
> +        self[attr] = value
> +
> +    def copy(self):
> +        return DataHolder(**dict.copy(self))
I'd like to see a tiny unit test doing some very basic stuff with this
class. If for nothing else, it would be useful for potential future
tweaks of the class. Otherwise this looks good to me.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list