def convertResponseToJson(self, jsonCandidate): try: def raiseException(): guid = uuid.uuid4() logging.error("%s of type %s is not valid json. guid = %s", jsonCandidate, type(jsonCandidate), guid) raise Exceptions.SubscribableWebObjectsException("result was not valid json. Guid = %s" % guid) if jsonCandidate is None: return jsonCandidate if isinstance(jsonCandidate, (int,str,unicode,float,bool,long)): return jsonCandidate if isinstance(jsonCandidate, (list, tuple)): return [self.convertResponseToJson(r) for r in jsonCandidate] if isinstance(jsonCandidate, dict): newDict = {} for k,v in jsonCandidate.iteritems(): if not isinstance(k,str): raiseException() newDict[k] = self.convertResponseToJson(v) return newDict objDefPopulated = False try: if ComputedGraph.isLocation(jsonCandidate): if jsonCandidate in self.objectToIdCache_: objDef = { 'objectId_': self.lookupObjectId(jsonCandidate) } else: objDef = { "objectId_": self.lookupObjectId(jsonCandidate), "objectDefinition_": { 'type': AllObjectClassesToExpose.typenameFromType( ComputedGraph.getLocationTypeFromLocation(jsonCandidate) ), 'args': jsonCandidate.__reduce__()[1][0] } } objDefPopulated = True else: objDef = jsonCandidate.objectDefinition_ objDefPopulated = True except AttributeError: objDefPopulated = False if objDefPopulated: return self.convertResponseToJson(objDef) raiseException() except: logging.error("%s of type %s is not valid json.", jsonCandidate, type(jsonCandidate)) raise
def convertResponseToJson(self, jsonCandidate): try: def raiseException(): guid = uuid.uuid4() logging.error("%s of type %s is not valid json. guid = %s", jsonCandidate, type(jsonCandidate), guid) raise Exceptions.SubscribableWebObjectsException("result was not valid json. Guid = %s" % guid) if jsonCandidate is None: return jsonCandidate if isinstance(jsonCandidate, (int, str, unicode, float, bool, long)): return jsonCandidate if isinstance(jsonCandidate, (list, tuple)): return [self.convertResponseToJson(r) for r in jsonCandidate] if isinstance(jsonCandidate, dict): newDict = {} for k, v in jsonCandidate.iteritems(): if not isinstance(k, str): raiseException() newDict[k] = self.convertResponseToJson(v) return newDict objDefPopulated = False try: if ComputedGraph.isLocation(jsonCandidate): if jsonCandidate in self.objectToIdCache_: objDef = {"objectId_": self.lookupObjectId(jsonCandidate)} else: objDef = { "objectId_": self.lookupObjectId(jsonCandidate), "objectDefinition_": { "type": AllObjectClassesToExpose.typenameFromType( ComputedGraph.getLocationTypeFromLocation(jsonCandidate) ), "args": jsonCandidate.__reduce__()[1][0], }, } objDefPopulated = True else: objDef = jsonCandidate.objectDefinition_ objDefPopulated = True except AttributeError: objDefPopulated = False if objDefPopulated: return self.convertResponseToJson(objDef) raiseException() except: logging.error("%s of type %s is not valid json.", jsonCandidate, type(jsonCandidate)) raise
def unfinishedDependentCodeLocationsAsJson(self): res = [] for cv in self.rootComputedValueDependencies: if not cv.isFinished: #each computed value we depend on might be a visualize. If so, we want #the actual script computation (if available) cv = cv.unwrapVisualizable cv = cv.unwrapMember #only some ComputedValue objects have this property loc = cv.codeLocationDefinitionAsJson if loc is not None: res.append(loc) else: res.append(str(ComputedGraph.getLocationTypeFromLocation(cv))) return tuple(res)
def getObjectClass(o): if ComputedGraph.isLocation(o): return ComputedGraph.getLocationTypeFromLocation(o) return o.__class__