diff --git a/caldav/async_davclient.py b/caldav/async_davclient.py index d7630e14..f21e5f88 100644 --- a/caldav/async_davclient.py +++ b/caldav/async_davclient.py @@ -18,43 +18,43 @@ from caldav.calendarobjectresource import CalendarObjectResource, Event, Todo from caldav.collection import Calendar, Principal -# Try httpx first (preferred), fall back to niquests +# Try niquests first (preferred), fall back to httpx _USE_HTTPX = False _USE_NIQUESTS = False _H2_AVAILABLE = False try: - import httpx + import niquests + from niquests import AsyncSession + from niquests.structures import CaseInsensitiveDict - _USE_HTTPX = True - # Check if h2 is available for HTTP/2 support - try: - import h2 # noqa: F401 + _USE_NIQUESTS = True +except ImportError: + pass - _H2_AVAILABLE = True - except ImportError: - pass +if not _USE_NIQUESTS: + try: + import httpx - class _HttpxBearerAuth(httpx.Auth): - """httpx-compatible bearer token auth.""" + _USE_HTTPX = True + # Check if h2 is available for HTTP/2 support + try: + import h2 # noqa: F401 - def __init__(self, password: str) -> None: - self.password = password + _H2_AVAILABLE = True + except ImportError: + pass - def auth_flow(self, request): - request.headers["Authorization"] = f"Bearer {self.password}" - yield request + class _HttpxBearerAuth(httpx.Auth): + """httpx-compatible bearer token auth.""" -except ImportError: - pass + def __init__(self, password: str) -> None: + self.password = password -if not _USE_HTTPX: - try: - import niquests - from niquests import AsyncSession - from niquests.structures import CaseInsensitiveDict + def auth_flow(self, request): + request.headers["Authorization"] = f"Bearer {self.password}" + yield request - _USE_NIQUESTS = True except ImportError: pass