Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions caldav/async_davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading