pymensago/contact.py
def flatten(d: dict) -> RetVal:
	'''Flattens a dictionary in Contact format into a single-level dot-notated dictionary. All 
	fields are expected to be dictionaries, lists, or strings. The flattened result is returned 
	in the 'value' field unless there is an error.'''
	if not len(d):
		return RetVal().set_value('value', dict())
	
	if not isinstance(d, dict):
		return RetVal(ErrBadType)
	
	flattened = dict()
	for k,v in d.items():
		status = RetVal()
		if isinstance(v, str):
			flattened[k] = v
		elif isinstance(v, dict):
			status = _flatten_dict(flattened, [k], v)
		elif isinstance(v, list):
			status = _flatten_list(flattened, [k], v)
		else:
			return RetVal(ErrBadValue, f"field {k} is not dictionary, list, or string")
		
		if status.error():
			return status

	return RetVal().set_value('value', flattened)
Flattens a dictionary in Contact format into a single-level dot-notated dictionary. All 
	fields are expected to be dictionaries, lists, or strings. The flattened result is returned 
	in the 'value' field unless there is an error.
Flattens a dictionary in Contact format into a single-level dot-notated dictionary. All
fields are expected to be dictionaries, lists, or strings. The flattened result is returned
in the 'value' field unless there is an error.
Flattens a dictionary in Contact format into a single - level dot - notated dictionary . All fields are expected to be dictionaries lists or strings . The flattened result is returned in the ' value ' field unless there is an error .
def flatten(d: dict) -> RetVal:
	if not len(d):
		return RetVal().set_value('value', dict())
	if not isinstance(d, dict):
		return RetVal(ErrBadType)
	flattened = dict()
	for k,v in d.items():
		status = RetVal()
		if isinstance(v, str):
			flattened[k] = v
		elif isinstance(v, dict):
			status = _flatten_dict(flattened, [k], v)
		elif isinstance(v, list):
			status = _flatten_list(flattened, [k], v)
		else:
			return RetVal(ErrBadValue, f"field {k} is not dictionary, list, or string")
		if status.error():
			return status
	return RetVal().set_value('value', flattened)
def flatten ( d : dict ) -> RetVal : if not len ( d ) : return RetVal ( ) . set_value ( 'value' , dict ( ) ) if not isinstance ( d , dict ) : return RetVal ( ErrBadType ) flattened = dict ( ) for k , v in d . items ( ) : status = RetVal ( ) if isinstance ( v , str ) : flattened [ k ] = v elif isinstance ( v , dict ) : status = _flatten_dict ( flattened , [ k ] , v ) elif isinstance ( v , list ) : status = _flatten_list ( flattened , [ k ] , v ) else : return RetVal ( ErrBadValue , f"field {k} is not dictionary, list, or string" ) if status . error ( ) : return status return RetVal ( ) . set_value ( 'value' , flattened )
Flattens a dictionary in Contact format into a single-level dot-notated dictionary.
Flattens a dictionary in Contact format into a single - level dot - notated dictionary .
'''Flattens a dictionary in Contact format into a single-level dot-notated dictionary. All 
	fields are expected to be dictionaries, lists, or strings. The flattened result is returned 
	in the 'value' field unless there is an error.'''
d
dict