################################################################################ # # File: iluutils.py # RCS: $Header: /u/testbed/CVSROOT/dldev/src/IBClient/iluutils.py,v 1.1 1996/09/15 20:51:20 paepcke Exp $ # Description: Routines to make life with ILU easier # Author: Andreas Paepcke, Stanford University # Created: Tue Jul 30 13:43:59 1996 # Modified: Sat Sep 7 15:56:30 1996 (Andreas Paepcke) paepcke@Walrus # Language: Python # Package: N/A # Status: Experimental (Do Not Distribute) # # (c) Copyright 1996, Stanford University, all rights reserved. # ################################################################################ # # Revisions: # # Sat Sep 7 15:28:00 1996 (Andreas Paepcke) paepcke@Walrus # Added getPropNamesFromItemsState ################################################################################ import any ###################################################### # # DLIOP Constructors: # ###################################################### def makeSingleOptionAC(target, cookie, itemClass, hintList): return(makeTAccessCapability([makeTAccessOption(target, cookie, itemClass, hintList)])) def makeTAccessOption(target, cookie, itemClass, hintList): return({'aTarget': target, 'aCookie': any.OutputAny(cookie), 'anItemClass': str(itemClass), 'aHints': hintList}) def makeTAccessCapability(listOfAccessOptions): return(listOfAccessOptions) # Take a list of access capabilities, a list of property names, and a matrix # of property values (one row for the values of one item, where the columns are # headed by the property names). Return a TItemsACState. def makeTItemsACState(ACList, listOfPropNames, propValueMatrix, convertValues=1): state = makeTItemsState(listOfPropNames, propValueMatrix, convertValues) return(makeTItemsACState_Helper(ACList, state)) # Take a list of cookies, a list of property names, and a matrix # of property values (one row for the values of one item, where the columns are # headed by the property names). Return a TItemsCookieState. def makeTItemsCookieState(cookieList, listOfPropNames, propValueMatrix, convertValues=1): cookieList = convertListToAnys(cookieList) state = makeTItemsState(listOfPropNames, propValueMatrix, convertValues) return(makeTItemsCookieState_Helper(cookieList, state)) # Like makeTItemsCookieState, but don't convert the cookies to ANYs. (This should only # be used when the cookies are already of type ANY): def makeTItemsAnyCookiesState(cookieList, listOfPropNames, propValueMatrix, convertValues=1): state = makeTItemsState(listOfPropNames, propValueMatrix, convertValues) return(makeTItemsCookieState_Helper(cookieList, state)) def makeTItemsState(listOfPropNames, matrix, convertValues=1): if convertValues: matrix = convertMatrixToAnys(matrix) return({'aNames': listOfPropNames, 'anItemsState': matrix}) def makeTItemsACState_Helper(accessCapabilitiesList, itemsState): return({'aACs': accessCapabilitiesList, 'aState': itemsState}) def makeTItemsCookieState_Helper(cookieList, itemsState): return({'aClientCookies': cookieList, 'aStates': itemsState}) # Given an item, return a TItemsState that only has this item: def getItemState(item, convertValues=1): propNames = item.keys() valueRow = [] for prop in propNames: valueRow.append(item.get_property_value_no_cnv(prop)) return(makeTItemsState(propNames, [valueRow], convertValues)) ###################################################### # # DLIOP Extractors: # ###################################################### # Given a TItemsACState, return a matrix of the item property values converted # to Python types: def getPythonValueMatrixFromItemsACState(itemsACState): matrix = getValueMatrixFromItemsACState(itemsACState) pythonMatrix = convertMatrixFromAnys(matrix) return(pythonMatrix) def getPythonValueMatrixFromItemsState(itemsState): matrix = getValueMatrixFromItemsState(itemsState) pythonMatrix = convertMatrixFromAnys(matrix) return(pythonMatrix) # Given a TItemsACState, return a matrix of the item property values # as ILU ANYs: def getValueMatrixFromItemsACState(itemsACState): return(itemsACState['aState']['anItemsState']) # Given a TItemsACState, return the property names: def getPropNamesFromItemsACState(itemsACState): return(itemsACState['aState']['aNames']) # Given a TItemsACState, return the access capabilities: def getACsFromItemsACState(itemsACState): return(itemsACState['aACs']) # Given a TItemsCookieState: return matrix of prop values converted to Python: def getPythonValueMatrixFromItemsCookieState(itemsCookieState): matrix = getValueMatrixFromItemsCookieState(itemsCookieState) pythonMatrix = convertMatrixFromAnys(matrix) return(pythonMatrix) def getValueMatrixFromItemsCookieState(itemsCookieState): return(itemsCookieState['aStates']['anItemsState']) # Given an TItemsCookieState, return the cookies: def getCookiesFromTItemsCookieState(itemsCookieState): return(convertListFromAnys(itemsCookieState['aClientCookies'])) # Given an TItemsCookieState, return the property names: def getPropNamesFromTItemsCookieState(itemsCookieState): return(itemsCookieState['aStates']['aNames']) # Given a TItemsState, return the property name list: def getPropNamesFromItemsState(itemsState): return(itemsState['aNames']) # Given a TItemsState, return the value matrix: def getValueMatrixFromItemsState(itemsState): return(itemsState['anItemsState']) # Pull cookie out of an Access option: def getCookieFromAccessOption(AO): return(AO['aCookie']) # Pull destination out of an Access option: def getDestinationFromAccessOption(AO): return(AO['aTarget']) # Pull items class from Access option: def getItemClassFromAccessOption(AO): return(AO['anItemClass']) ###################################################### # # Value conversions: # ###################################################### # Given a list of lists: convert all the values in that matrix into ANYs. # Return a new matrix def convertMatrixToAnys(matrix): newMatrix = [] for rowIndex in range(len(matrix)): newRow = [] for colIndex in range(len(matrix[rowIndex])): newRow.append(any.OutputAny(matrix[rowIndex][colIndex])) newMatrix.append(newRow) return(newMatrix) # Given a list of lists with values of type ANY: convert all the values in that # matrix into regular Python values. This is done in place!: def convertMatrixFromAnys(matrix): newMatrix = [] for rowIndex in range(len(matrix)): newRow = [] for colIndex in range(len(matrix[rowIndex])): newRow.append(any.InputAny(matrix[rowIndex][colIndex])) newMatrix.append(newRow) return(newMatrix) # Given a list: convert all the values in that list into ANYs. # Return a new list def convertListToAnys(list): newList = [] for element in list: newList.append(any.OutputAny(element)) return(newList) # Given a list of ANYs: convert all the values in that list into Python values. # Return a new list def convertListFromAnys(list): newList = [] for element in list: newList.append(any.InputAny(element)) return(newList) def convertToAny(value): return(any.OutputAny(value)) def convertFromAny(value): return(any.InputAny(value))