from sfa.util.faults import MissingSfaInfo
from sfa.util.sfalogging import logger
from sfa.util.table import SfaTable
+from sfa.util.defaultdict import defaultdict
from sfa.util.xrn import hrn_to_urn
from sfa.util.plxrn import slicename_to_hrn, hostname_to_hrn, hrn_to_pl_slicename, hrn_to_pl_login_base
from sfa.server.sfaapi import SfaApi
-#################### xxx should move into util/defaultdict
-try:
- from collections import defaultdict
-except:
- class defaultdict(dict):
- def __init__(self, default_factory=None, *a, **kw):
- if (default_factory is not None and
- not hasattr(default_factory, '__call__')):
- raise TypeError('first argument must be callable')
- dict.__init__(self, *a, **kw)
- self.default_factory = default_factory
- def __getitem__(self, key):
- try:
- return dict.__getitem__(self, key)
- except KeyError:
- return self.__missing__(key)
- def __missing__(self, key):
- if self.default_factory is None:
- raise KeyError(key)
- self[key] = value = self.default_factory()
- return value
- def __reduce__(self):
- if self.default_factory is None:
- args = tuple()
- else:
- args = self.default_factory,
- return type(self), args, None, None, self.items()
- def copy(self):
- return self.__copy__()
- def __copy__(self):
- return type(self)(self.default_factory, self)
- def __deepcopy__(self, memo):
- import copy
- return type(self)(self.default_factory,
- copy.deepcopy(self.items()))
- def __repr__(self):
- return 'defaultdict(%s, %s)' % (self.default_factory,
- dict.__repr__(self))
-## end of http://code.activestate.com/recipes/523034/ }}}
-
def list_to_dict(recs, key):
"""
convert a list of dictionaries into a dictionary keyed on the
else:
oldList = []
newList = record.get(listName, [])
- # xxx ugly hack - somehow we receive here a list of {'text':value}
- # instead of an expected list of strings
- # please remove once this is issue is cleanly fixed
- #def normalize (value):
- # from types import StringTypes
- # if isinstance(value,StringTypes): return value
- # elif isinstance(value,dict):
- # newvalue=value['text']
- # logger.info("Normalizing %s=>%s"%(value,newvalue))
- # return newvalue
- #newList=[normalize(v) for v in newList]
# if the lists are the same, then we don't have to update anything
if (oldList == newList):