@@ -477,6 +477,32 @@ def fetch(self, url: str) -> tuple[int | None, str, str]:
477477 self .retry_after_s = parse_retry_after (retry_after )
478478 return status , final , body
479479
480+ def fetch_post (self , url : str , form : dict [str , str ]) -> tuple [int | None , str , str ]:
481+ gap = max (self .sleep_s , MIN_SLEEP_S )
482+ if self .requests :
483+ wait = gap - (time .monotonic () - self ._last )
484+ if wait > 0 :
485+ time .sleep (wait )
486+ self .requests += 1
487+ self ._last = time .monotonic ()
488+ data = urlencode (form ).encode ()
489+ request = Request (
490+ url ,
491+ data = data ,
492+ headers = {"User-Agent" : USER_AGENT , "Content-Type" : "application/x-www-form-urlencoded" },
493+ )
494+ try :
495+ with urlopen (request , timeout = 60 ) as response :
496+ return (
497+ int (getattr (response , "status" , None ) or response .getcode ()),
498+ response .geturl (),
499+ response .read ().decode ("utf-8" , "replace" ),
500+ )
501+ except HTTPError as exc :
502+ return int (exc .code ), exc .geturl (), exc .read ().decode ("utf-8" , "replace" )
503+ except URLError :
504+ return None , url , ""
505+
480506
481507def _outside_repo (path : Path , repo : Path ) -> None :
482508 resolved = path .resolve ()
@@ -755,36 +781,6 @@ def search(self, name: str) -> list[Candidate]:
755781 return disambiguate (name , found )
756782
757783
758- def _fetch_post (self : PoliteClient , url : str , form : dict [str , str ]) -> tuple [int | None , str , str ]:
759- gap = max (self .sleep_s , MIN_SLEEP_S )
760- if self .requests :
761- wait = gap - (time .monotonic () - self ._last )
762- if wait > 0 :
763- time .sleep (wait )
764- self .requests += 1
765- self ._last = time .monotonic ()
766- data = urlencode (form ).encode ()
767- request = Request (
768- url ,
769- data = data ,
770- headers = {"User-Agent" : USER_AGENT , "Content-Type" : "application/x-www-form-urlencoded" },
771- )
772- try :
773- with urlopen (request , timeout = 60 ) as response :
774- return (
775- int (getattr (response , "status" , None ) or response .getcode ()),
776- response .geturl (),
777- response .read ().decode ("utf-8" , "replace" ),
778- )
779- except HTTPError as exc :
780- return int (exc .code ), exc .geturl (), exc .read ().decode ("utf-8" , "replace" )
781- except URLError :
782- return None , url , ""
783-
784-
785- PoliteClient .fetch_post = _fetch_post # type: ignore[attr-defined]
786-
787-
788784def evaluate_record (record : dict [str , Any ], fetcher : PhoneDbFetcher , fetch : FetchFn ) -> GateResult :
789785 name = record .get ("name" )
790786 if not isinstance (name , str ) or not name .strip ():
0 commit comments