Skip to content

Commit 8bbfee0

Browse files
committed
suggested change in each class and param
1 parent 638008b commit 8bbfee0

File tree

1 file changed

+86
-20
lines changed

1 file changed

+86
-20
lines changed

py/selenium/webdriver/common/bidi/browsing_context.py

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,23 @@ def from_json(cls, json: dict) -> "NavigationInfo":
6767
-------
6868
NavigationInfo: A new instance of NavigationInfo.
6969
"""
70-
return cls(
71-
context=str(json.get("context", "")),
72-
navigation=json.get("navigation"),
73-
timestamp=int(json.get("timestamp", 0)),
74-
url=str(json.get("url", "")),
75-
)
70+
context = json.get("context")
71+
if context is None or not isinstance(context, str):
72+
raise ValueError("context is required and must be a string")
73+
74+
navigation = json.get("navigation")
75+
if navigation is not None and not isinstance(navigation, str):
76+
raise ValueError("navigation must be a string")
77+
78+
timestamp = json.get("timestamp")
79+
if timestamp is None or not isinstance(timestamp, int):
80+
raise ValueError("timestamp is required and must be an integer")
81+
82+
url = json.get("url")
83+
if url is None or not isinstance(url, str):
84+
raise ValueError("url is required and must be a string")
85+
86+
return cls(context, navigation, timestamp, url)
7687

7788

7889
class BrowsingContextInfo:
@@ -117,10 +128,17 @@ def from_json(cls, json: dict) -> "BrowsingContextInfo":
117128
children.append(BrowsingContextInfo.from_json(child))
118129
else:
119130
warnings.warn(f"Unexpected child type in browsing context: {type(child)}")
131+
context = json.get("context")
132+
if context is None or not isinstance(context, str):
133+
raise ValueError("context is required and must be a string")
134+
135+
url = json.get("url")
136+
if url is None or not isinstance(url, str):
137+
raise ValueError("url is required and must be a string")
120138

121139
return cls(
122-
context=str(json.get("context", "")),
123-
url=str(json.get("url", "")),
140+
context=context,
141+
url=url,
124142
children=children,
125143
parent=json.get("parent"),
126144
user_context=json.get("userContext"),
@@ -155,12 +173,32 @@ def from_json(cls, json: dict) -> "DownloadWillBeginParams":
155173
-------
156174
DownloadWillBeginParams: A new instance of DownloadWillBeginParams.
157175
"""
176+
context = json.get("context")
177+
if context is None or not isinstance(context, str):
178+
raise ValueError("context is required and must be a string")
179+
180+
navigation = json.get("navigation")
181+
if navigation is not None and not isinstance(navigation, str):
182+
raise ValueError("navigation must be a string")
183+
184+
timestamp = json.get("timestamp")
185+
if timestamp is None or not isinstance(timestamp, int):
186+
raise ValueError("timestamp is required and must be an integer")
187+
188+
url = json.get("url")
189+
if url is None or not isinstance(url, str):
190+
raise ValueError("url is required and must be a string")
191+
192+
suggested_filename = json.get("suggestedFilename")
193+
if suggested_filename is None or not isinstance(suggested_filename, str):
194+
raise ValueError("suggestedFilename is required and must be a string")
195+
158196
return cls(
159-
context=str(json.get("context", "")),
160-
navigation=json.get("navigation"),
161-
timestamp=int(json.get("timestamp", 0)),
162-
url=str(json.get("url", "")),
163-
suggested_filename=str(json.get("suggestedFilename", "")),
197+
context=context,
198+
navigation=navigation,
199+
timestamp=timestamp,
200+
url=url,
201+
suggested_filename=suggested_filename,
164202
)
165203

166204

@@ -249,11 +287,27 @@ def from_json(cls, json: dict) -> "UserPromptClosedParams":
249287
-------
250288
UserPromptClosedParams: A new instance of UserPromptClosedParams.
251289
"""
290+
context = json.get("context")
291+
if context is None or not isinstance(context, str):
292+
raise ValueError("context is required and must be a string")
293+
294+
accepted = json.get("accepted")
295+
if accepted is None or not isinstance(accepted, bool):
296+
raise ValueError("accepted is required and must be a boolean")
297+
298+
type_value = json.get("type")
299+
if type_value is None or not isinstance(type_value, str):
300+
raise ValueError("type is required and must be a string")
301+
302+
user_text = json.get("userText")
303+
if user_text is not None and not isinstance(user_text, str):
304+
raise ValueError("userText must be a string if provided")
305+
252306
return cls(
253-
context=str(json.get("context", "")),
254-
accepted=bool(json.get("accepted", False)),
255-
type=str(json.get("type", "")),
256-
user_text=str(json.get("userText", "")),
307+
context=context,
308+
accepted=accepted,
309+
type=type_value,
310+
user_text=user_text,
257311
)
258312

259313

@@ -280,9 +334,17 @@ def from_json(cls, json: dict) -> "HistoryUpdatedParams":
280334
-------
281335
HistoryUpdatedParams: A new instance of HistoryUpdatedParams.
282336
"""
337+
context = json.get("context")
338+
if context is None or not isinstance(context, str):
339+
raise ValueError("context is required and must be a string")
340+
341+
url = json.get("url")
342+
if url is None or not isinstance(url, str):
343+
raise ValueError("url is required and must be a string")
344+
283345
return cls(
284-
context=str(json.get("context", "")),
285-
url=str(json.get("url", "")),
346+
context=context,
347+
url=url,
286348
)
287349

288350

@@ -305,7 +367,11 @@ def from_json(cls, json: dict) -> "BrowsingContextEvent":
305367
-------
306368
BrowsingContextEvent: A new instance of BrowsingContextEvent.
307369
"""
308-
return cls(event_class=str(json.get("event_class", "")), **json)
370+
event_class = json.get("event_class")
371+
if event_class is None or not isinstance(event_class, str):
372+
raise ValueError("event_class is required and must be a string")
373+
374+
return cls(event_class=event_class, **json)
309375

310376

311377
class BrowsingContext:

0 commit comments

Comments
 (0)