|
1 | | -import warnings |
2 | | - |
3 | 1 | from redash import settings |
4 | 2 |
|
5 | | -with warnings.catch_warnings(): |
6 | | - # Supress advocate warning below |
7 | | - # /usr/local/lib/python3.13/site-packages/advocate/api.py:102: SyntaxWarning: invalid escape sequence '\*' |
8 | | - # server-1 | :param \*\*kwargs: Optional arguments that ``request`` takes. |
9 | | - warnings.filterwarnings("ignore", category=SyntaxWarning, module=r".*advocate.*") |
| 3 | +if settings.ENFORCE_PRIVATE_ADDRESS_BLOCK: |
| 4 | + try: |
| 5 | + import champion as requests_or_champion |
| 6 | + from champion.exceptions import ( |
| 7 | + UnacceptableAddressException, # noqa: F401, E402 |
| 8 | + ) |
| 9 | + except ImportError as e: |
| 10 | + raise RuntimeError( |
| 11 | + "ENFORCE_PRIVATE_ADDRESS_BLOCK requires the champion package. " |
| 12 | + "Install it in your environment (e.g. pip install " |
| 13 | + "git+https://github.com/Gee19/champion.git)." |
| 14 | + ) from e |
| 15 | +else: |
| 16 | + import requests as requests_or_champion |
10 | 17 |
|
11 | | - from advocate.exceptions import UnacceptableAddressException # noqa: F401, E402 |
| 18 | + class UnacceptableAddressException(Exception): |
| 19 | + """Only raised when champion is used (ENFORCE_PRIVATE_ADDRESS_BLOCK).""" |
12 | 20 |
|
13 | | - if settings.ENFORCE_PRIVATE_ADDRESS_BLOCK: |
14 | | - import advocate as requests_or_advocate |
15 | | - else: |
16 | | - import requests as requests_or_advocate |
| 21 | + pass |
17 | 22 |
|
18 | 23 |
|
19 | | -class ConfiguredSession(requests_or_advocate.Session): |
| 24 | +class ConfiguredSession(requests_or_champion.Session): |
20 | 25 | def request(self, *args, **kwargs): |
21 | 26 | if not settings.REQUESTS_ALLOW_REDIRECTS: |
22 | 27 | kwargs.update({"allow_redirects": False}) |
|
0 commit comments