mfddlZddlZddlZddlmZddlmZmZddlmZddl m Z ddl m Z e r(ddl Z ddlmZddlmZdd lmZdd lmZdd lmZdd l mZdd ZeddZdZdZGddeZGddeZdS)N)datetime)ThreadLock)contextmanager)MYPY)format_timestamp)Optional)Union)Any)Dict) Generator) SessionStatusc|tjj}|jj}|0|jr|jjdni}|d}|S)z>r)exitedabnormalcrashedc6eZdZ d dZdZdZdZdZdZdS) SessionFlusher c||_||_i|_d|_t |_d|_d|_dS)NT) flush_funcflush_intervalpending_threadr _thread_lock_thread_for_pid_running)selfr1r2s r__init__zSessionFlusher.__init__@s@ %,   FF# rc|j}i|_|t|dSr$)r3r1listvalues)r8r3s rflushzSessionFlusher.flushNs:,  W^^--../////rcjtjkr jdSj5jtjkrj ddddSfd}t |}d|_||_tj_dddn #1swxYwYdS)NcjrDtjjjrjrjBdSdSr$)r7timesleepr2r3r=r8srr4z/SessionFlusher._ensure_running.._thread\s`m%Jt2333|% % m%%%%%r)targetT)r6osgetpidr4r5rdaemonstart)r8r4threads` r_ensure_runningzSessionFlusher._ensure_runningTs"  29;; . .4<3K4   / /#ry{{22t|7O / / / / / / / / % % % % %7+++F FM LLNNN!DL#%9;;D  / / / / / / / / / / / / / / / ts%B; AB;;B?B?cz||j|jj<|dSr$)to_jsonr3sidhexrI)r8sessions r add_sessionzSessionFlusher.add_sessionjs6)0(9(9 W[_% rcd|_dS)NF)r7rBs rkillzSessionFlusher.killqs  rc.|dSr$)rQrBs r__del__zSessionFlusher.__del__us rN)r/) __name__ __module__ __qualname__r9r=rIrOrQrSrrr.r.?sx    000 ,rr.c^eZdZ ddZ ddZ ddZdZdS)SessionNc |tj}|tj}|d}||_d|_||_d|_d|_d|_ d|_ d|_ d|_ | ||||||| | | |  dS)Nokr) rLdid timestampdurationrelease environment user_agent ip_addresserrorsuser)r&uuid4rutcnowstatusr\startedr_r`r^rarbrcupdate r8rLr\r]rhr^rgr_r`rarbrcrds rr9zSession.__init__{s ;*,,C ?o''G >F      #!!  rc | rX| | d} |?| dp)| dp| d}|t||_|t||_|t j}||_|||_|||_ |||_ |||_ | | |_ | | |_ | | |_| ||_dSdS)Nrbidemailusername)rr)rLstrr\rrfr]rhr^r_r`rbrarcrgrjs rrizSession.updates "  R!!XXl33 {hhtnnQ(9(9QTXXj=Q=Q ?!#DH ?3xxDH   ))I"  "DL  $DM  "DL  "*D   !(DO  !(DO   DK   DKKK  rcX| |jdkrd}|||dSdS)Nr[r*)rg)rgri)r8rgs rclosez Session.closesB >dkT11F   KKvK & & & & &  rct|jdt|jt|j|jd}|jr |j|d<|j |j|d<|j |j|d<i}|j |j |d<|j |j |d<|j |j |d<|j |j |d <|r||d <|S) NT)rLinitrhr]rgrcr\r^r_r`rbraattrs) rorLrrhr]rgrcr\r^r_r`rbra)r8rvrts rrKzSession.to_jsonstx==' 55)$.99k    ; ';BxL 8 BuI = $!]BzN < ##|E)    '#'#3E- ? &"&/E,  ? &"&/E,   BwK r) NNNNNNNNNNNNr$)rTrUrVr9rirqrKrWrrrYrYzs   + + + + ^   .!.!.!.!b''''rrYr$)rDr&r@r threadingrr contextlibrsentry_sdk._typesrsentry_sdk.utilsrrtypingr r r r r rrrr)TERMINAL_SESSION_STATESobjectr.rYrWrrr}s """"""""%%%%%%""""""------ 0      //////        <88888V888vBBBBBfBBBBBr