
    g                         d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZ d dlZd dlmZmZ  e j                   d      Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZdefdZ G d de      Zd Zy)    N)defaultdict)datedatetimetimezone)Decimal)UUID)tzlocaltzutcposthogc                 \    | j                   du xs | j                   j                  |       du S )z1Determines if a given datetime.datetime is naive.N)tzinfo	utcoffset)dts    B/var/www/openai/venv/lib/python3.12/site-packages/posthog/utils.pyis_naiver      s*    99?		 3 3B 74 ??    c                 f    | j                   | j                  | j                  dz  dz  z   dz  z   dz  S )z2Determines total seconds with python < 2.7 compat.   i  g    .A)microsecondssecondsdays)deltas    r   total_secondsr      s6     %--%**r/D2H"HC!OOSVVVr   c                     t        |       rYt        j                         | z
  }t        |      dk  r| j	                  t                     S | j	                  t                     S | S )z:Attempts to convert a naive datetime to an aware datetime.   r   )r   r   nowr   replacer	   r
   )r   r   s     r   guess_timezoner      sW    | #!# ::WY:// ::UW:--Ir   c                 2    | j                  d      r| d d S | S )N/)endswith)hosts    r   remove_trailing_slashr%   +   s    }}SCRyKr   c                    t        | t              rt        |       S t        | t              rt	        |       S t        | t
        j                  t        t        j                  t        t        t        d       f      r| S t        | t        t        t        f      rt!        |       S 	 t#        | d      r&t%        | j&                        r| j'                         } n1t#        | d      r%t%        | j(                        r| j)                         } t        | t(              rt1        |       S t3        |       S # t*        $ r"}t,        j/                  d|        Y d }~Ld }~ww xY w)N
model_dumpdictz)Could not serialize Pydantic-like model: )
isinstancer   floatr   strsixstring_typesboolnumbersNumberr   r   typesetlisttuple_clean_listhasattrcallabler'   r(   	TypeErrorlogdebug_clean_dict_coerce_unicode)itemes     r   cleanr?   1   s   $ T{$4y$))44QUVZQ[\]$dE*+4  	4&8DOO+D??$DT6"x		':99;D $4  4    		=aSABs   #A#D, ,	E5EEc                 >    | D cg c]  }t        |       c}S c c}w N)r?   )list_r=   s     r   r5   r5   J   s    $)*EDE$KE***s   c           
          i }t        j                  |       D ]  \  }}	 t        |      ||<    |S # t        $ r$ t        j                  d||t        |             Y Ew xY w)NzXDictionary values must be serializeable to JSON "%s" value %s of type %s is unsupported.)r,   	iteritemsr?   r8   r9   warningr1   )dict_datakvs       r   r;   r;   N   sd    De$1	AhDG % K  	KKjQ		s   1*AAc                     	 | j                  dd      }|S # t        $ rC}dj                  |      }|j                  dd       t        j	                  d|       Y d }~y d }~ww xY w)Nzutf-8strict:zError decoding: %s)decodeAttributeErrorjoinr9   rE   )cmplxr=   	exceptions      r   r<   r<   ]   s^    ||GX. K  xx	"GX&($/	s    	A"9AA"returnc                 b    	 t        j                  |        y# t         j                  $ r Y yw xY w)NTF)recompileerror)values    r   is_valid_regexrX   h   s,    


588 s    ..c                   (     e Zd Z fdZ fdZ xZS )SizeLimitedDictc                 2    t        |   |i | || _        y rA   )super__init__max_size)selfr^   argskwargs	__class__s       r   r]   zSizeLimitedDict.__init__q   s    $)&) r   c                 v    t        |       | j                  k\  r| j                          t        |   ||       y rA   )lenr^   clearr\   __setitem__)r_   keyrW   rb   s      r   rf   zSizeLimitedDict.__setitem__u   s+    t9%JJLC'r   )__name__
__module____qualname__r]   rf   __classcell__)rb   s   @r   rZ   rZ   p   s    !( (r   rZ   c                 ^    | j                    | j                  t        j                        } | S )Nr   )r   r   r   utc)date_objs    r   convert_to_datetime_awarero   |   s(    ##8<<#8Or   )loggingr/   rT   collectionsr   r   r   r   decimalr   uuidr   r,   dateutil.tzr	   r
   	getLoggerr9   r   r   r   r%   r?   r5   r;   r<   r.   rX   rZ   ro    r   r   <module>rw      s|      	 # - -   
 &g	"@
W"!2+T 	(k 	(r   