Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typing for core fetch_all #1589

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion theHarvester/discovery/bingsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SearchBing:
def __init__(self, word, limit, start) -> None:
self.word = word.replace(" ", "%20")
self.results: tuple[Any, ...] = ()
self.results: list[Any] = []
self.total_results = ""
self.server = "www.bing.com"
self.apiserver = "api.search.live.net"
Expand Down
5 changes: 2 additions & 3 deletions theHarvester/discovery/takeover.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ async def do_take(self) -> None:
http_hosts = [f"http://{host}" for host in self.hosts]
all_hosts = https_hosts + http_hosts
shuffle(all_hosts)
tup_resps = await AsyncFetcher.fetch_all(
resps: list = await AsyncFetcher.fetch_all(
all_hosts, takeover=True, proxy=self.proxy
)
tup_resps = tuple(tup for tup in tup_resps if len(tup[1]) >= 1)
for url, resp in tup_resps:
for url, resp in tuple(resp for resp in resps if len(resp[1]) >= 1):
await self.check(url, resp)
else:
return
Expand Down
20 changes: 7 additions & 13 deletions theHarvester/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ async def fetch_all(
json: bool = False,
takeover: bool = False,
proxy: bool = False,
) -> tuple:
) -> list:
# By default, timeout is 5 minutes; 60 seconds should suffice
timeout = aiohttp.ClientTimeout(total=60)
if len(headers) == 0:
Expand All @@ -449,27 +449,25 @@ async def fetch_all(
headers=headers, timeout=aiohttp.ClientTimeout(total=15)
) as session:
if proxy:
tuples = await asyncio.gather(
return await asyncio.gather(
*[
AsyncFetcher.takeover_fetch(
session, url, proxy=random.choice(cls().proxy_list)
)
for url in urls
]
)
return tuples
else:
tuples = await asyncio.gather(
return await asyncio.gather(
*[AsyncFetcher.takeover_fetch(session, url) for url in urls]
)
return tuples

if len(params) == 0:
async with aiohttp.ClientSession(
headers=headers, timeout=timeout
) as session:
if proxy:
texts = await asyncio.gather(
return await asyncio.gather(
*[
AsyncFetcher.fetch(
session,
Expand All @@ -480,19 +478,17 @@ async def fetch_all(
for url in urls
]
)
return texts
else:
texts = await asyncio.gather(
return await asyncio.gather(
*[AsyncFetcher.fetch(session, url, json=json) for url in urls]
)
return texts
else:
# Indicates the request has certain params
async with aiohttp.ClientSession(
headers=headers, timeout=timeout
) as session:
if proxy:
texts = await asyncio.gather(
return await asyncio.gather(
*[
AsyncFetcher.fetch(
session,
Expand All @@ -504,12 +500,10 @@ async def fetch_all(
for url in urls
]
)
return texts
else:
texts = await asyncio.gather(
return await asyncio.gather(
*[
AsyncFetcher.fetch(session, url, params, json)
for url in urls
]
)
return texts
Loading