Skip to content

Commit 7b6122e

Browse files
committed
cap21: wip
1 parent db218ed commit 7b6122e

File tree

5 files changed

+252
-113
lines changed

5 files changed

+252
-113
lines changed

code/21-async/domains/asyncio/domaincheck.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from domainlib import multi_probe
77

8-
98
async def main(tld: str) -> None:
109
tld = tld.strip('.')
1110
names = (kw for kw in kwlist if len(kw) <= 4) # <1>
@@ -16,7 +15,6 @@ async def main(tld: str) -> None:
1615
indent = '' if found else '\t\t' # <5>
1716
print(f'{indent}{domain}')
1817

19-
2018
if __name__ == '__main__':
2119
if len(sys.argv) == 2:
2220
asyncio.run(main(sys.argv[1])) # <6>

code/21-async/domains/asyncio/domainlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ async def probe(domain: str, loop: OptionalLoop = None) -> Result: # <3>
2222
return Result(domain, True)
2323

2424

25-
async def multi_probe(domains: Iterable[str]) -> AsyncIterator[Result]: # <4>
25+
async def multi_probe(
26+
domains: Iterable[str]) -> AsyncIterator[Result]: # <4>
2627
loop = asyncio.get_running_loop()
2728
coros = [probe(domain, loop) for domain in domains] # <5>
2829
for coro in asyncio.as_completed(coros): # <6>
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#!/usr/bin/env python3
2-
from curio import run, TaskGroup
3-
import curio.socket as socket
42
from keyword import kwlist
3+
import curio
54

65
MAX_KEYWORD_LEN = 4
76

8-
97
async def probe(domain: str) -> tuple[str, bool]: # <1>
108
try:
11-
await socket.getaddrinfo(domain, None) # <2>
12-
except socket.gaierror:
9+
await curio.socket.getaddrinfo(domain, None) # <2>
10+
except curio.socket.gaierror:
1311
return (domain, False)
1412
return (domain, True)
1513

1614
async def main() -> None:
1715
names = (kw for kw in kwlist if len(kw) <= MAX_KEYWORD_LEN)
1816
domains = (f'{name}.dev'.lower() for name in names)
19-
async with TaskGroup() as group: # <3>
17+
async with curio.TaskGroup() as group: # <3>
2018
for domain in domains:
2119
await group.spawn(probe, domain) # <4>
2220
async for task in group: # <5>
@@ -25,4 +23,4 @@ async def main() -> None:
2523
print(f'{mark} {domain}')
2624

2725
if __name__ == '__main__':
28-
run(main()) # <6>
26+
curio.run(main()) # <6>

links/FPY.LI.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,3 +1477,4 @@ RedirectTemp /c4 https://docs.python.org/pt-br/3/library/functions.html#type
14771477

14781478
# cap21: appended 2026-02-06
14791479
RedirectTemp /c5 https://fastapi.tiangolo.com/pt/project-generation/
1480+
RedirectTemp /c6 https://pypi.org/project/curio-compat/

0 commit comments

Comments
 (0)