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

Function expand_cc_args

20-executors/getflags/flags2_common.py:67–87  ·  view source on GitHub ↗
(every_cc: bool,
                   all_cc: bool,
                   cc_args: list[str],
                   limit: int)

Source from the content-addressed store, hash-verified

65
66
67def expand_cc_args(every_cc: bool,
68 all_cc: bool,
69 cc_args: list[str],
70 limit: int) -> list[str]:
71 codes: set[str] = set()
72 A_Z = string.ascii_uppercase
73 if every_cc:
74 codes.update(a+b for a in A_Z for b in A_Z)
75 elif all_cc:
76 text = COUNTRY_CODES_FILE.read_text()
77 codes.update(text.split())
78 else:
79 for cc in (c.upper() for c in cc_args):
80 if len(cc) == 1 and cc in A_Z:
81 codes.update(cc + c for c in A_Z)
82 elif len(cc) == 2 and all(c in A_Z for c in cc):
83 codes.add(cc)
84 else:
85 raise ValueError('*** Usage error: each CC argument '
86 'must be A to Z or AA to ZZ.')
87 return sorted(codes)[:limit]
88
89
90def process_args(default_concur_req):

Callers 1

process_argsFunction · 0.85

Calls 2

addMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected