118
118
from palace .manager .sqlalchemy .util import get_one
119
119
from palace .manager .util import base64
120
120
from palace .manager .util .datetime_helpers import utc_now
121
- from palace .manager .util .http .async_http import AsyncClient
122
121
from palace .manager .util .http .exception import BadResponseException
123
122
from palace .manager .util .http .http import HTTP , RequestKwargs
124
123
@@ -613,8 +612,11 @@ def _get_book_list_page(
613
612
availability_queue = extractor_class .availability_link_list (content_dict )
614
613
return availability_queue , next_link
615
614
616
- def _get_headers (self , auth_token : str ) -> dict [str , str ]:
617
- return {"Authorization" : f"Bearer { auth_token } " , "User-Agent" : "Palace" }
615
+ def _get_headers (self , auth_token : str | None ) -> dict [str , str ]:
616
+ if auth_token :
617
+ return {"Authorization" : f"Bearer { auth_token } " , "User-Agent" : "Palace" }
618
+ else :
619
+ return {}
618
620
619
621
def book_info_initial_endpoint (
620
622
self ,
@@ -640,7 +642,7 @@ def book_info_initial_endpoint(
640
642
limit = str (min (page_size , self .PAGE_SIZE_LIMIT )),
641
643
collection_token = self .collection_token ,
642
644
)
643
- endpoint : str | None = _make_link_safe (book_info_initial_endpoint )
645
+ endpoint : str = _make_link_safe (book_info_initial_endpoint )
644
646
645
647
return BookInfoEndpoint (endpoint )
646
648
@@ -663,12 +665,11 @@ async def fetch_book_info_list(
663
665
"""
664
666
665
667
async with self .create_async_client (connections ) as client :
666
-
667
668
base_url = self .endpoint (self .HOST_ENDPOINT_BASE )
668
669
client .headers .update (self ._get_headers (self ._client_oauth_token ))
669
670
client .base_url = URL (base_url )
670
671
urls : deque [str ] = deque ()
671
- pending_requests : list [asyncio .Task [Response ]] = []
672
+ pending_requests : list [asyncio .Task [httpx . _models . Response ]] = []
672
673
books : dict [str , Any ] = {}
673
674
retried_requests : defaultdict [str , int ] = defaultdict (int )
674
675
extractor_class = extractor_class or OverdriveRepresentationExtractor
@@ -689,12 +690,13 @@ async def fetch_book_info_list(
689
690
for req in done :
690
691
try :
691
692
response = await req
693
+ response .raise_for_status ()
692
694
693
695
if not next :
694
696
next_url = extractor_class .link (
695
- response .raise_for_status (). json (), rel_to_follow
697
+ response .json (), rel_to_follow
696
698
)
697
- next = BookInfoEndpoint (next_url )
699
+ next = BookInfoEndpoint (next_url ) if next_url else None
698
700
699
701
self ._process_request (
700
702
response ,
@@ -728,7 +730,7 @@ async def fetch_book_info_list(
728
730
729
731
return list (books .values ()), next
730
732
731
- def create_async_client (self , connections ) :
733
+ def create_async_client (self , connections : int = 5 ) -> httpx . AsyncClient :
732
734
return httpx .AsyncClient (
733
735
timeout = Timeout (20.0 , pool = None ),
734
736
limits = Limits (
@@ -740,9 +742,9 @@ def create_async_client(self, connections):
740
742
741
743
def _make_request (
742
744
self ,
743
- client : AsyncClient ,
745
+ client : httpx . AsyncClient ,
744
746
urls : deque [str ] | str ,
745
- pending_requests : list [asyncio .Task [Response ]],
747
+ pending_requests : list [asyncio .Task [httpx . _models . Response ]],
746
748
) -> None :
747
749
if isinstance (urls , str ):
748
750
url = urls
@@ -754,7 +756,7 @@ def _make_request(
754
756
755
757
def _process_request (
756
758
self ,
757
- response : Response ,
759
+ response : httpx . _models . Response ,
758
760
request_metadata : bool ,
759
761
request_availability : bool ,
760
762
base_url : str ,
0 commit comments