|
18 | 18 | from caldav.calendarobjectresource import CalendarObjectResource, Event, Todo |
19 | 19 | from caldav.collection import Calendar, Principal |
20 | 20 |
|
21 | | -# Try httpx first (preferred), fall back to niquests |
| 21 | +# Try niquests first (preferred), fall back to httpx |
22 | 22 | _USE_HTTPX = False |
23 | 23 | _USE_NIQUESTS = False |
24 | 24 | _H2_AVAILABLE = False |
25 | 25 |
|
26 | 26 | try: |
27 | | - import httpx |
| 27 | + import niquests |
| 28 | + from niquests import AsyncSession |
| 29 | + from niquests.structures import CaseInsensitiveDict |
28 | 30 |
|
29 | | - _USE_HTTPX = True |
30 | | - # Check if h2 is available for HTTP/2 support |
31 | | - try: |
32 | | - import h2 # noqa: F401 |
| 31 | + _USE_NIQUESTS = True |
| 32 | +except ImportError: |
| 33 | + pass |
33 | 34 |
|
34 | | - _H2_AVAILABLE = True |
35 | | - except ImportError: |
36 | | - pass |
| 35 | +if not _USE_NIQUESTS: |
| 36 | + try: |
| 37 | + import httpx |
37 | 38 |
|
38 | | - class _HttpxBearerAuth(httpx.Auth): |
39 | | - """httpx-compatible bearer token auth.""" |
| 39 | + _USE_HTTPX = True |
| 40 | + # Check if h2 is available for HTTP/2 support |
| 41 | + try: |
| 42 | + import h2 # noqa: F401 |
40 | 43 |
|
41 | | - def __init__(self, password: str) -> None: |
42 | | - self.password = password |
| 44 | + _H2_AVAILABLE = True |
| 45 | + except ImportError: |
| 46 | + pass |
43 | 47 |
|
44 | | - def auth_flow(self, request): |
45 | | - request.headers["Authorization"] = f"Bearer {self.password}" |
46 | | - yield request |
| 48 | + class _HttpxBearerAuth(httpx.Auth): |
| 49 | + """httpx-compatible bearer token auth.""" |
47 | 50 |
|
48 | | -except ImportError: |
49 | | - pass |
| 51 | + def __init__(self, password: str) -> None: |
| 52 | + self.password = password |
50 | 53 |
|
51 | | -if not _USE_HTTPX: |
52 | | - try: |
53 | | - import niquests |
54 | | - from niquests import AsyncSession |
55 | | - from niquests.structures import CaseInsensitiveDict |
| 54 | + def auth_flow(self, request): |
| 55 | + request.headers["Authorization"] = f"Bearer {self.password}" |
| 56 | + yield request |
56 | 57 |
|
57 | | - _USE_NIQUESTS = True |
58 | 58 | except ImportError: |
59 | 59 | pass |
60 | 60 |
|
|
0 commit comments