pymensago/contact.py
def _unflatten_recurse(target: Union[dict,list], levels: list, levelindex: int, value: str) -> RetVal:
	'''This method continues to unpack a dot-notated string field. It is only called by itself or 
	unflatten(), so we will assume that parameter values are correct.'''

	if isinstance(target, list):
		target_is_list = True
		targetindex = int(levels[levelindex])
	else:
		target_is_list = False
		targetindex = levels[levelindex]

	if len(levels[levelindex:]) == 1:
		if target_is_list:
			value_index = int(levels[-1])
			
			if value_index == len(target):
				target.append(value)
			elif value_index < 0:
				return RetVal(ErrBadValue, f"negative list index for f{'.'.join(levels)}")
			elif value_index < len(target):
				target[value_index] = value
			elif value_index > len(target):
				return RetVal(ErrOutOfRange, f"list index for f{'.'.join(levels)} out of bounds")
		else:
			target[levels[-1]] = value
	else:
		value_index_is_int = True
		try:
			value_index = int(levels[levelindex+1])
		except:
			value_index = levels[levelindex+1]
			value_index_is_int = False

		if target_is_list:
			# Check to see if item is already in the list
			# if it exists, check index type against list. If not, add new container to list
			if targetindex == len(target):
				if value_index_is_int:
					target.append(list())
				else:
					target.append(dict())
			elif targetindex < 0:
				return RetVal(ErrBadValue, f"negative list index for f{'.'.join(levels)}")
			elif targetindex > len(target):
				return RetVal(ErrOutOfRange, f"list index for f{'.'.join(levels)} out of bounds")
			
			# Recurse into list as target
			return _unflatten_recurse(target[targetindex], levels, levelindex+1, value)
		else:
			# Check to see if item is already in the dictionary
			# if it exists, check index type against dictionary. If not, add new container
			# Recurse into new list as target
			if targetindex not in target:
				if isinstance(target, list):
					if value_index_is_int:
						target.append(list())
					else:
						target.append(dict())
				else:
					if value_index_is_int:
						target[targetindex] = list()
					else:
						target[targetindex] = dict()
			
			# Recurse into dict as target
			return _unflatten_recurse(target[targetindex], levels, levelindex+1, value)

	return RetVal()
This method continues to unpack a dot-notated string field. It is only called by itself or 
	unflatten(), so we will assume that parameter values are correct.
This method continues to unpack a dot-notated string field. It is only called by itself or
unflatten(), so we will assume that parameter values are correct.
This method continues to unpack a dot - notated string field . It is only called by itself or unflatten () so we will assume that parameter values are correct .
def _unflatten_recurse(target: Union[dict,list], levels: list, levelindex: int, value: str) -> RetVal:
	if isinstance(target, list):
		target_is_list = True
		targetindex = int(levels[levelindex])
	else:
		target_is_list = False
		targetindex = levels[levelindex]
	if len(levels[levelindex:]) == 1:
		if target_is_list:
			value_index = int(levels[-1])
			if value_index == len(target):
				target.append(value)
			elif value_index < 0:
				return RetVal(ErrBadValue, f"negative list index for f{'.'.join(levels)}")
			elif value_index < len(target):
				target[value_index] = value
			elif value_index > len(target):
				return RetVal(ErrOutOfRange, f"list index for f{'.'.join(levels)} out of bounds")
		else:
			target[levels[-1]] = value
	else:
		value_index_is_int = True
		try:
			value_index = int(levels[levelindex+1])
		except:
			value_index = levels[levelindex+1]
			value_index_is_int = False
		if target_is_list:
			if targetindex == len(target):
				if value_index_is_int:
					target.append(list())
				else:
					target.append(dict())
			elif targetindex < 0:
				return RetVal(ErrBadValue, f"negative list index for f{'.'.join(levels)}")
			elif targetindex > len(target):
				return RetVal(ErrOutOfRange, f"list index for f{'.'.join(levels)} out of bounds")
			return _unflatten_recurse(target[targetindex], levels, levelindex+1, value)
		else:
			if targetindex not in target:
				if isinstance(target, list):
					if value_index_is_int:
						target.append(list())
					else:
						target.append(dict())
				else:
					if value_index_is_int:
						target[targetindex] = list()
					else:
						target[targetindex] = dict()
			return _unflatten_recurse(target[targetindex], levels, levelindex+1, value)
	return RetVal()
def _unflatten_recurse ( target : Union [ dict , list ] , levels : list , levelindex : int , value : str ) -> RetVal : if isinstance ( target , list ) : target_is_list = True targetindex = int ( levels [ levelindex ] ) else : target_is_list = False targetindex = levels [ levelindex ] if len ( levels [ levelindex : ] ) == 1 : if target_is_list : value_index = int ( levels [ - 1 ] ) if value_index == len ( target ) : target . append ( value ) elif value_index < 0 : return RetVal ( ErrBadValue , f"negative list index for f{'.'.join(levels)}" ) elif value_index < len ( target ) : target [ value_index ] = value elif value_index > len ( target ) : return RetVal ( ErrOutOfRange , f"list index for f{'.'.join(levels)} out of bounds" ) else : target [ levels [ - 1 ] ] = value else : value_index_is_int = True try : value_index = int ( levels [ levelindex + 1 ] ) except : value_index = levels [ levelindex + 1 ] value_index_is_int = False if target_is_list : if targetindex == len ( target ) : if value_index_is_int : target . append ( list ( ) ) else : target . append ( dict ( ) ) elif targetindex < 0 : return RetVal ( ErrBadValue , f"negative list index for f{'.'.join(levels)}" ) elif targetindex > len ( target ) : return RetVal ( ErrOutOfRange , f"list index for f{'.'.join(levels)} out of bounds" ) return _unflatten_recurse ( target [ targetindex ] , levels , levelindex + 1 , value ) else : if targetindex not in target : if isinstance ( target , list ) : if value_index_is_int : target . append ( list ( ) ) else : target . append ( dict ( ) ) else : if value_index_is_int : target [ targetindex ] = list ( ) else : target [ targetindex ] = dict ( ) return _unflatten_recurse ( target [ targetindex ] , levels , levelindex + 1 , value ) return RetVal ( )
This method continues to unpack a dot-notated string field.
This method continues to unpack a dot - notated string field .
'''This method continues to unpack a dot-notated string field. It is only called by itself or 
	unflatten(), so we will assume that parameter values are correct.''' # Check to see if item is already in the list # if it exists, check index type against list. If not, add new container to list # Recurse into list as target # Check to see if item is already in the dictionary # if it exists, check index type against dictionary. If not, add new container # Recurse into new list as target # Recurse into dict as target
target
Union[dict,list]
levels
list
levelindex
int
value
str