17 from collections
import MutableMapping
19 from collections.abc
import MutableMapping
21 from .platform
import IRONPYTHON, PY_VERSION, PY3
22 from .robottypes
import is_dict_like, is_unicode
30 def normalize(string, ignore=(), caseless=
True, spaceless=
True):
32 if PY3
and isinstance(ignore, bytes):
34 ignore = [bytes([i])
for i
in ignore]
36 string = empty.join(string.split())
38 string =
lower(string)
39 ignore = [
lower(i)
for i
in ignore]
44 string = string.replace(ign, empty)
49 if IRONPYTHON
and PY_VERSION < (2, 7, 5):
51 return (
'A' + string).
lower()[1:]
68 def __init__(self, initial=None, ignore=(), caseless=
True, spaceless=
True):
76 items = initial.items()
if hasattr(initial,
'items')
else initial
77 for key, value
in items:
85 self.
_data_data[norm_key] = value
86 self.
_keys_keys.setdefault(norm_key, key)
90 del self.
_data_data[norm_key]
91 del self.
_keys_keys[norm_key]
94 return (self.
_keys_keys[norm_key]
for norm_key
in sorted(self.
_keys_keys))
97 return len(self.
_data_data)
100 return '{%s}' %
', '.join(
'%r: %r' % (key, self[key])
for key
in self)
105 if not isinstance(other, NormalizedDict):
107 return self.
_data_data == other._data
110 return not self == other
Custom dictionary implementation automatically normalizing keys.
def __contains__(self, key)
def __setitem__(self, key, value)
def __init__(self, initial=None, ignore=(), caseless=True, spaceless=True)
Initialized with possible initial value and normalizing spec.
def _add_initial(self, initial)
def __delitem__(self, key)
def __getitem__(self, key)
def normalize(string, ignore=(), caseless=True, spaceless=True)
Normalizes given string according to given spec.