def soap_GetVariableInfo(self, ps): """ implementation of the "GetVariableInfo" operation """ try: rsp = WaterOneFlow.soap_GetVariableInfo(self,ps) request = self.request variableCodeArray = map(str, request.get_element_variable().split(":")) #if pass in empty string, show info of all variables variablesNode = variables() #for the variable list variableList = [] if variableCodeArray == [""]: for key in variable_Dictionary.keys(): #notice here the protocol of function generateVariableTypeNodeString variableList.append(generateVariableTypeNodeString(key,variable_Dictionary[key])) elif not variableCodeArray[0].upper()=="CBI" or not variable_Dictionary.has_key(variableCodeArray[1]) \ or len(variableCodeArray) != 2: fault = Fault(Fault.Client, "Illegal variableCode", actor="variableCode", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray)) raise fault elif variable_Dictionary.has_key(variableCodeArray[1]): variableList.append(generateVariableTypeNodeString(variableCodeArray[1],variable_Dictionary[variableCodeArray[1]])) #here, to decide if queryInfo required variablesNode.set_variable(variableList) variableResponseNode = VariablesResponseType() variableResponseNode.set_variables(variablesNode) #actual xml string variableResponseString = cStringIO.StringIO() # variableResponseNode.export(variableResponseString, 0, \ namespacedef_=' '.join(['xmlns:gml="http://www.opengis.net/gml"', 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', 'xmlns:xlink="http://www.w3.org/1999/xlink"', 'xmlns:wtr="http://www.cuahsi.org/waterML/"', 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"', 'xmlns="http://www.cuahsi.org/waterML/1.0/"'])) rsp.set_element_GetVariableInfoResult(variableResponseString.getvalue()) #here, how to generate a fault!!! except Exception, e: import traceback traceback.print_exc(file=sys.stdout) if isinstance(e,Fault): detail = None if e.detail is not None: detail = Detail() detail.any = e.detail rsp = FaultType(e.code, e.string, e.actor, detail)
def soap_GetVariableInfoObject(self, ps): """ implementation of the "GetVariableInfo" operation """ try: #this code is just for deploying on apache #httpReq = kw['request'] rsp = WaterOneFlow.soap_GetVariableInfoObject(self,ps) request = self.request variableCodeArray = map(str, request.get_element_variable().split(":")) variableResponseNode=rsp.new_variablesResponse() variablesNode = variableResponseNode.new_variables() variableList = [] if variableCodeArray == [""]: for key in variable_Dictionary.keys(): variableNode = variablesNode.new_variable() variableList.append(generateVariableTypeNode(variableNode,key,variable_Dictionary[key])) elif not variableCodeArray[0].upper()=="CBI" or not variable_Dictionary.has_key(variableCodeArray[1]) \ or len(variableCodeArray) != 2: fault = Fault(Fault.Client, "Illegal variableCode", actor="variableCode", detail="variable code \"%s\" is illegal/not found" % ":".join(variableCodeArray)) raise fault elif variable_Dictionary.has_key(variableCodeArray[1]): variableNode = variablesNode.new_variable() variableList.append(generateVariableTypeNode(variableNode,variableCodeArray[1],variable_Dictionary[variableCodeArray[1]])) variablesNode.set_element_variable(variableList) variableResponseNode.set_element_variables(variablesNode) rsp.set_element_variablesResponse(variableResponseNode) #here, how to generate a fault!!! except Exception, e: import traceback traceback.print_exc(file=sys.stdout) if isinstance(e,Fault): detail = None if e.detail is not None: detail = Detail() detail.any = e.detail rsp = FaultType(e.code, e.string, e.actor, detail)