convert json/dict of element configuration into elegant/mad format
        :param kw: keyword
436340
def formatElement(self, kw, format='elegant'):
        
        etype = self.getElementType(kw)
        econf_dict = self.getElementConf(kw)
        econf_str = ''
        for k, v in econf_dict.items():
            econf_str += (k + ' = ' + '"' + str(v) + '"' + ', ')

        if format == 'elegant':
            fmtstring = '{eid:<10s}:{etype:>10s}, {econf}'.format(eid=kw.upper(),
                                                                  etype=etype.upper(),
                                                                  econf=econf_str[
                                                                        :-2])
            # [:-2] slicing to remove trailing space and ','
        elif format == 'mad':
            raise NotImplementedError("Not implemented, yet")

        return fmtstring
1085810
def resolve_kw(self, kwargs):
        
        resolved = {}
        for key, value in kwargs.items():
            split = key.split('_', 1)
            if len(split) > 1:
                key = split[1]
            resolved[key] = value
        return resolved
264182
def key_from_dict(**kwargs):
    
    out = []
    stack = [kwargs]
    while stack:
        obj = stack.pop()
        if isinstance(obj, dict):
            stack.extend(sorted(obj.items()))
        elif isinstance(obj, (list, tuple)):
            stack.extend(obj)
        else:
            out.append(str(obj))
    return ''.join(out)
839764
def serialize_to_json(data, **kwargs):
    
    kwargs['cls'] = kwargs.get('cls', LazyJSONEncoder)

    return json.dumps(data, **kwargs)
1352781
def references_to_dict(elements):
    
    dictionary = {}
    for kvp in elements:
        dictionary[str(kvp['rel'])] = str(kvp['href'])
    return dictionary
759510
def makeElement(self, kw):
        
        kw_name = kw
        kw_type = self.getKwType(kw_name)
        kw_config = {k.lower(): v for k, v in self.getKwConfig(kw_name).items()}
        objtype = 'Element' + kw_type.capitalize()
        retobj = getattr(element, objtype)(name=kw_name, config=kw_config)
        # set up EPICS control configs
        ctrlconf = self.getKwCtrlConf(kw_name)
        if ctrlconf != {}:
            retobj.setConf(ctrlconf, type='ctrl')

        return retobj
765832
def makeElement(self, kw):
        
        kw_name = kw
        kw_type = self.getElementType(kw_name)
        kw_config = {k.lower(): v for k, v in self.getElementConf(kw_name).items()}
        objtype = 'Element' + kw_type.capitalize()
        retobj = getattr(element, objtype)(name=kw_name, config=kw_config)
        # set up EPICS control configs
        ctrlconf = self.getElementCtrlConf(kw)
        if ctrlconf != {}:
            retobj.setConf(ctrlconf, type='ctrl')

        return retobj
232590
def from_json_format(conf):
    ''''''
    if 'fmode' in conf:
        conf['fmode'] = int(conf['fmode'], 8)
    if 'dmode' in conf:
        conf['dmode'] = int(conf['dmode'], 8)
131231
def to_dict(self, rw = False):
		'''
		'''
		return {k:v for (k,v) in self.attributes.items() 
				if (v is not None and (not rw or (k in self.rw_attr_keys)))}
1028561
def from_json(cls, attributes):
        
        return cls(**{to_snake_case(k): v for k, v in attributes.items()})
1103510
def format_json(item, **kwargs):
    
    try:
        json.dumps(item.value)
        return item.value
    except TypeError:
        if 'time' in item.class_type.lower() \
                or 'date' in item.class_type.lower():
            return item.value.isoformat()
        raise
131824
def to_dict(item):
        
        def convert(item):
            if isinstance(item, IterableObject):
                if isinstance(item.source, dict):
                    return {k: convert(v.source) if hasattr(v, 'source') else convert(v) for k, v in item}
                else:
                    return convert(item.source)
            elif isinstance(item, dict):
                return {k: convert(v) for k, v in item.items()}
            elif isinstance(item, list):
                def yield_convert(item):
                    for index, value in enumerate(item):
                        yield convert(value)
                return list(yield_convert(item))
            else:
                return item

        return convert(item)
467359
def translate_kwargs(self, **kwargs):
        """"""
        local_kwargs = self.kwargs.copy()
        local_kwargs.update(kwargs)

        if "data" in local_kwargs and "json" in local_kwargs:
            raise ValueError("Cannot use data and json together")

        if "data" in local_kwargs and isinstance(local_kwargs["data"], dict):
            local_kwargs.update({"json": local_kwargs["data"]})
            del local_kwargs["data"]

        headers = DEFAULT_HEADERS.copy()
        if "headers" in kwargs:
            headers.update(kwargs["headers"])
        if "json" in local_kwargs:
            headers.update({"Content-Type": "application/json;charset=UTF-8"})
        local_kwargs.update({"headers": headers})

        return local_kwargs
1328387
def to_json(self, *args, **kwargs):
        
        return json.dumps(self.serialized, *args, **kwargs)
512459
def tree_to_dict(cls, tree):
        
        specs = {}
        for k in tree.keys():
            spec_key = '.'.join(k)
            specs[spec_key] = {}
            for grp in tree[k].groups:
                kwargs = tree[k].groups[grp].kwargs
                if kwargs:
                    specs[spec_key][grp] = kwargs
        return specs
1199598
def from_dict(val, onts, mdb_safe=False):
    
    if isinstance(val, dict):
        if "__class__" in val:
            ns, typ = val["__class__"].split("&")
            cls = getattr(onts[ns], typ)
            if cls is md.Extensions:
                lv = []
                for key, ditems in val.items():
                    if key in EXP_SKIP:
                        continue
                    for item in ditems:
                        ns, typ = item["__class__"].split("&")
                        cls = getattr(onts[ns], typ)
                        kwargs = _kwa(item, onts, mdb_safe)
                        inst = cls(**kwargs)
                        lv.append(element_to_extension_element(inst))
                return lv
            else:
                kwargs = _kwa(val, onts, mdb_safe)
                inst = cls(**kwargs)
            return inst
        else:
            res = {}
            for key, v in val.items():
                if mdb_safe:
                    key = key.replace("__", ".")
                res[key] = from_dict(v, onts)
            return res
    elif isinstance(val, six.string_types):
        return val
    elif isinstance(val, list):
        return [from_dict(v, onts) for v in val]
    else:
        return val
1080734
def _kwargs_to_attributes(self, kwargs):
        
        for key, val in kwargs.iteritems():
            if key not in self.__dict__:
                raise ValueError(
                    "Can't set %s parameter - it is not defined here!" % key
                )

            self.__dict__[key] = val