+
    jU                      a  0 t $ ^ RIHt ^ RIt^ RIt^ RIt^ RI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 ^ RIHt ^ RIHtHtHt RtR]R&   R	tR]R
&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&    ! R R] 4      t! ! R R]!4      t" ! R R]!4      t# ! R R]#4      t$ ! R  R!]!4      t% ! R" R#]!4      t& ! R$ R%]!4      t']! R&R'7       ! R( R)4      4       t(]! R&R'7       ! R* R+4      4       t)]](]*.])3,          t+]! R&R'7       ! R, R-4      4       t,]! R&R'7       ! R. R/4      4       t- ! R0 R14      t.R2 R3 lt/. R4Ot0R# )5    )annotationsN)	dataclassfield)Path)CallableFinalMappingz)https://api.anthropic.com/api/oauth/usagez
Final[str]	USAGE_URLz*https://platform.claude.com/v1/oauth/token	TOKEN_URLz$9d1c250a-e61b-44d9-88ed-5944d1962f5eCLAUDE_CODE_CLIENT_IDzoauth-2025-04-20OAUTH_BETA_HEADERzsystray-ai/1.0
USER_AGENTg      ^@zFinal[float] ACCESS_TOKEN_EXPIRY_SKEW_SECONDSg      >@TOKEN_REFRESH_TIMEOUT_SECONDSz.rotate-journal.jsonROTATE_JOURNAL_SUFFIXc                      ] tR t^ tRtR# )ClaudeOAuthError N__name__
__module____qualname____firstlineno____static_attributes__r       F/home/user/overdeck-private-tests/subrouter-s5-systray/claude_oauth.pyr   r           r   r   c                      ] tR t^$tRtR# )ClaudeOAuthCredentialsErrorr   Nr   r   r   r   r   r   $   r   r   r   c                      ] tR t^(tRtR# )ClaudeOAuthAuthErrorr   Nr   r   r   r   r!   r!   (   r   r   r!   c                      ] tR t^,tRtR# )ClaudeOAuthLoggedOutErrorr   Nr   r   r   r   r#   r#   ,   r   r   r#   c                      ] tR t^0tRtR# )ClaudeOAuthProtocolErrorr   Nr   r   r   r   r%   r%   0   r   r   r%   c                      ] tR t^4tRtR# )ClaudeOAuthTimeoutErrorr   Nr   r   r   r   r'   r'   4   r   r   r'   c                  6   a  ] tR t^8tRR/R V 3R llltRtV ;t# )ClaudeOAuthTransportErrorretry_after_secondsNc               $    V ^8  d   QhRRRRRR/# )   messagestrr*   float | NonereturnNoner   )formats   "r   __annotate__&ClaudeOAuthTransportError.__annotate__9   s"     7 7 7\ 7UY 7r   c               	2   < \         SV `  V4       W n        R # N)super__init__r*   )selfr-   r*   	__class__s   &&$r   r8   "ClaudeOAuthTransportError.__init__9   s    !#6 r   r*   )r   r   r   r   r8   r   __classcell__)r:   s   @r   r)   r)   8   s    7D 7 7 7r   r)   T)frozenc                  D    ] tR t^>t$ R]R&   R]R&   R]R&   RtR]R&   R	tR# )
ClaudeOAuthRequestr.   methodurlMapping[str, str]headersNzbytes | Nonebodyr   )r   r   r   r   __annotations__rE   r   r   r   r   r@   r@   >   s    K	HD,r   r@   c                  H    ] tR t^Ft$ R]R&   R]R&   ]! ]R7      tR]R&   RtR	# )
ClaudeOAuthResponseintstatus_coder.   rE   )default_factoryrC   rD   r   N)	r   r   r   r   rF   r   dictrD   r   r   r   r   rH   rH   F   s    
I!&t!<G<r   rH   c                  0    ] tR t^Pt$ RtR]R&   R]R&   RtR# )UsageReadingu   Usage payload plus the access token that fetched it — the only durable
link between a reading and the account it describes, because the
credentials file may be rewritten by another process mid-fetch.dict[str, object]payloadr.   access_tokenr   N)r   r   r   r   __doc__rF   r   r   r   r   rN   rN   P   s    G r   rN   c                  @    ] tR t^Zt$ R]R&   R]R&   R]R&   R]R&   RtR# )	_LoadedCredentialsrO   rP   oauth_payloadr.   rQ   refresh_tokenr   N)r   r   r   r   rF   r   r   r   r   rT   rT   Z   s    $$r   rT   c                     ] tR t^btRtR7R R lltR R ltR R lt]R	 R
 l4       t	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  lt]R! R" l4       tR# R$ lt]R% R& l4       tR' R( ltR8R) R* lltR+ R, ltR- R. lt]R/ R0 l4       t]R1]R2R3/R4 R5 ll4       tR6tR# )9ClaudeOAuthSessionu#  Consumer of a Claude CLI credentials file.

By default the session is strictly read-only: Anthropic refresh tokens are
one-time-use, and a Claude CLI session that has the grant in memory rotates it
itself — a second rotator replays a consumed refresh token and the provider
revokes the entire grant chain. ``allow_rotation=True`` is only correct when the
caller has proven no live CLI session owns this credentials file; then this
session becomes the sole rotator, and it persists the rotated grant atomically
so the next CLI launch picks it up.Nc               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r,   credentials_pathz
Path | str	transportzClaudeOAuthTransport | Nonetimeout_secsfloatallow_rotationboolrotation_backup_pathzPath | str | Noner0   r1   r   )r2   s   "r   r3   ClaudeOAuthSession.__annotate__m   sF     
 
$
 /
 	

 
 0
 

r   c                	    V^ 8:  d   \        R4      h\        V4      V n        Vf   \        MTV n        W0n        W@n        Vf
   RV n        R# \        V4      V n        R# )r   z.Claude OAuth timeout must be greater than zeroN)r'   r   rZ   default_transport
_transport_timeout_secs_allow_rotation_rotation_backup_path)r9   rZ   r[   r\   r^   r`   s   &&&&&&r   r8   ClaudeOAuthSession.__init__m   sb     1)*Z[[ $%5 6/8/@+i)-(0D 	"6:;O6P 	"r   c                   V ^8  d   QhRR/# )r,   r0   rO   r   )r2   s   "r   r3   ra      s     0 0, 0r   c                	6    V P                  4       P                  # r6   )get_usage_readingrP   r9   s   &r   	get_usageClaudeOAuthSession.get_usage   s    %%'///r   c                   V ^8  d   QhRR/# )r,   r0   rN   r   )r2   s   "r   r3   ra      s     
 
< 
r   c                	   V P                  4       pV P                  V4      '       d   V P                  V4      pV P                  V P	                  VP
                  4      4      pVP                  R 8X  dX   V P                  V4      pV P                  V P	                  VP
                  4      4      pVP                  R 8X  d   \        R4      h\        V P                  V4      VP
                  R7      # )  zOClaude OAuth usage request failed with status 401 with the latest on-disk token)rP   rQ   )
_load_credentials_is_expired_freshen_send_build_usage_requestrQ   rJ   r#   rN   _parse_usage_response)r9   credentialsresponses   &  r   rk   $ClaudeOAuthSession.get_usage_reading   s    ,,.K((--4K::d778P8PQR3&--4Kzz$";";K<T<T"UVH##s*/e  ..x8$11
 	
r   c                    V ^8  d   QhRRRR/# )r,   rx   rT   r0   r_   r   )r2   s   "r   r3   ra      s     X X!3 X Xr   c                	    V P                   P                  R 4      p\        V\        4      '       g   \        V\        \
        34      '       g   R# VR,          \        P                  ! 4       \        ,           8*  # )	expiresAtFg     @@)rU   get
isinstancer_   rI   r]   timer   )rx   expires_at_mss   & r   rs   ClaudeOAuthSession._is_expired   sU    #1155kBmT***]SRWL2Y2Yv%7W)WWWr   c                    V ^8  d   QhRRRR/# r,   rx   rT   r0   r   )r2   s   "r   r3   ra      s     
 
$6 
;M 
r   c                	8  a  S P                  4       pVP                  VP                  8w  d   V# S P                  '       d   S P                  V4      # S P	                  4       P                  4       '       d   S P                  V 3R  l4      pVe   V# \        R4      h)c                 $   < S P                  4       # r6   )_replay_rotate_journalrl   s   r   <lambda>-ClaudeOAuthSession._freshen.<locals>.<lambda>   s    t7R7R7Tr   zHClaude OAuth access token is stale and only the Claude CLI may rotate it)rr   rQ   rf   _rotate_journal_pathexists_with_rotate_lockr)   )r9   rx   latest	recovereds   f&  r   rt   ClaudeOAuthSession._freshen   s    '')+":"::M<<''&&((../TUI$  'V
 	
r   c                    V ^8  d   QhRRRR/# r   r   )r2   s   "r   r3   ra      s     5 5#5 5:L 5r   c                	<   a a R  VV 3R llpS P                  V4      # )c                   V ^8  d   QhRR/# r,   r0   rT   r   )r2   s   "r   r3   0ClaudeOAuthSession._rotate.<locals>.__annotate__   s     	 	1 	r   c                   < SP                  4       p V e   V # SP                  4       pVP                  SP                  8w  d   V# SP                  4        SP	                  V4      pSP                  VP                  4       SP                  VP                  4       SP                  4        SP                  VP                  4       V# r6   )
r   rr   rQ   _preflight_writable_request_rotated_grant_write_rotate_journalrP   _atomic_write_payload_clear_rotate_journal_write_rotation_backup)r   r   rotatedrx   r9   s      r   rotate_locked1ClaudeOAuthSession._rotate.<locals>.rotate_locked   s    335I$  ++-F""k&>&>>$$&11&9G&&w7&&w7&&(''8Nr   )r   )r9   rx   r   s   ff r   r   ClaudeOAuthSession._rotate   s     	 	 %%m44r   c                   V ^8  d   QhRR/# )r,   actionz'Callable[[], _LoadedCredentials | None]r   )r2   s   "r   r3   ra      s     
 
(O 
r   c                	t   V P                   P                  V P                   P                  R ,           4      p \        VRRR7      pT;_uu_ 4        \        P                  ! T\        P                  4       T! 4       uuRRR4       #   \         d   p\        R4      ThRp?ii ; i  + '       g   i     R# ; i)z.rotate.lockwutf-8encodingz/Claude OAuth rotation lock could not be createdN)	rZ   	with_namenameopenOSErrorr   fcntlflockLOCK_EX)r9   r   	lock_path	lock_fileexcs   &&   r   r   $ClaudeOAuthSession._with_rotate_lock   s    ))33D4I4I4N4NQ_4_`		Yg>I
 YKK	5==18 Y	  	-A	 YYs#   B ,B&B#BB#&B7	c                   V ^8  d   QhRR/# )r,   r0   r   r   )r2   s   "r   r3   ra      s     c ct cr   c                	v    V P                   P                  V P                   P                  \        ,           4      # r6   )rZ   r   r   r   rl   s   &r   r    ClaudeOAuthSession._journal_path   s+    $$..t/D/D/I/ILa/abbr   c                   V ^8  d   QhRR/# )r,   r0   z_LoadedCredentials | Noner   )r2   s   "r   r3   ra      s      (A r   c                Z   V P                  4       p VP                  RR7      p T P                  \        P                  ! T4      4      pT P                  4       pTP                  TP                  8X  d   T P                  4        R# T P                  TP                  4       T P                  4        T P                  TP                  4       T#   \         d     R# \         d   p\	        R4      ThRp?ii ; i  \        P                  \        3 d    T P                  4         R# i ; i)u   A journal left behind means a rotated grant arrived from the provider but
the credentials file was never replaced — the journal holds the only copy of
the live refresh token. Replay it before anything else touches the grant.r   r   Nz:Claude OAuth rotation journal exists but could not be read)r   	read_textFileNotFoundErrorr   r   $_loaded_credentials_from_raw_payloadjsonloadsJSONDecodeErrorr   rr   rQ   r   rP   r   )r9   journal_pathtextr   	journaledr   s   &     r   r   )ClaudeOAuthSession._replay_rotate_journal   s    ))+	))7);D	AA$**TBRSI '')!!V%8%88&&(""9#4#45""$##I$5$56% ! 	 	-L	 $$&AB 	&&(	s4   C %C; C8C8&C8'C33C8;+D*)D*c                   V ^8  d   QhRR/# r,   r0   r1   r   )r2   s   "r   r3   ra      s      T r   c                    \         P                  ! V P                  P                  RR7      w  r \        P
                  ! VR4       \        P                  ! V4       \        P                  ! V4       \        P                  ! V4       R#   \        P                  ! T4       i ; i  \         d   p\        R4      ThRp?ii ; i)zProve the grant can be persisted BEFORE the one-time refresh token is
spent; a full disk or read-only mount must never consume a token.z.credentials.preflight-dirprefixs   {}zFClaude OAuth credentials directory is not writable; refusing to rotateN)tempfilemkstemprZ   parentoswritefsynccloseunlinkr   r   )r9   fd	temp_namer   s   &   r   r   &ClaudeOAuthSession._preflight_writable   s    	$,,))009RMBU#IIi   	-X	s.   .B' -B ,B' B$$B' 'C2B>>Cc                    V ^8  d   QhRRRR/# r,   rP   rO   r0   r1   r   )r2   s   "r   r3   ra      s      -> 4 r   c                	   V P                  4       p \        P                  ! V P                  P                  R R7      w  r4 \
        P                  ! VR4       \
        P                  ! VRRR7      ;_uu_ 4       pVP                  \        P                  ! V4      4       VP                  4        \
        P                  ! VP                  4       4       RRR4       \
        P                  ! WB4       R#   + '       g   i     L(; i  \         d+     \
        P                   ! T4       h   \         d     h i ; ii ; i  \         d   p\#        R4      ThRp?ii ; i)z.credentials.journal-r     r   r   r   NzLrotated Claude OAuth grant could not be journaled; this account needs /login)r   r   r   rZ   r   r   fchmodfdopenr   r   dumpsflushr   filenoreplacer   r   r   )r9   rP   r   r   r   handler   s   &&     r   r   (ClaudeOAuthSession._write_rotate_journal   s   ))+	$,,))009PMB		"e$YYr399VLLG!45LLNHHV]]_- : 

93	 :9
  IIi(     	-^	sf   .D> 8D 9AC3D 3D	>D D;D)(D;)D74D;6D77D;;D> >E	EEc                   V ^8  d   QhRR/# r   r   )r2   s   "r   r3   ra     s      t r   c                	t     \         P                  ! V P                  4       4       R #   \         d     R # i ; ir6   )r   r   r   r   rl   s   &r   r   (ClaudeOAuthSession._clear_rotate_journal  s.    	IId((*+ 		s   $( 77c                    V ^8  d   QhRRRR/# r   r   )r2   s   "r   r3   ra     s      .? D r   c                	   V P                   f   R #  V P                   pVP                  P                  RRRR7       \        P                  ! VP                  RR7      w  r4 \
        P                  ! VR4       \
        P                  ! VRRR	7      ;_uu_ 4       pVP                  \        P                  ! V4      4       VP                  4        \
        P                  ! VP                  4       4       R R R 4       \
        P                  ! WB4       R #   + '       g   i     L(; i  \         d+     \
        P                   ! T4       h   \         d     h i ; ii ; i  \         d     R # i ; i)
Ni  T)modeparentsexist_okz.backup-r   r   r   r   r   )rg   r   mkdirr   r   r   r   r   r   r   r   r   r   r   r   r   r   )r9   rP   backupr   r   r   s   &&    r   r   )ClaudeOAuthSession._write_rotation_backup  s   %%-	//FMMUD4H$,,zRMB		"e$YYr399VLLG!45LLNHHV]]_- : 

9-	 :9
  IIi(     		sa   AE !8D& AD3D& D#	D& &E2E	E	EEEEE E-,E-c                    V ^8  d   QhRRRR/# r   r   )r2   s   "r   r3   ra   +  s      *B *B2D *BI[ *Br   c                	   \         P                  P                  R RRVP                  R\        /4      P                  R4      pV P                  \        R\        RRRRR	\        /VR
7      \        V P                  \        4      R7      pVP                  ^8w  d_   V P                  VP                  4      R8X  d   \!        R4      h\#        RVP                   2V P%                  VP&                  4      R7      hV P)                  VP                  R4      pV P+                  VR4      pVP-                  R4      pVP-                  R4      p\/        VP0                  4      pWXR&   \3        V\4        4      '       d   V'       d   WhR&   \3        V\6        4      '       gL   \3        V\8        \:        34      '       d0   \9        \<        P<                  ! 4       V,           R,          4      VR&   \/        VP>                  4      p	WR&   V PA                  V	4      # )
grant_typerV   	client_idr   POSTAcceptapplication/jsonzContent-Typez!application/x-www-form-urlencoded
User-Agent)rA   rB   rD   rE   )r\   invalid_grantz8Claude OAuth refresh grant was rejected as invalid_grantz.Claude OAuth token refresh failed with status r<   ztoken responserQ   
expires_inaccessTokenrefreshTokeni  r}   claudeAiOauth)!urllibparse	urlencoderV   r   encoderu   r@   r   r   maxre   r   rJ   _oauth_error_coderE   r#   r)   _retry_after_secondsrD   _parse_json_object_require_non_empty_stringr~   rL   rU   r   r.   r_   rI   r]   r   rP   r   )
r9   rx   rE   ry   grantrQ   rV   r   rU   rP   s
   &&        r   r   )ClaudeOAuthSession._request_rotated_grant+  s   ||%%o!:!:2
 &/ 	 ::0"$G *
 	 T//1NO  
 3&%%hmm4G/N  ,@AUAU@VW$($=$=h>N>N$O  ''7GH55e^L		/2YY|,
[667'3m$mS))m,9.)*d++
:U|0T0T),diikJ.F$-N)OM+&{**+#0 88AAr   c                    V ^8  d   QhRRRR/# r   r   )r2   s   "r   r3   ra   W  s      -> 4 r   c                	   V P                   P                  p V P                   P                  4       P                  R ,          p\
        P                  ! VRR7      w  rE \        P                  ! WC4       \        P                  ! VRRR7      ;_uu_ 4       pVP                  \        P                  ! V4      4       VP                  4        \        P                  ! VP                  4       4       RRR4       \        P                   ! WPP                   4        \        P&                  ! T\        P(                  4      p \        P                  ! T4       \        P*                  ! T4       R#   \         d    Rp EL9i ; i  + '       g   i     L; i  \         d;   p \        P"                  ! T4       M  \         d     Mi ; i\%        R4      ThRp?ii ; i  \        P*                  ! T4       i ; i  \         d     R# i ; i)	i  r   z.credentials.rotate-r   r   r   r   NzLrotated Claude OAuth grant could not be persisted; this account needs /login)rZ   r   statst_moder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   O_RDONLYr   )	r9   rP   	directoryr   r   r   r   r   dir_fds	   &&       r   r   (ClaudeOAuthSession._atomic_write_payloadW  sy   ))00		((--/77%?D !((Y?UV	IIb2sW55TZZ01) 6 JJy"7"78	WWY4F!  /  	D	
 65
  			)$ -^	   		s   +E, 7F AF /(F %G6 >G G6 ,E=<E= F	F GF65G6GGGGGG33G6 6HHc                    V ^8  d   QhRRRR/# )r,   rE   r.   r0   z
str | Noner   )r2   s   "r   r3   ra   w  s     9 9 9
 9r   c                	     \         P                  ! V 4      p\        T\        4      '       g   R # TP                  R4      p\        T\        4      '       d   T# R #   \         P                   d     R # i ; i)Nerror)r   r   r   r   rL   r~   r.   )rE   rP   r  s   &  r   r   $ClaudeOAuthSession._oauth_error_codev  sf    	jj&G '4((G$"5#..u8D8 ## 		s   A A43A4c                    V ^8  d   QhRRRR/# )r,   ry   rH   r0   rO   r   )r2   s   "r   r3   ra     s      .A FW r   c                	   VP                   R9   d   \        RVP                    24      hVP                   ^8w  d4   \        RVP                    2V P                  VP                  4      R7      hV P                  VP                  R4      pV# )rq   z.Claude OAuth usage request failed with status r<   zusage response>   rq       )rJ   r!   r)   r   rD   r   rE   )r9   ry   rP   s   && r   rw   (ClaudeOAuthSession._parse_usage_response  s    ?2&@AUAU@VW  3&+@AUAU@VW$($=$=h>N>N$O  ))(--9IJr   c                    V ^8  d   QhRRRR/# )r,   rD   rC   r0   r/   r   )r2   s   "r   r3   ra     s     L L&7 LL Lr   c                	    \        R  V P                  4        4       R4      pVf   R#  \        V4      p\
        P                  ! T4      '       d
   T^ 8  d   T# R#   \        \        3 d     R# i ; i)c              3  X   "   T F   w  rVP                  4       R 8X  g   K  Vx  K"  	  R# 5i)zretry-afterN)lower).0keyheaders   &  r   	<genexpr>:ClaudeOAuthSession._retry_after_seconds.<locals>.<genexpr>  s!     W#))+:VVVs   *
*N)nextitemsr]   	TypeError
ValueErrormathisfinite)rD   valuesecondss   &  r   r   'ClaudeOAuthSession._retry_after_seconds  so    Ww}}W
 =	ElG --00W\wKtK :& 		s   A A0/A0c                    V ^8  d   QhRRRR/# )r,   rQ   r.   r0   r@   r   )r2   s   "r   r3   ra     s     

 

 

9K 

r   c                	L    \        R \        RRRRV 2R\        R\        /R7      # )GETr   r   AuthorizationzBearer r   zanthropic-beta)rA   rB   rD   )r@   r
   r   r   )r9   rQ   s   &&r   rv   'ClaudeOAuthSession._build_usage_request  s7    !,7<.!9j "3		
 		
r   c               $    V ^8  d   QhRRRRRR/# )r,   requestr@   r\   r/   r0   rH   r   )r2   s   "r   r3   ra     s$      )9E	r   c                	     T P                  Yf   V P                  MT4      p\        T\        4      '       g   \        R4      h\        TP                  \        4      '       g!   \        TP                  \        4      '       g   \        R4      h\        TP                  \         4      '       g   \        R4      hT#   \         d    h \        \        P
                  3 d   p\        R4      ThR p?i\         d   p\        R4      ThR p?ii ; i)NzClaude OAuth request timed outzClaude OAuth transport failedz3Claude OAuth transport returned an invalid responsez>Claude OAuth transport response status_code must be an integerz1Claude OAuth transport response body must be text)rd   re   r   TimeoutErrorsockettimeoutr'   	Exceptionr)   r   rH   r%   rJ   r_   rI   rE   r.   )r9   r+  r\   ry   r   s   &&&  r   ru   ClaudeOAuthSession._send  s    		V/C++H ($788*+`aah**D11HDXDXZ]9^9^*P  (----*+^__   	fnn- 	U)*JKQTT 	V+,KLRUU	Vs/   !B< <$D!D"C..D;D<DDc                   V ^8  d   QhRR/# r   r   )r2   s   "r   r3   ra     s     B B#5 Br   c                	P    V P                   P                  R R7      p \
        P                  ! T4      pT P                  T4      #   \         d   p\        R4      ThRp?i\         d   p\        R4      ThRp?ii ; i  \
        P                   d   p\        R4      ThRp?ii ; i)r   r   (Claude OAuth credentials file is missingNz/Claude OAuth credentials file could not be read>Claude OAuth credentials file must contain a valid JSON object)	rZ   r   r   r   r   r   r   r   r   )r9   r   r   rP   s   &   r   rr   $ClaudeOAuthSession._load_credentials  s    	j((22G2DD	jj&G
 88AA ! 	c-.XY_bb 	j-._`fii	j
 ## 	-P	s@   A A? A<AA<*A<+A77A<?B%B  B%c                    V ^8  d   QhRRRR/# )r,   rP   objectr0   rT   r   )r2   s   "r   r3   ra     s     
 
F 
GY 
r   c                	N   \        V\        4      '       g   \        R 4      hVP                  R4      p\        V\        4      '       g   \        R4      hV P	                  VR\        RR7      pV P	                  VR\        RR7      p\        \        V4      \        V4      VVR7      # )r5  r   z6Claude OAuth credentials file is missing claudeAiOauthr   r4  )failure_clsr   r   )rP   rU   rQ   rV   )r   rL   r   r~   r   rT   )r9   rP   rU   rQ   rV   s   &&   r   r   7ClaudeOAuthSession._loaded_credentials_from_raw_payload  s    '4((-P   O4-..-H  553=	 6 
 663=	 7 
 "M}-%'	
 	
r   c               $    V ^8  d   QhRRRRRR/# )r,   rE   r.   labelr0   rO   r   )r2   s   "r   r3   ra     s"       S 5F r   c                	     \         P                  ! V 4      p\	        T\
        4      '       g   \        R T R24      hT#   \         P                   d   p\        R T R24      ThRp?ii ; i)zClaude OAuth z must be valid JSONNz must be a JSON object)r   r   r   r%   r   rL   )rE   r=  rP   r   s   &&  r   r   %ClaudeOAuthSession._parse_json_object  sz    	jj&G
 '4((*w&<=   ## 	*w&9:	s   ? A)A$$A)r:  r   zClaude OAuth response fieldc          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r,   rP   zMapping[str, object]r  r.   r:  ztype[ClaudeOAuthError]r   r0   r   )r2   s   "r   r3   ra     sA     
H 
H%
H
H ,	
H
 
H 

Hr   c               	    V P                  V4      p\        V\        4      '       d   V'       d   V# V! V R V R24      h) z must be a non-empty string)r~   r   r.   )rP   r  r:  r   r"  s   &&$$ r   r   ,ClaudeOAuthSession._require_non_empty_string  s?     C eS!!eLVHAcU*EFGGr   )rf   rg   re   rd   rZ   )Ng      @FNr6   ) r   r   r   r   rR   r8   rm   rk   staticmethodrs   rt   r   r   r   r   r   r   r   r   r   r   r   rw   r   rv   ru   rr   r   r   r%   r   r   r   r   r   rX   rX   b   s    +
$0
" X X
5$
c6$0.*BX> 9 9 L L

0B 
<   
H /G	
H
 4
H 
Hr   rX   c               $    V ^8  d   QhRRRRRR/# )r,   r+  r@   r\   r]   r0   rH   r   )r2   s   "r   r3   r3   
  s#     4 41 4 4K^ 4r   c           
        \         P                  P                  V P                  V P                  \        V P                  4      V P                  R 7      p \         P                  P                  W!R7      ;_uu_ 4       pVP                  4       P                  RRR7      p\        VP                  4       V\        VP                  P                  4       4      R7      uuRRR4       #   + '       g   i     R# ; i  \         P                  P                   du   pTP                  4       P                  RRR7      p\        TP                   TTP                  e$   \        TP                  P                  4       4      M/ R7      u Rp?# Rp?i\         P                  P"                   dQ   p\%        TRR4      p\'        T\(        \*        P,                  34      '       d   \)        R4      Th\/        R	4      ThRp?ii ; i)
)datarD   rA   )r/  r   r   )errors)rJ   rE   rD   Nreasonz	timed outztransport failure)r   r+  RequestrB   rE   rL   rD   rA   urlopenreaddecoderH   getcoder  r  	HTTPErrorcodeURLErrorgetattrr   r-  r.  r/  r   )r+  r\   raw_requestry   rE   r   rI  s   &&     r   rc   rc   
  su   ..((\\W__%~~	 ) K4^^##K#FF(==?))'))DD&$,,.X--3356 GFFF <<!! 
xxz   ;"141HD**,-b
 	

 <<   4h-f|V^^<=={+4)*3	4sQ   (C; >AC'
C; 'C8	2C; 8C; ;G;A)F	G;	 G;*G;+AG66G;)r   r   r   r   r   r   r
   r   r!   r   r   r#   r%   r@   rH   rX   r'   ClaudeOAuthTransportr)   rc   )1__conditional_annotations__
__future__r   r   r   r   r   r.  r   r   urllib.errorr   urllib.parseurllib.requestdataclassesr   r   pathlibr   typingr   r   r	   r
   rF   r   r   r   r   r   r   r   RuntimeErrorr   r   r!   r#   r%   r'   r)   r@   rH   r]   rT  rN   rT   rX   rc   __all__)rU  s   @r   <module>r_     s   " "    	       (  + + D	: CD	: D$J z J 2 : 2)
J )16  , 6 /3 | 2$: z :	| 		"2 		+ 		 4 		/ 		. 	7 0 7 $   $= = =  !3U ;=P PQ  $   $  eH eHP4:r   