MCPcopy
hub / github.com/fluentpython/example-code-2e / download_one

Function download_one

20-executors/getflags/flags2_sequential.py:38–56  ·  view source on GitHub ↗
(cc: str, base_url: str, verbose: bool = False)

Source from the content-addressed store, hash-verified

36 return resp.content
37
38def download_one(cc: str, base_url: str, verbose: bool = False) -> DownloadStatus:
39 try:
40 image = get_flag(base_url, cc)
41 except httpx.HTTPStatusError as exc: # <4>
42 res = exc.response
43 if res.status_code == HTTPStatus.NOT_FOUND:
44 status = DownloadStatus.NOT_FOUND # <5>
45 msg = f'not found: {res.url}'
46 else:
47 raise # <6>
48 else:
49 save_flag(image, f'{cc}.gif')
50 status = DownloadStatus.OK
51 msg = 'OK'
52
53 if verbose: # <7>
54 print(cc, msg)
55
56 return status
57# end::FLAGS2_BASIC_HTTP_FUNCTIONS[]
58
59# tag::FLAGS2_DOWNLOAD_MANY_SEQUENTIAL[]

Callers 1

download_manyFunction · 0.70

Calls 2

save_flagFunction · 0.90
get_flagFunction · 0.70

Tested by

no test coverage detected