+
    i                     D   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
Ht ^ RIHt ^t]P                  P!                  RR4      P#                  4       R9   tR R lt^tRtR	t ! R
 R]4      tRR]]R3R R lltRR R lltRR R lltRR R llt]]3R R lltR# )z2HTTP utilities for last30days skill (stdlib only).N)AnyDictOptional)	urlencodeLAST30DAYS_DEBUG c                $    V ^8  d   QhR\         /# )   msg)str)formats   "P/Users/bowang/.openclaw/workspace/skills/last30days-official/scripts/lib/http.py__annotate__r      s      S     c                    \         '       dD   \        P                  P                  RV  R24       \        P                  P	                  4        R# R# )zLog debug message to stderr.z[DEBUG] 
N)DEBUGsysstderrwriteflush)r
   s   &r   logr      s7    u

8C5+,

 r   g       @z&last30days-skill/2.1 (Assistant Skill)c                   F   a a ] tR t^t oRtRV3R lV 3R llltRtVtV ;t# )	HTTPErrorz$HTTP request error with status code.c                L   < V ^8  d   QhRS[ RS[S[,          RS[S[ ,          /# )r	   messagestatus_codebody)r   r   int)r   __classdict__s   "r   r   HTTPError.__annotate__   s+       (3- hWZm r   c                >   < \         SV `  V4       W n        W0n        R # N)super__init__r   r   )selfr   r   r   	__class__s   &&&&r   r$   HTTPError.__init__   s    !&	r   )r   r   )NN)	__name__
__module____qualname____firstlineno____doc__r$   __static_attributes____classdictcell____classcell__)r&   r   s   @@r   r   r      s     .  r   r   Fc                
   V ^8  d   QhR\         R\         R\        \        \         \         3,          ,          R\        \        \         \        3,          ,          R\        R\        R\
        R\        \         \        3,          /# )	r	   methodurlheaders	json_datatimeoutretriesrawreturn)r   r   r   r   r   bool)r   s   "r   r   r   "   s     _< _<_<	_< d38n%_< S#X'	_<
 _< _< 
_< 
#s(^_<r   c                	   T;'       g    / pVP                  R\        4       RpVe8   \        P                  ! V4      P	                  R4      pVP                  RR4       \
        P                  P                  WW R7      p\        V  RV 24       Rp	\        V4       F  p
 \
        P                  P                  WR7      ;_uu_ 4       pVP                  4       P                  R4      p\        R	VP                   R
\        V4       R24       V'       d   VuuRRR4       u # V'       d   \        P                  ! V4      M/ uuRRR4       u # 	  V	'       d   V	h\#        R4      h  + '       g   i     K  ; i  \
        P                   P"                   Ed   pRp TP                  4       P                  R4      pM    M; i\        RTP$                   RTP&                   24       T'       d5   RP)                  TP+                  4       4      p\        RTR,           24       \#        RTP$                   RTP&                   2TP$                  T4      p	RTP$                  u;8:  d   R8  d   M MTP$                  R8w  d   T	hY^,
          8  d   TP$                  R8X  d   \-        TR4      '       d   TP.                  P1                  R4      MRpT'       d:    \3        T4      pMG  \4         d    \6        ^T
,          ,          ^,           p Mi ; i\6        ^T
,          ,          ^,           p\        RTR RT
^,            RT 24       M\6        ^T
,          ,          p\8        P:                  ! T4        Rp?EK   Rp?EK  Rp?i\
        P                   P<                   dy   p\        RTP&                   24       \#        RTP&                   24      p	Y^,
          8  d0   \8        P:                  ! \6        T
^,           ,          4        Rp?EKu   Rp?EK|  Rp?i\        P>                   d$   p\        RT 24       \#        RT 24      p	T	hRp?i\@        \B        \D        3 d   p\        R\G        T4      PH                   RT 24       \#        R\G        T4      PH                   RT 24      p	Y^,
          8  d0   \8        P:                  ! \6        T
^,           ,          4        Rp?EKO   Rp?EKV  Rp?ii ; i)a  Make an HTTP request and return JSON response.

Args:
    method: HTTP method (GET, POST, etc.)
    url: Request URL
    headers: Optional headers dict
    json_data: Optional JSON body (for POST)
    timeout: Request timeout in seconds
    retries: Number of retries on failure

Returns:
    Parsed JSON response (or raw text if raw=True)

Raises:
    HTTPError: On request failure

User-AgentNzutf-8zContent-Typeapplication/json)datar3   r1    )r5   z
Response: z (z bytes)zHTTP Error z: zError body: :N   NzHTTP i  i  i  r3   zRetry-AfterzRate limited (429). Waiting z.1fzs before retry /zURL Error: zJSON decode error: zInvalid JSON response: zConnection error: z$Request failed with no error details)%
setdefault
USER_AGENTjsondumpsencodeurllibrequestRequestr   rangeurlopenreaddecodestatuslenloadserrorr   codereasonjoinsplithasattrr3   getfloat
ValueErrorRETRY_DELAYtimesleepURLErrorJSONDecodeErrorOSErrorTimeoutErrorConnectionResetErrortyper(   )r1   r2   r3   r4   r5   r6   r7   r=   req
last_errorattemptresponser   esnippetretry_afterdelays   &&&&&&&          r   rG   rG   "   s   2 mmG|Z0Dzz)$++G4>+=>
..
 
 
 
PC6(!C5J>4	8'''==}}--g6j 1CI;gFG	 >=
 ,0tzz$'R >= "n 
:
;;o >== ||%% 	"Dvvxw/+affXRz23((4::<0l74=/23"U166("QXXJ#?NJ aff"s"qvv}  1$66S=BI!YBWBW!))--">]aK"E$)+$6E) E$/1<$@1$DEE !,qG| <q @6uSkQX[\Q\P]]^_f^ghi'1<8E

5!! % ||$$ 	8+ahhZ()"[
#;<J1$

;'A+677 %## 	%aS)*"%<QC#@AJ';< 	8$T!W%5%5$6b<="%7Q8H8H7IA3#OPJ1$

;'A+677 %		8s   "(E<
AE(
E<%E(-E(
E<(E93E<9E<< S9NF?>N?GDNK)(N)&LNLA%N S9&S9'A%PS91S92QS9(S9)A=S44S9c                    V ^8  d   QhR\         R\        \        \         \         3,          ,          R\        \         \        3,          /# )r	   r2   r3   r8   )r   r   r   r   )r   s   "r   r   r      s7     : :S :8DcN3 :cSVh :r   c                     \        RV 3RV/VB # )zMake a GET request.GETr3   rG   )r2   r3   kwargss   &&,r   rV   rV      s    5#9w9&99r   c          
          V ^8  d   QhR\         R\        \         \        3,          R\        \        \         \         3,          ,          R\        \         \        3,          /# r	   r2   r4   r3   r8   r   r   r   r   )r   s   "r   r   r      sP     P Pc Pd38n PxS#X7O Peijmorjres Pr   c                $    \        RV 3RVRV/VB # )z#Make a POST request with JSON body.POSTr3   r4   rm   r2   r4   r3   rn   s   &&&,r   postru      s    63OO9OOOr   c          	          V ^8  d   QhR\         R\        \         \        3,          R\        \        \         \         3,          ,          R\         /# rp   rq   )r   s   "r   r   r      sD     Z Z# Z$sCx. Z8DcN;S Zil Zr   c           	     (    \        RV 3RVRVRR/VB # )z7Make a POST request with JSON body and return raw text.rs   r3   r4   r7   Trm   rt   s   &&&,r   post_rawrx      s$    63YY9Y$YRXYYr   c          
      j    V ^8  d   QhR\         R\        R\        R\        \         \        3,          /# )r	   pathr5   r6   r8   )r   r   r   r   )r   s   "r   r   r      s;     G G# G G G^bcfhkck^l Gr   c                    V P                  R4      '       g
   RV ,           p V P                  R4      p V P                  R4      '       g
   V R,           p RV  R2pR\        RR/p\	        W4WR7      # )	zFetch Reddit thread JSON.

Args:
    path: Reddit path (e.g., /r/subreddit/comments/id/title)
    timeout: HTTP timeout per attempt in seconds
    retries: Number of retries on failure

Returns:
    Parsed JSON response
r@   z.jsonzhttps://www.reddit.comz?raw_json=1r;   Acceptr<   )r3   r5   r6   )
startswithrstripendswithrB   rV   )rz   r5   r6   r2   r3   s   &&&  r   get_reddit_jsonr      su     ??3Tz ;;sD==!!g~"4&
4C 	j$G
 sWFFr   )1trueyesr"   )r,   rC   osr   rZ   urllib.errorrF   urllib.requesttypingr   r   r   urllib.parser   DEFAULT_TIMEOUTenvironrV   lowerr   r   MAX_RETRIESrY   rB   	Exceptionr   rG   ru   rx   r    r   r   <module>r      s    8  	 
    & & "


)2.446:NN
 5
	  )-*."_<D:
P
Z
 />k G Gr   