
    Ki=                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
JrJr  S SKJrJr  S SKrS SKJr  S SKJr  S SKJr  S SKJr  S S	KJrJrJrJrJr  S S
KJ r J!r!  S SK"J#r#  S SK$J%r%J&r&J'r'J(r(J)r)J*r*J+r+  S SK,J-r-J.r.J/r/  S SK0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:  S SK;J<r<J=r=J>r>J?r?  S SK@JArA   S SKBrB\R                  \\4rFSrGS rHS\I\J\
4   4S jrK " S S\L5      rMS rNS rOg! \C a    S SKDrB N>f = f)    N)datetime	timedelta)AnyOptionalUnion)UUIDuuid4)tzutc)string_types)Consumer)ExceptionCapture)exc_info_from_errorexceptions_from_error_tuplehandle_in_appexception_is_already_capturedmark_exception_as_captured)InconclusiveMatchErrormatch_feature_flag_properties)Poller)DEFAULT_HOSTAPIError
batch_postdetermine_server_hostflagsgetremote_config)_get_current_contextget_context_distinct_idget_context_session_id)
FeatureFlagFeatureFlagResultFlagMetadataFlagsAndPayloadsFlagsResponse	FlagValuenormalize_flags_responseto_flags_and_payloadsto_payloads	to_values)SizeLimitedDictcleanguess_timezoneremove_trailing_slash)VERSIONiP  c                     Sn Sn[         R                  nUR                  S5      (       a;  Sn [        [        S5      (       a!  [        R                  " 5       S   nU(       a  UnX4$ US:X  a;  Sn [        [        S5      (       a!  [        R
                  " 5       S   nU(       a  UnX4$ UR                  S	5      (       a)  S
n [        R                  " 5       nUS   (       a  US   nX4$ UR                  S5      (       a/  Sn [        [        S5      (       a  [        R                  " 5       nX4$ Un [        [        S5      (       a  [        R                  " 5       nX4$ )zf
Returns standardized OS name and version information.
Similar to how user agent parsing works in JS.
 winWindows	win32_verr   darwinzMac OS Xmac_verlinuxLinuxversionfreebsdFreeBSDrelease)	sysplatform
startswithhasattrr3   r5   distroinfor;   )os_name
os_versionplatform_namewin_versionmac_version
linux_infos         P/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/posthog/client.pyget_os_inforI   B   sK   
 GJLLM&&8[))",,.q1K(
2 / 
(	"8Y''"**,Q/K(
$ ! 
	!	!'	*	*[[]
i #I.J  
	!	!)	,	,8Y''!))+J 	  8Y''!))+J    returnc                  v    [        5       u  p[        R                  " 5       S[        R                  S S -  U US.$ )Nz%s.%s.%s   )z$python_runtimez$python_versionz$osz$os_version)rI   r=   python_implementationr<   version_info)rB   rC   s     rH   system_contextrP   m   s?    %-G $99;%)9)9"1)=>!	 rJ   c                      \ rS rSrSr\R                  " S5      r                           S@S jr\	S 5       r
\
R                  S	 5       r
      SAS
 jr    SBS\\\\\4   4   4S jjr    SBS\\\4   4S jjr    SBS\4S jjr    SBS\4S jjr         SCS jr      SAS jr      SAS jr        SDS jr      SAS jr       SES jr       SES jrS rS rS r S r!S r"S r#0 0 0 SS.S\$4S jjr%0 0 0 SSSS.S  jr&S0 0 0 SSSS!.S"\'\$   S\'\(   4S# jjr)0 0 0 SSSS.S\'\(   4S$ jjr*0 0 0 SSSS.S\'\$   4S% jjr+S&\S'\S(\\\4   S)\\\4   S*\\\4   S\'\$   4S+ jr,S0 0 0 SSSS,.S-\'\$   4S. jjr-S&\S'\S(\\\4   S)\\\4   S*\\\4   S/\'\   S\.\'\/   \'\   4   4S0 jr0S'\S&\S1\'\$   S2\'\   S3\S(\\\4   S/\'\   S4\'\   S5\'\/   4S6 jr1S&\4S7 jr2S&\S-\$S\'\   4S8 jr30 0 0 SSS9.S\'\\\\\4   4      4S: jjr40 0 0 SSS9.S\4S; jjr50 0 0 SS.S\.\\4   4S< jjr6S= r7S> r8S?r9g)FClientx   zCreate a new PostHog client.posthogNFTc                    [         R                  " U5      U l         U=(       d    UU l        [        SU R                  [        5        X`l        X0l        XPl        Xl        U=(       d    [        U l
        [        U5      U l        Xl        Xl        S U l        S U l        S U l        S U l        Xl        UU l        S U l        [-        [.        [0        5      U l        UU l        UU l        UU l        UU l        UU l        UU l        UU l         S U l!        UU l"        Uc   [F        RH                  " 5       nUU l&        Xl'        U(       a?  [P        RR                  " 5         U RT                  RW                  [P        RX                  5        O)U RT                  RW                  [P        RZ                  5        Ub;  []        U5      (       a  UU l/        O*U RT                  Ra                  S5        S U l/        OS U l/        U R<                  (       a  [c        X R@                  S9U l!        U(       a  S U l2        g U(       a   [f        Rh                  " U Rj                  5        [m        U5       Hn  n/ U l2        [o        U R                   U R                  U R                  UUUU	U
UUS9
nU Rd                  Rq                  U5        U(       d  M^  URs                  5         Mp     g ! [J         a    S n GNf = f)Napi_keyz/before_send is not callable, it will be ignored)integrations)hoston_errorflush_atflush_intervalgzipretriestimeouthistorical_migration):queueQueuerV   requirer   rY   debugsend	sync_moder   raw_hostr   rX   r\   r^   _feature_flagsfeature_flags_by_keygroup_type_mappingcohortspoll_interval%feature_flags_request_timeout_secondspollerr*   MAX_DICT_SIZEset#distinct_ids_feature_flags_reporteddisableddisable_geoipr_   super_propertiesenable_exception_autocapturelog_captured_exceptions"exception_autocapture_integrationsexception_captureprivacy_modeosgetcwd	Exceptionproject_rootpersonal_api_keyloggingbasicConfiglogsetLevelDEBUGWARNINGcallablebefore_sendwarningr   	consumersatexitregisterjoinranger   appendstart)selfrV   rX   rc   max_queue_sizerd   rY   rZ   r[   r\   max_retriesre   r^   threadrk   r}   project_api_keyrq   rr   r_   rl   rs   rt   ru   rv   r|   rx   r   nconsumers                                 rH   __init__Client.__init__}   s^   < [[0
 '1'	4<<6 
	",)$/		"$(!"&*1 	2 3B=RU3V0 *$8! 0,H)'>$2T/!%($!yy{ ) !1 !HHgmm,HHgoo."$$#.   !RS#' #D,,%5#J#J&D" !DN 		*6]!##JJLL%%#1'#)= %%h/ 4NN$% #Q  $#$s   K KKc                     U R                   $ )z)
Get the local evaluation feature flags.
)rg   r   s    rH   feature_flagsClient.feature_flags   s    
 """rJ   c                     U=(       d    / U l         U R                    Vs0 s H  nUR                  S5      c  M  US   U_M     snU l        U R                  c   S5       egs  snf )z)
Set the local evaluation feature flags.
keyNDfeature_flags_by_key should be initialized when feature_flags is set)rg   r   rh   )r   r   flags      rH   r   r     sq    
 $kr ++%
+xx DK+%
!
 ((4 	
R	
4%
s
   A 
A c                 &   Ub  [         R                  " S[        SS9  Uc
  [        5       nU=(       d    0 n[	        SU[
        5        [	        SU[        5        SU;  a  [        5       (       a  [        5       US'   UUUSUS.nU R                  Xv5      $ )	NNThe 'context' parameter is deprecated and will be removed in a future version.   
stackleveldistinct_id
properties$session_idz	$identify	timestampr   $seteventuuid)	warningswarnDeprecationWarningr   rb   ID_TYPESdictr   _enqueuer   r   r   contextr   r   rr   msgs           rH   identifyClient.identify  s     MM`" 13K%2
{H5j$/
*/E/G/G(>(@J}% #& 
 }}S00rJ   rK   c                 P    U R                  XX4U5      n[        U5      =(       d    0 $ )z@
Get feature flag variants for a distinct_id by calling decide.
)get_flags_decisionr)   r   r   groupsperson_propertiesgroup_propertiesrr   	resp_datas          rH   get_feature_variantsClient.get_feature_variants9  s.     ++!2m
	 #)r)rJ   c                 P    U R                  XX4U5      n[        U5      =(       d    0 $ )z@
Get feature flag payloads for a distinct_id by calling decide.
)r   r(   r   s          rH   get_feature_payloadsClient.get_feature_payloadsI  s.     ++!2m
	 9%++rJ   c                 >    U R                  XX4U5      n[        U5      $ )zE
Get feature flags and payloads for a distinct_id by calling decide.
)r   r'   )r   r   r   r   r   rr   resps          rH   get_feature_flags_and_payloads%Client.get_feature_flags_and_payloadsY  s)     &&!2m
 %T**rJ   c                    Uc
  [        5       n[        SU[        5        Uc  U R                  nU(       a  [        SU[        5        O0 nUUUUUS.n[        U R                  U R                  4SU R                  0UD6n[        U5      $ )zT
Get feature flags decision, using either flags() or decide() API based on rollout.
r   r   )r   r   r   r   geoip_disabler^   )
r   rb   r   rr   r   r   rV   rX   rl   r&   )r   r   r   r   r   rr   request_datar   s           rH   r   Client.get_flags_decisioni  s     13K{H5  ..MHfd+F '!2 0*
 LLII
 >>
 	
	 (	22rJ   c
                    Ub  [         R                  " S[        SS9  0 U=(       d    0 E[        5       EnSU;  a  [	        5       (       a  [	        5       US'   Uc
  [        5       n[        SU[        5        [        SU[        5        [        SU[        5        [        5       n
U
(       a#  U
R                  5       nUR                  U5        UnUUUUUS.nU(       a  [        S	U[        5        X|S   S
'   0 n0 nU(       a   U R                  XU	S9nO2U R"                  (       a!  US:w  a  U R%                  UU=(       d    0 U	SS9nU=(       d    0 R'                  5        H  u  nnUUSU 3'   M     U=(       d    0 R'                  5        VVs/ s H  u  nnUSLd  M  UPM     nnnU(       a  UUS'   U(       a  0 UEUS   EUS'   U R)                  X5      $ ! [         a(  nU R                  R!                  SU 35         S nANS nAff = fs  snnf )Nr   r   r   r   r   r   r   )r   r   r   r   r   r   z$groups)rr   z0[FEATURE FLAGS] Unable to get feature variants: $feature_flag_calledT)r   rr   only_evaluate_locally	$feature/Fz$active_feature_flags)r   r   r   rP   r   r   rb   r   r   r   r   collect_tagsupdater   r{   r   	exceptionr   get_all_flagsitemsr   )r   r   r   r   r   r   r   r   send_feature_flagsrr   current_contextcontext_tagsr   extra_propertiesfeature_variantsefeaturevariantr   valueactive_feature_flagss                        rH   captureClient.capture  s5    MM`" @)r?n.>?

*/E/G/G(>(@J}%13K{H5j$/-.0*779L
+%J %"&
 Hfd++1i(+-BD#'#<#<} $= $  E-C$C#11"+&*	  2   "2!7R > > @GW6=y	23 !A
 "2!7R > > @ 
 @eE!  @ 	  

  8L45 I#3 Is<7H IC}}S009  ""FqcJ " 
s$   >G HH
HG>>Hc                     Ub  [         R                  " S[        SS9  Uc
  [        5       nU=(       d    0 n[	        SU[
        5        [	        SU[        5        UUUSUS.nU R                  Xv5      $ )Nr   r   r   r   r   r   r   r   r   r   r   rb   r   r   r   r   s           rH   ro   
Client.set  sz     MM`" 13K%2
{H5j$/ #&
 }}S00rJ   c                     Ub  [         R                  " S[        SS9  Uc
  [        5       nU=(       d    0 n[	        SU[
        5        [	        SU[        5        UUUSUS.nU R                  Xv5      $ )Nr   r   r   r   r   	$set_once)r   r   r   r   r   r   r   s           rH   set_onceClient.set_once
  sz     MM`" 13K%2
{H5j$/ #&# 
 }}S00rJ   c	                 F   Ub  [         R                  " S[        SS9  U=(       d    0 n[        SU[        5        [        SU[        5        [        SU[
        5        U(       a  [        SU[        5        OSR                  X5      nS	UUUS
.UUUS.n	U R                  X5      $ )Nr   r   r   
group_type	group_keyr   r   z${}_{}z$groupidentify)z$group_type
$group_keyz
$group_set)r   r   r   r   r   )r   r   r   rb   r   r   formatr   )
r   r   r   r   r   r   r   rr   r   r   s
             rH   group_identifyClient.group_identify+  s     MM`"
  %2
j(3Y1j$/M;9"//*@K &)'(
 '"

 }}S00rJ   c                     Ub  [         R                  " S[        SS9  Uc
  [        5       n[	        SU[
        5        [	        SU[
        5        UUS.USUS.nU R                  Xv5      $ )	Nr   r   r   previous_idr   )r   aliasz$create_alias)r   r   r   r   )r   r   r   r   rb   r   r   )r   r   r   r   r   r   rr   r   s           rH   r   Client.aliasT  sw     MM`" 13K{H5{H5  +$ #$&
 }}S00rJ   c                 P   Ub  [         R                  " S[        SS9  Uc
  [        5       nU=(       d    0 n[	        SU[
        5        [	        SU[        5        SU;  a  [        5       (       a  [        5       US'   [	        SU[        5        X#S'   S	UUUUS
.nU R                  X5      $ )Nr   r   r   r   r   r   urlz$current_urlz	$pageview)r   r   r   r   r   )
r   r   r   r   rb   r   r   r   r   r   )	r   r   r   r   r   r   r   rr   r   s	            rH   pageClient.pagev  s     MM`" 13K%2
{H5j$/
*/E/G/G(>(@J}%sL)%(>" !$"&
 }}S00rJ   c           	         Ub  [         R                  " S[        SS9  Uc
  [        5       n U=(       d    0 nUb,  [	        U5      (       a  U R
                  R                  S5        g Uc  SUS'   [        5       n[        SU[        5        [        SU[        5        Ub  [        U5      n	O[        R                  " 5       n	U	b  U	S	:X  a  U R
                  R                  S
5        g [        U	5      n
[!        SSU
00U R"                  S9nUS   S   nUS   R%                  S5      US   R%                  S5      U['        U R(                  5       SU R*                   SU 3S.UEnU R,                  (       a  U R
                  R/                  XS9  U R1                  USX4XVU5      nUb  [3        U5        U$ ! [4         a(  nU R
                  R/                  SU 35         S nAg S nAff = f)Nr   r   r   z$Exception already captured, skippingFz$process_person_profiler   r   )NNNz"No exception information availabler   values)r|   r   typer   z	/project/z/person/)z$exception_typez$exception_messagez$exception_listz$exception_personURL)extraz
$exceptionzFailed to capture exception: )r   r   r   r   r   r   rc   r	   rb   r   r   r   r<   exc_infor   r   r   r|   r   r-   rf   rV   ru   r   r   r   r{   )r   r   r   r   r   r   r   r   kwargsr   all_exceptions_with_tracer   $all_exceptions_with_trace_and_in_appresr   s                  rH   capture_exceptionClient.capture_exception  s    MM`" 13K?	D#)rJ $)Fy)Q)QEF "8=
45#gM;9L*d3$.y9<<>8/A#A  !EF )DH(M% " ";"
 "..E 493Eh3O0 $H#J#N#Nv#V&J1&M&Q&Q' $H+@+O*PPYZ^ZfZfYggop{o|(} J ++""9";,,\:	QWC
 $*95J 	DHH!>qcBCC	Ds%   9F/ &A<F/ #CF/ /
G!9GG!c           	         U R                   (       a  gUS   nUc  [        R                  " [        5       S9n[	        SU[        5        [        U5      nUR                  5       US'   SU;   a&  UR                  S5      nU(       a  [        U5      US'   UR                  S5      (       d  0 US'   SUS   S'   [        US   S	'   Uc  U R                  nU(       a  S
US   S'   U R                  (       a  0 US   EU R                  EUS'   [        UR                  SS5      5      US'   [        U5      nU R                  (       a3   U R                  U5      nUc  U R                  R!                  S5        gUnU R                  R!                  SU5        U R&                  (       d  S
U4$ U R(                  (       ad  U R                  R!                  SUS   5        [+        U R,                  U R.                  U R0                  U R2                  U/U R4                  S9  S
U4$  U R6                  R9                  USS9  U R                  R!                  SUS   5        S
U4$ ! ["         a)  nU R                  R%                  SU 35         SnAGNSnAff = f! [6        R:                   a"    U R                  R=                  S5        SU4s $ f = f)z8Push a new `msg` onto the queue, return `(success, msg)`)Frq   r   Ntzr   r   zposthog-pythonz$libz$lib_versionTz$geoip_disabler   z%Event dropped by before_send callback)TNzError in before_send callback: zqueueing: %szenqueued with blocking %s.r   )r\   r^   batchr_   F)blockzenqueued %s.zanalytics-python queue is full)rq   r   nowr
   rb   r,   	isoformatpopstringify_idr   r.   rr   rs   r+   r   r   rc   r{   r   rd   re   r   rV   rX   r\   r^   r_   r`   putFullr   )r   r   rr   r   r   modified_msgr   s          rH   r   Client._enqueue  s    ==$$	 0IY1 #9-	$..0K S=776?D*40Fww|$$ "C$4L&!,3L.)  ..M26C./   N3|#4 N8M8M NC)#''-*FGMCjJ#//4'HHNN#JK%"
 	~s+ yy9>>HHNN7WF		YYe%)%>%> 9	JJNN3eN,HHNN>3w<895  J""%DQC#HIIJ6 zz 	HH=>#:	s0   /I 1I <J 
J
!JJ
3KKc                     U R                   nUR                  " 5       nUR                  " 5         U R                  R	                  SU5        g)z4Forces a flush from the internal queue to the serverz$successfully flushed about %s items.N)r`   qsizer   r   rc   )r   r`   sizes      rH   flushClient.flushD  s2    

{{}

=tDrJ   c                     U R                    H$  nUR                  5          UR                  5         M&     U R                  (       a  U R                  R                  5         gg! [         a     Mb  f = f)zREnds the consumer thread once the queue is empty.
Blocks execution until finished
N)r   pauser   RuntimeErrorrm   stop)r   r   s     rH   r   Client.joinL  s\     HNN ' ;;KK 	   s   A""
A0/A0c                     U R                  5         U R                  5         U R                  (       a  U R                  R                  5         gg)z2Flush all messages and cleanly shutdown the clientN)r  r   rw   closer   s    rH   shutdownClient.shutdown[  s4    

		!!""((* "rJ   c                     [        U R                  SU R                   S3U R                  SS9nUS   =(       d    / U l        US   =(       d    0 U l        US   =(       d    0 U l        [        R                   " [#        5       S9U l        g ! [         a  nUR                  S:X  a;  U R                  R                  S	5        U R                  (       a
  [        SS
S9e S nANwUR                  S:X  aP  U R                  R                  S5        / U l        0 U l        0 U l        U R                  (       a
  [        SSS9e S nANU R                  R                  SU 35         S nANS nAf[         aN  nU R                  R                  SU R                  -  5        U R                  R                  U5         S nAGNPS nAff = f)Nz*/api/feature_flag/local_evaluation/?token=z&send_cohorts
   r^   r   ri   rj   i  z[FEATURE FLAGS] Error loading feature flags: To use feature flags, please set a valid personal_api_key. More information: https://posthog.com/docs/api/overviewzYou are using a write-only key with feature flags. To use feature flags, please set a personal_api_key More information: https://posthog.com/docs/api/overview)statusmessagei  z[FEATURE FLAGS] PostHog feature flags quota limited, resetting feature flag data.  Learn more about billing limits at https://posthog.com/docs/billing/limits-alertsz#PostHog feature flags quota limitedz-[FEATURE FLAGS] Error loading feature flags: z`[FEATURE FLAGS] Fetching feature flags failed with following error. We will retry in %s seconds.r  )r   r}   rV   rX   r   ri   rj   r   r  r   errorrc   r   r{   rk   r   r  r
   _last_feature_flag_poll)r   responser   s      rH   _load_feature_flagsClient._load_feature_flagsc  s   -	 %%<T\\N-X			H "*'!2!8bD&./C&D&JD##I.4"DLJ (0||uw'?$G  	Txx3 v ::""!R   S   { &("*,'!::"" E   !NqcRSS 	 HHr$$% HHQ	 s3   A'B 
F>AE# AE# E##F>0AF99F>c                 v   U R                   (       d#  U R                  R                  S5        / U l        g U R	                  5         U R
                  (       a  U R
                  R                  5       (       dE  [        [        U R                  S9U R                  S9U l        U R
                  R                  5         g g )NzL[FEATURE FLAGS] You have to specify a personal_api_key to use feature flags.)seconds)intervalexecute)r}   r   r   r   r$  rm   is_aliver   r   rk   r   r   s    rH   load_feature_flagsClient.load_feature_flags  s    $$HH^ "$D  " 4 4 6 6 "4+=+=>00DK KK !7rJ   r   r   r   warn_on_unknown_groupsc                z   UR                  SS5      (       a  [        S5      eUR                  S5      (       d  gUR                  S5      =(       d    0 nUR                  S5      nUb  U R                  R                  [        U5      5      n	U	(       d/  U R                  R                  SU SUS	    35        [        S
5      eX;  aM  U(       a#  U R                  R                  SUS	    S35        gU R                  R                  SUS	    S35        gXY   n
[        XU	   U
5      $ [        XX@R                  5      $ )Nensure_experience_continuityFz&Flag has experience continuity enabledactivefiltersaggregation_group_type_indexz)[FEATURE FLAGS] Unknown group type index z for feature flag r   z!Flag has unknown group type indexz2[FEATURE FLAGS] Can't compute group feature flag: z without group names passed in)	r   r   ri   strr   r   rc   r   rj   )r   feature_flagr   r   r   r   r.  flag_filtersr3  
group_namefocused_group_propertiess              rH   _compute_flag_locallyClient._compute_flag_locally  so    :EBB()QRR))#''	28b'3'7'78V'W$'30044S9U5VWJ  ?@\?]]op|  ~C  qD  pE  F --PQQ' *HH$$L\Z_M`Laa  A  HHNNL\Z_M`Laa  A '7'C$0Z02J  1+<ll rJ   r   r   r   r   send_feature_flag_eventsrr   c                L    U R                  UUUUUUUUS9n	U	c  g [        U	5      $ )Nr;  )get_feature_flagbool)
r   r   r   r   r   r   r   r<  rr   r#  s
             rH   feature_enabledClient.feature_enabled  sF     ((/-"7%=' ) 	
 H~rJ   override_match_valuer   r   r   r   r<  rr   rC  c                &   [        SU[        5        [        SU[        5        [        SU[        5        U R                  (       a  g U R                  X$XV5      u  pVS n
S nS nU R                  XXEU5      nUS LnU(       a=  U=(       d    UnU(       a  U R                  X5      OS n[        R                  " XU5      n
OWU(       dP   U R                  UUUUUU	5      u  p[        R                  " X5      n
U R                  R                  SU SU
 35        U(       aC  U R!                  UUU
(       a  U
R#                  5       OS U
(       a  U
R$                  OS UUU	UU5	        U
$ ! [         a(  nU R                  R                  SU 35         S nANyS nAff = f)Nr   r   r   z&Successfully computed flag remotely: #z -> #z-[FEATURE FLAGS] Unable to get flag remotely: )rb   r   r   r   rq   &_add_local_person_and_group_properties_locally_evaluate_flag_compute_payload_locallyr!   from_value_and_payload%_get_feature_flag_details_from_decidefrom_flag_detailsr   rc   r{   r   _capture_feature_flag_called	get_valuepayload)r   r   r   rC  r   r   r   r   r<  rr   flag_resultflag_details
request_id
flag_valueflag_was_locally_evaluatedlookup_match_valuerM  r   s                     rH   _get_feature_flag_resultClient._get_feature_flag_result  s    	sL){H5&$'== 77%6 	, 
00f9I

 &0t%;"%!5!C & --cF 
 ,BBK 'X+/+U+U%$!,( 0AA  <SE{mT $--+6%%'D'2##*
 !  X""%RSTRU#VWWXs   AE 
F(FFc                .    U R                  UUUUUUUUS9$ )a,  
Get a FeatureFlagResult object which contains the flag result and payload for a key by evaluating locally or remotely
depending on whether local evaluation is enabled and the flag can be locally evaluated.

This also captures the $feature_flag_called event unless send_feature_flag_events is False.
r;  )rT  )	r   r   r   r   r   r   r   r<  rr   s	            rH   get_feature_flag_resultClient.get_feature_flag_resultA  s4    $ ,,/-"7%=' - 	
 		
rJ   c                `    U R                  UUUUUUUUS9n	U	(       a  U	R                  5       $ S$ )z
Get a feature flag value for a key by evaluating locally or remotely
depending on whether local evaluation is enabled and the flag can be
locally evaluated.

This also captures the $feature_flag_called event unless send_feature_flag_events is False.
r;  N)rW  rL  )
r   r   r   r   r   r   r   r<  rr   feature_flag_results
             rH   r>  Client.get_feature_flag^  sL    & #::/-"7%=' ; 	
 3F",,.O4OrJ   r   r   r   r   r   c                 6   U R                   c!  U R                  (       a  U R                  5         S nU R                   (       am  U R                  c   S5       eU R                  R	                  U5      nU(       a7   U R                  UUUUUS9nU R                  R                  SU SU 35        U$ U$ ! [         a,  nU R                  R                  SU SU 35         S nAU$ S nAf[         a)  nU R                  R                  SU 35         S nAU$ S nAff = f)Nr   r   r   r   z$Successfully computed flag locally: z -> zFailed to compute flag z
 locally: z7[FEATURE FLAGS] Error while computing variant locally: )r   r}   r+  rh   r   r9  r   rc   r   r{   r   )	r   r   r   r   r   r   r#  r   r   s	            rH   rF  Client._locally_evaluate_flag}  s/    %$*?*?##%,,8 V8 ,,005D#99#%*;)9  :  H HHNN>se4zR x . QHHNN%<SEA3#OPP
 	 ! HH&&QRSQTU  	s$   94B1 1
D;!C""D/DD)match_valuer   r   r   r   r<  rr   r_  c                Z    U R                  UUUUUUUUU	S9	n
U
(       a  U
R                  $ S $ )NrB  )rT  rM  )r   r   r   r_  r   r   r   r   r<  rr   rZ  s              rH   get_feature_flag_payloadClient.get_feature_flag_payload  sL     #;;!,/-"7%=' < 

 /B"**KtKrJ   rr   c                     U R                  X#XEU5      nUR                  S5      nUR                  S5      n	U	(       a  U	R                  " U5      OSn
X4$ )z;
Calls /decide and returns the flag details and request id
	requestIdr   N)r   r   )r   r   r   r   r   r   rr   r   rP  r   rO  s              rH   rI  ,Client._get_feature_flag_details_from_decide  sT     ++!2m
	 ]];/
g&).uyy~D''rJ   r#  rM  rR  rP  rO  c
                    U SUc  SO
[        U5       3n
U
U R                  U   ;  Ga6  SUSUSUSU 3U0nU(       a  XKS'   U(       a  XS'   [        U	[        5      (       a  U	R                  (       a4  U	R                  R
                  (       a  U	R                  R
                  US	'   [        U	R                  [        5      (       ah  U	R                  R                  (       a  U	R                  R                  US
'   U	R                  R                  (       a  U	R                  R                  US'   U R                  USUUUS9  U R                  U   R                  U
5        g g )N_z::null::z$feature_flagz$feature_flag_responselocally_evaluatedr   z$feature_flag_payloadz$feature_flag_request_idz$feature_flag_reasonz$feature_flag_versionz$feature_flag_idr   )r   rr   )r4  rp   
isinstancer    reasondescriptionmetadatar"   r8   idr   add)r   r   r   r#  rM  rR  r   rr   rP  rO  feature_flag_reported_keyr   s               rH   rK  #Client._capture_feature_flag_called  s_    e18#3ZXGH 	"
 &;;KHI  ((#%?C5!8	*J 6=239C56,44&&<+>+>+J+J9E9L9L9X9XJ56l33\BB#,,44(1199 ##:; $,,//9E9N9N9Q9Q
#56LL&+   44[AEE)EIrJ   c                 8   U R                   (       a  g U R                  c  U R                  R                  S5        g  [	        U R                  U R
                  UU R                  S9$ ! [         a(  nU R                  R                  SU 35         S nAg S nAff = f)Nz`[FEATURE FLAGS] You have to specify a personal_api_key to fetch decrypted feature flag payloads.r  z>[FEATURE FLAGS] Unable to get decrypted feature flag payload: )	rq   r}   r   r   r   rX   rl   r{   r   )r   r   r   s      rH   get_remote_config_payload Client.get_remote_config_payload  s    ==  (HHr 
	 %%		BB	   	HHPQRPST 	s   )A' '
B1BBc                 J   S nU R                   c  U$ U R                   R                  U5      nU(       ao  UR                  S5      =(       d    0 nUR                  S5      =(       d    0 n[        U[        5      (       a	  U(       a  SO
[	        U5      nUR                  US 5      nU$ )Nr2  payloadstrue)rh   r   ri  r?  r4  )r   r   r_  rM  flag_definitionr6  flag_payloadslookup_values           rH   rG  Client._compute_payload_locally  s     $$,N3377<*..y9?RL(,,Z8>BM
 k400[ % 
 $''d;GrJ   r   r   r   r   rr   c          	      4    U R                  UUUUUUS9nUS   $ )Nr{  featureFlags)get_all_flags_and_payloads)r   r   r   r   r   r   rr   r#  s           rH   r   Client.get_all_flags4  s8     22/-"7' 3 
 ''rJ   c                H   U R                   (       a  S S S.$ U R                  XX45      u  p4U R                  UUUUS9u  pxU(       a&  U(       d   U R                  UUUUUS9n	[	        U	5      $ U$ ! [
         a)  n
U R                  R                  SU
 35         S n
A
U$ S n
A
ff = f)Nr}  featureFlagPayloadsr]  )r   r   r   rr   z:[FEATURE FLAGS] Unable to get feature flags and payloads: )rq   rE  #_get_all_flags_and_payloads_locallyr   r'   r{   r   r   )r   r   r   r   r   r   rr   r#  fallback_to_decidedecide_responser   s              rH   r~  !Client.get_all_flags_and_payloadsI  s     ==$(FF 77%6 	, (,'O'O/-	 (P (
$ &;"&"9"9!&7%5"/ #: # -_==   ""PQRPST  s   A. .
B!8BB!c          
         [        SU[        5        [        SU[        5        U R                  c!  U R                  (       a  U R                  5         0 n0 nSnU R                  (       aX  U R                   HG  n	 U R                  U	UUUUUS9XiS   '   U R                  U	S   XiS      5      n
U
(       a	  XU	S   '   MG  MI     OSnUUS.U4$ ! [         a    Sn Md  [         a+  nU R                  R                  SU 35        Sn S nAM  S nAff = f)	Nr   r   Fr-  r   Tz;[FEATURE FLAGS] Error while computing variant and payload: r  )rb   r   r   r   r}   r+  r9  rG  r   r{   r   r   )r   r   r   r   r   r.  r   ru  r  r   matched_payloadr   s               rH   r  *Client._get_all_flags_and_payloads_locallyt  s;    	{H5&$'%$*?*?##%&(#%"**.)-)C)C#%*;)9/E *D *Eu+& '+&C&CUU;%7'O '0?e- ' +0 "& "#+
  	 . .)-&  .HH&&UVWUXY *.&	.s   8AC		D	D! DDc                     U R                   $ N)r   r   s    rH   feature_flag_definitionsClient.feature_flag_definitions  s    !!!rJ   c                     SU0U=(       d    0 En0 nU(       a+  U H%  nSX'   0UR                  U5      =(       d    0 EXg'   M'     XV4$ )Nr   r   )r   )r   r   r   r   r   all_person_propertiesall_group_propertiesr7  s           rH   rE  -Client._add_local_person_and_group_properties  si     ;!
 &B!

  "$
 &"44'++J7=24$0 % %::rJ   )!rg   r"  rV   r   rj   r   rc   rr   rq   rp   rt   rv   rw   r   rh   rl   ri   r\   r_   rX   ru   rY   r}   rk   rm   rx   r|   r`   rf   rd   rs   re   r^   )NNFi'  TNd   g      ?FrM   F         NNFTFrM   NFFNNFN)NNNNNN)NNNN)	NNNNNNNFN)NNNNNNNN)NNNNNNN):__name__
__module____qualname____firstlineno____doc__r~   	getLoggerr   r   propertyr   setterr   r   r4  r   r?  r   r   r#   r   r$   r   r   ro   r   r   r   r   r   r   r  r   r  r$  r+  r%   r9  r@  r   r!   rT  rW  r>  rF  ra  tupler    rI  rK  rr  rG  r   r~  r  r  rE  __static_attributes__ rJ   rH   rR   rR   x   s:   &


I
&C "./%* %+/9%B # # 
 
  #1P * 
c5s##	$*& , 
c3h,& + 
+& '3 
'3V  U1r 1F 1F '1V  1H &1T VDpL\E+0@d * #0 
0n #!%@ 59#!%M
 'y1M 
#	$Mh #!%
 
#	$
D #!%P 
)	P>$$ $ S#X	$
  S>$ sCx.$ 
)	$V ,0#!%L
 i(L4(( ( S#X	(
  S>( sCx.(  ~( 
x$hsm3	4((55 5 9%	5
 #5 %)5 S#X5  ~5 SM5 {+5nS ,%.	#4 #( 
$sE$),,-	.(2 #) 
)^ $1 
%	&1f";rJ   rR   c                 ^    [        X5      (       d  SR                  XU5      n[        U5      eg)z8Require that the named `field` has the right `data_type`z{0} must have {1}, got: {2}N)ri  r   AssertionError)namefield	data_typer   s       rH   rb   rb     s/    e''+224EJS!! (rJ   c                 N    U c  g [        U [        5      (       a  U $ [        U 5      $ r  )ri  r   r4  )vals    rH   r	  r	    s%    
{#|$$
s8OrJ   )Pr   r~   numbersry   r=   r<   r   r   r   typingr   r   r   r   r   r	   r@   dateutil.tzr
   sixr   posthog.consumerr   posthog.exception_capturer   posthog.exception_utilsr   r   r   r   r   posthog.feature_flagsr   r   posthog.pollerr   posthog.requestr   r   r   r   r   r   r   posthog.scopesr   r   r   posthog.typesr    r!   r"   r#   r$   r%   r&   r'   r(   r)   posthog.utilsr*   r+   r,   r-   posthog.versionr.   r`   ImportErrorra   Numberr   rn   rI   r   r4  rP   objectrR   rb   r	  r  rJ   rH   <module>r     s       	  
  ( ' '     % 6  X !   
   X W #
 NNL$/(VS#X B;V B;J*"U,  s   6C, ,
C98C9