@@ -165,6 +165,23 @@ def __init__(self, urn: str = None, contextId: str = None, contextSearchId: str
165165 self ._states = {}
166166 self ._objects = {}
167167
168+ def toDict (self ):
169+ ret = {
170+ "urn" : self ._urn ,
171+ "contextId" : self ._contextId ,
172+ "estimate" : self ._estimate ,
173+ "estimatedCost" : self ._estimatedCost ,
174+ "scenarios" : list (self ._scenarios ), # ensure it's a list
175+ "states" : list (self ._states ),
176+ "objects" : list (self ._objects )
177+ }
178+
179+ # Include searchContextId if present
180+ if getattr (self , "searchContextId" , None ):
181+ ret ["contextSearchId" ] = self .searchContextId
182+
183+ return ret
184+
168185 def toJson (self ):
169186 es = str (self ._estimate ).lower ()
170187
@@ -263,17 +280,28 @@ def __init__(self) -> None:
263280 self ._estimate = False
264281 self ._estimatedCost = - 1
265282
283+ def toDict (self ):
284+ return {
285+ "urn" : self ._urn ,
286+ "geometry" : self ._geometry ,
287+ "contextType" : self ._contextType ,
288+ "observables" : [str (o ) for o in self ._observables ],
289+ "scenarios" : [str (s ) for s in self ._scenarios ],
290+ "estimate" : self ._estimate ,
291+ "estimatedCost" : self ._estimatedCost
292+ }
293+
266294 def toJson (self ):
267295 es = str (self ._estimate ).lower ()
268-
269296 obs = [str (o ) for o in self ._observables ]
270297 obs = str (obs ).replace ("'" , "\" " )
271298 scen = [str (s ) for s in self ._scenarios ]
272299 scen = str (scen ).replace ("'" , "\" " )
300+ urn = "null" if self ._urn is None else self ._urn
273301
274- ret = """{{"geometry":"{0}","contextType":"{1}","observables":{2},"scenarios":{3},"estimate":{4},"estimatedCost":{5}}}"""
302+ ret = """{{"geometry":"{0}","contextType":"{1}","observables":{2},"scenarios":{3},"estimate":{4},"estimatedCost":{5}, "urn": {6} }}"""
275303 ret = ret .format (self ._geometry , self ._contextType ,
276- obs , scen , es , self ._estimatedCost )
304+ obs , scen , es , self ._estimatedCost , urn )
277305
278306 ret = ret .encode ('utf-8' ).decode ('unicode-escape' )
279307 return ret
0 commit comments