+
    j                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ] ! R R4      4       t] ! R R	4      4       t ! R
 R4      tRR R lltR# )    N)	dataclassPath)DeviceAuthProtocol)codex_executablec                   ,   a  ] tR t^t o V 3R ltRtV tR# )DeviceAuthPromptc                >   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   # )   urlcoderaw_textstr)format__classdict__s   "E/home/user/overdeck-private-tests/subrouter-s5-systray/device_auth.py__annotate__DeviceAuthPrompt.__annotate__   s'     	H  I  M	      N__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__r   s   @r   r	   r	            r   r	   c                   ,   a  ] tR t^t o V 3R ltRtV tR# )DeviceAuthSessionc                R   < V ^8  d   Qh/ S[ P                  ;R&   S[;R&   S[;R&   # )r   process
codex_home
had_backup)
subprocessPopenr   bool)r   r   s   "r   r   DeviceAuthSession.__annotate__   s0         	 r   r   Nr   r    s   @r   r#   r#      r!   r   r#   c                      a  ] tR t^t o V 3R lR ltV 3R lR ltRV 3R lR lltRV 3R lR lltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR lt]V 3R lR l4       tV 3R lR ltRtV tR# )DeviceAuthFlowc                   < V ^8  d   QhRR/# )r   returnNr   )r   r   s   "r   r   DeviceAuthFlow.__annotate__   s     . .$ .r   c                $    \        4       V n        R # N)r   	_protocol)selfs   &r   __init__DeviceAuthFlow.__init__   s    +-r   c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   r&   backup_existingr/   )r   r*   r#   )r   r   s   "r   r   r0       s(     ` ` `t `@Q `r   c           	     D   VR ,          pVR,          pRpVP                  RRR7       V'       d/   VP                  4       '       d   \        P                  ! W44       Rp\        P                  P                  4       p\        V4      VR&   VP                  R\        P                  P                  \        \        P                  ! 4       4      R4      4       \        4       ;'       g    Rp\        P                  ! VR	R
.\        P                  \        P                  \        P                   VR7      pVP"                  VP$                  3 F/  p	V	f   K	   \        P&                  ! V	P)                  4       R4       K1  	  \/        WVR7      #   \*        \,        3 d     KT  i ; i)	auth.jsonauth.json.bakFT)parentsexist_ok
CODEX_HOMECODEX_SQLITE_HOMEz.codex-shared-statecodexloginz--device-auth)stdoutstderrstdinenv)r%   r&   r'   )mkdirexistsosreplaceenvironcopyr   
setdefaultpathjoinr   homer   r(   r)   PIPEDEVNULLrB   rC   set_blockingfilenoAttributeErrorOSErrorr#   )
r4   r&   r8   	auth_pathbackup_pathr'   rE   
executabler%   streams
   &&&       r   startDeviceAuthFlow.start    sD   ,	 ?2
5y//11JJy.Jjjoo
OLGGLLTYY[)+@A	
 &'227
""/2????$$
 ~~w~~6F~7	 7 !T^__ #G, s   %F

FFc                ,   < V ^8  d   QhRS[ RS[RS[/# r   sessiontimeout_secsr/   )r#   floatr	   )r   r   s   "r   r   r0   A   s)     G G#4 GE GUe Gr   c                   \         P                  ! 4       V,           pR p\         P                  ! 4       V8  d   V P                  VP                  V4      pV'       dP   V P                  P                  WE4      w  rFVe-   \        VP                  VP                  VP                  R7      # K  VP                  P                  4       e   M\         P                  ! R4       K  \        R4      h) )r   r   r   g{Gz?z(Timed out waiting for device-auth prompt)time	monotonic_read_next_chunkr%   r3   feedr	   r   r   r   pollsleepTimeoutError)r4   r^   r_   deadlinestrippedchunkprompts   &&&    r   read_promptDeviceAuthFlow.read_promptA   s    >>#l2nn)))'//8DE#'>>#6#6x#G %+"JJ#[[!' 
 ##%1JJtEFFr   c                ,   < V ^8  d   QhRS[ RS[RS[/# r]   )r#   r`   r*   )r   r   s   "r   r   r0   W   s)     	N 	N(9 	N 	N[_ 	Nr   c                     VP                   P                  VR 7      pT^ 8w  d   R# T P                  TP                  R,          4      #   \        P                   d    \	        TP                   4        R# i ; i)timeoutFr:   )r%   waitr(   TimeoutExpiredterminate_process_has_decodable_id_tokenr&   )r4   r^   r_   	exit_codes   &&& r   await_completionDeviceAuthFlow.await_completionW   sl    	,,\,BI
 >++G,>,>,LMM (( 	goo.	s   A	 	*A76A7c                $   < V ^8  d   QhRS[ RR/# r   r&   r/   Nr   )r   r   s   "r   r   r0   b   s     ! ! !$ !r   c                h    VR ,          pVP                  4       '       d   VP                  4        R# R# )r;   N)rG   unlink)r4   r&   rW   s   && r   commitDeviceAuthFlow.commitb   s,     ?2   r   c                $   < V ^8  d   QhRS[ RR/# r|   r   )r   r   s   "r   r   r0   g   s     / /4 /D /r   c                    VR ,          pVR,          pVP                  4       '       d   \        P                  ! W24       R# R# )r:   r;   N)rG   rH   rI   )r4   r&   rV   rW   s   &&  r   rollbackDeviceAuthFlow.rollbackg   s6    ,	 ?2JJ{.  r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r^   r&   r/   N)r#   r   )r   r   s   "r   r   r0   m   s#     " ". "D "T "r   c                R    \        VP                  4       V P                  V4       R # r2   )rv   r%   r   )r4   r^   r&   s   &&&r   abortDeviceAuthFlow.abortm   s    '//*j!r   c                @   < V ^8  d   QhRS[ P                  RS[RS[/# )r   r%   rj   r/   )r(   r)   r`   r   )r   r   s   "r   r   r0   q   s(      
(8(8 E c r   c                   . pR F&  p\        WR4      pVf   K  VP                  V4       K(  	  \        P                  ! 4       pRp V F&  p VP	                  V\        P
                  4       RpK(  	  V'       d   \        RV\        P                  ! 4       ,
          4      pVP                  V4      p	V	 F`  w  r \        P                  ! V
P                  P                  4       R4      pT'       g   K?  T P!                  T4      u TP#                  4        # 	  V P%                  V4      VP#                  4        #   \         d     K  i ; i  \         d     K  i ; i  TP#                  4        i ; i)rB   NFTg        i   )rB   rC   )getattrappend	selectorsDefaultSelectorregister
EVENT_READ	Exceptionmaxrc   rd   selectrH   readfileobjrS   BlockingIOError_decode_chunkclose_fallback_read)r4   r%   rj   streamsstream_namerY   selector
registeredrs   eventskey_maskdatas   &&&          r   re   DeviceAuthFlow._read_next_chunkq   s>   /KW48F!v& 0
 ,,.
	!%%fi.B.BC!%J " c8dnn.>#>?!1"(JC!!wws{{'9'9';TB t#11$77 NN #) &&w/NN !  + ! ! NNsf   E "D9/E ;>E :/E)E 3E E 9EE EE EE EE E/c                    < V ^8  d   QhRS[ /# r   r/   r   )r   r   s   "r   r   r0      s       r   c                    V F0  p VP                  ^4      pT'       g   K  T P                  T4      u # 	  R#   \         d     KD  i ; i)   rb   )r   r   r   )r4   r   rY   r   s   &&  r   r   DeviceAuthFlow._fallback_read   sO    F{{1~ t))$//  	  s   9AAc                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r0      s      s r   c                X    \        V \        4      '       d   V P                  R RR7      # V # )utf-8rI   )errors)
isinstancebytesdecode)r   s   &r   r   DeviceAuthFlow._decode_chunk   s'    dE"";;wy;99r   c                &   < V ^8  d   QhRS[ RS[/# )r   rV   r/   )r   r*   )r   r   s   "r   r   r0      s       $ r   c                    \         P                  ! VP                  R R7      4      pTP                  R4      p\        T\        4      '       g9   TP                  R4      p\        T\        4      '       d   TP                  R4      p\        T\        4      '       g   R# TP                  R4      p\        T4      ^8w  d   R# T^,          pR\        T4      ) ^,          ,          p \        P                  ! Yg,           4      p\         P                  ! TP                  R 4      4       R#   \        \        \         P
                  3 d     R# i ; i  \        \         P
                  \         3 d     R# i ; i)r   )encodingFid_tokentokens.=T)jsonloads	read_textFileNotFoundErrorrU   JSONDecodeErrorgetr   r   dictsplitlenbase64urlsafe_b64decoder   
ValueErrorUnicodeDecodeError)	r4   rV   payloadtokenr   partsencoded_payloadpaddingdecodeds	   &&       r   rw   &DeviceAuthFlow._has_decodable_id_token   s)   	jj!4!4g!4!FGG J'%%%[[*F&$''

:.%%%C u:?(#o..23	../HIGJJw~~g./ - "7D,@,@A 		( D002DE 		s$   &D) &AE ) EE E43E4)r3   N)g      4@)g      @)r   r   r   r   r5   rZ   rn   ry   r   r   r   re   r   staticmethodr   rw   r   r   r    s   @r   r-   r-      s     . .` `BG G,	N 	N! !
/ /" " >   
 r   r-   c                T    V ^8  d   QhR\         P                  R\        R\        RR/# )r   r%   wait_timeout_secskill_timeout_secsr/   N)r(   r)   r`   )r   s   "r   r   r      s6        
	r   c                 z   V P                  4       e   R #  V P                  4         T P                  TR7       R #   \         d     R # i ; i  \        P
                   d     Mi ; i T P                  4        M  \         d     R # i ; i T P                  TR7       R #   \        P
                   d     R # i ; i)Nrr   )rg   	terminaterU   rt   r(   ru   kill)r%   r   r   s   &&&r   rv   rv      s    
 ||~!./   $$  ./$$ sD   ; A A
	A
A%$A%)A: :B	B	B! !B:9B:)g      @g      ?)r   r   rH   r   r(   rc   dataclassesr   pathlibr   device_auth_protocolr   health_clientr   r	   r#   r-   rv   r   r   r   <module>r      sl      	    !  3 *      ] ]@ r   