Skip to content

Commit 08f7e24

Browse files
committed
style: refactor target filtering and improve file handler clarity
1 parent 8d76cc9 commit 08f7e24

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

pydoll/browser/chromium/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ async def get_opened_tabs(self) -> list[Tab]:
231231
"""
232232
targets = await self.get_targets()
233233
valid_tab_targets = [
234-
target for target in targets if target['type'] == 'page'
235-
and 'extension' not in target['url']
234+
target
235+
for target in targets
236+
if target['type'] == 'page' and 'extension' not in target['url']
236237
]
237238
return [
238-
Tab(self, self._connection_port, target['targetId']) for target
239-
in reversed(valid_tab_targets)
239+
Tab(self, self._connection_port, target['targetId'])
240+
for target in reversed(valid_tab_targets)
240241
]
241242

242243
async def set_download_path(self, path: str, browser_context_id: Optional[str] = None):

pydoll/browser/tab.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ async def expect_file_chooser(
680680
"""
681681

682682
async def event_handler(event: EventFileChooserOpened):
683-
file_list = files if isinstance(files, list) else [files]
683+
file_list = [str(file) for file in files] if isinstance(files, list) else [str(files)]
684684
await self._execute_command(
685685
DomCommands.set_file_input_files(
686686
files=file_list,
@@ -697,7 +697,11 @@ async def event_handler(event: EventFileChooserOpened):
697697
if self.intercept_file_chooser_dialog_enabled is False:
698698
await self.enable_intercept_file_chooser_dialog()
699699

700-
await self.on(PageEvent.FILE_CHOOSER_OPENED, event_handler, temporary=True)
700+
await self.on(
701+
PageEvent.FILE_CHOOSER_OPENED,
702+
cast(Callable[[dict], Any], event_handler),
703+
temporary=True,
704+
)
701705

702706
yield
703707

pydoll/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class TextExtractor(HTMLParser):
1919
Extracts visible text content from an HTML string, excluding the contents of
2020
tags specified in _skip_tags.
2121
"""
22+
2223
def __init__(self):
2324
super().__init__()
2425
self._parts = []
2526
self._skip = False
26-
self._skip_tags = {"script", "style", "template"}
27+
self._skip_tags = {'script', 'style', 'template'}
2728

2829
def handle_starttag(self, tag, attrs):
2930
"""

0 commit comments

Comments
 (0)