Package ganeti :: Module serializer :: Class PrivateDict
[hide private]
[frames] | no frames]

Class PrivateDict

source code


A dictionary that turns its values to private fields.

>>> PrivateDict()
{}
>>> supersekkrit = PrivateDict({"password": "foobar"})
>>> print supersekkrit["password"]
<password>
>>> supersekkrit["password"].Get()
'foobar'
>>> supersekkrit.GetPrivate("password")
'foobar'
>>> supersekkrit["user"] = "eggspam"
>>> supersekkrit.Unprivate()
{'password': 'foobar', 'user': 'eggspam'}
Instance Methods [hide private]
new empty dictionary

__init__(self, data=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__setitem__(self, item, value)
x[i]=y
source code
None
update(self, other=None, **kwargs)
Update D from dict/iterable E and F.
source code
 
GetPrivate(self, *args)
Like dict.get, but extracting the value in the process.
source code
dict
Unprivate(self)
Turn this dict of Private() values to a dict of values.
source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __sizeof__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, values, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Returns:
new empty dictionary

Overrides: object.__init__
(inherited documentation)

__setitem__(self, item, value)
(Index assignment operator)

source code 

x[i]=y

Overrides: dict.__setitem__
(inherited documentation)

update(self, other=None, **kwargs)

source code 

Update D from dict/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

Returns: None
Overrides: dict.update
(inherited documentation)

GetPrivate(self, *args)

source code 

Like dict.get, but extracting the value in the process.

Arguments are semantically equivalent to ``dict.get``

>>> PrivateDict({"foo": "bar"}).GetPrivate("foo")
'bar'
>>> PrivateDict({"foo": "bar"}).GetPrivate("baz", "spam")
'spam'

Unprivate(self)

source code 

Turn this dict of Private() values to a dict of values.

>>> PrivateDict({"foo": "bar"}).Unprivate()
{'foo': 'bar'}
Returns: dict