Extract all consts from the contents found at the given URL. Parameters ---------- url : str URL to fetch the contents from. pattern : re.Pattern, Optional RE compiled pattern for extracting the consts. exclude : frozenset[str], Optional Items to exc
(
url: str, *, pattern: re.Pattern = CONSTS_PATTERN, exclude: frozenset[str] = EXCLUDE
)
| 157 | |
| 158 | |
| 159 | def consts_from_url( |
| 160 | url: str, *, pattern: re.Pattern = CONSTS_PATTERN, exclude: frozenset[str] = EXCLUDE |
| 161 | ) -> frozenset[str]: |
| 162 | """ |
| 163 | Extract all consts from the contents found at the given URL. |
| 164 | |
| 165 | Parameters |
| 166 | ---------- |
| 167 | url : str |
| 168 | URL to fetch the contents from. |
| 169 | pattern : re.Pattern, Optional |
| 170 | RE compiled pattern for extracting the consts. |
| 171 | exclude : frozenset[str], Optional |
| 172 | Items to exclude from the returned value. |
| 173 | |
| 174 | Returns |
| 175 | ------- |
| 176 | frozenset[str] |
| 177 | All constant names at the URL. |
| 178 | """ |
| 179 | try: |
| 180 | with urllib.request.urlopen(url) as f: |
| 181 | contents = f.read().decode() |
| 182 | except urllib.error.HTTPError as err: |
| 183 | err.add_note(url) |
| 184 | raise |
| 185 | |
| 186 | return extract_consts(contents, pattern=pattern, exclude=exclude) |
| 187 | |
| 188 | |
| 189 | def main(): |