MCPcopy Index your code
hub / github.com/microsoft/playwright-python / parse_value

Function parse_value

playwright/_impl/_js_handle.py:213–328  ·  view source on GitHub ↗
(value: Any, refs: Optional[Dict[int, Any]] = None)

Source from the content-addressed store, hash-verified

211
212
213def parse_value(value: Any, refs: Optional[Dict[int, Any]] = None) -> Any:
214 if refs is None:
215 refs = {}
216 if value is None:
217 return None
218 if isinstance(value, dict):
219 if "ref" in value:
220 return refs[value["ref"]]
221
222 if "v" in value:
223 v = value["v"]
224 if v == "Infinity":
225 return float("inf")
226 if v == "-Infinity":
227 return float("-inf")
228 if v == "-0":
229 return float("-0")
230 if v == "NaN":
231 return float("nan")
232 if v == "undefined":
233 return None
234 if v == "null":
235 return None
236 return v
237
238 if "u" in value:
239 return urlparse(value["u"])
240
241 if "bi" in value:
242 return int(value["bi"])
243
244 if "e" in value:
245 error = Error(value["e"]["m"])
246 error._name = value["e"]["n"]
247 error._stack = value["e"]["s"]
248 return error
249
250 if "a" in value:
251 a: List = []
252 refs[value["id"]] = a
253 for e in value["a"]:
254 a.append(parse_value(e, refs))
255 return a
256
257 if "d" in value:
258 # Node.js Date objects are always in UTC.
259 return datetime.datetime.strptime(
260 value["d"], "%Y-%m-%dT%H:%M:%S.%fZ"
261 ).replace(tzinfo=datetime.timezone.utc)
262
263 if "o" in value:
264 o: Dict = {}
265 refs[value["id"]] = o
266 for e in value["o"]:
267 o[e["k"]] = parse_value(e["v"], refs)
268 return o
269
270 if "n" in value:

Callers 3

_expect_implMethod · 0.90
_expectMethod · 0.90
parse_resultFunction · 0.85

Calls 2

ErrorClass · 0.90
appendMethod · 0.80

Tested by

no test coverage detected