
    ,i                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZmZmZmZmZmZ d dlmZ ddlmZmZmZ e
rd dlmZ  ed      Zdd	Z ed
      Z ed      Z G d d      ZdddZddZ	 	 	 	 	 	 	 	 ddZ ddZ!d dZ"d!dZ#ejH                  d"d       Z%ejH                  d#d       Z&d$dZ'd%dZ(d&dZ)d'dZ*y)(    )annotationsN)TYPE_CHECKINGAnyDictUnionTypeVarIteratorNoReturn	Coroutine	find_spec   )CoroTypeFuncType	TypeGuard)r   _Tc                b    t         j                  j                  | d      j                         dv S )N >   1ttrue)osenvirongetlower)keys    Q/var/www/html/langgraph-service/venv/lib/python3.12/site-packages/prisma/utils.py	_env_boolr      s&    ::>>#r"((*.@@@    PRISMA_PY_DEBUGPRISMA_PY_DEBUG_GENERATORc                      e Zd ZddZy)	_NoneTypec                     y)NF )selfs    r   __bool__z_NoneType.__bool__   s    r   N)returnbool)__name__
__module____qualname__r'   r%   r   r   r#   r#      s    r   r#   c                N    t        t        j                         | z
  |      }| dS )Ns)roundtime	monotonic)start	precisiondeltas      r   
time_sincer5   "   s&    $.."U*I6EWA;r   c                 v    t         r3t        j                  d      j                  t        j                          y y )Nprisma)DEBUGlogging	getLoggersetLevelr%   r   r   setup_loggingr<   (   s'    (#,,W]]; r   c                J    t        |       rt         | |i |      S  | |i |S N)is_coroutine	async_run)funcargskwargss      r   maybe_async_runrD   -   s1    
 Dt.v.//   r   c                4    t               j                  |       S )z,Execute the coroutine and return the result.)get_or_create_event_looprun_until_complete)coros    r   r@   r@   7   s    #%88>>r   c                Z    t        j                  |       xs t        j                  |       S r>   )asyncioiscoroutinefunctioninspectisgeneratorfunctionobjs    r   r?   r?   <   s#    &&s+Ow/J/J3/OOr   c                    t        |       d uS r>   r   )names    r   module_existsrR   @   s    T?$&&r   c              #    K   t         j                  j                         }	 t         j                  j                  |        d  | D ]"  }t         j                  j	                  |d        $ t         j                  j                  |       y # | D ]"  }t         j                  j	                  |d        $ t         j                  j                  |       w xY wwr>   )r   r   copyupdatepop)envoldr   s      r   temp_env_updaterY   D   s     
**//
C


# 	&CJJNN3%	& 	

#  	&CJJNN3%	& 	

#s   C#B ACACCc              #     K   dfd}t        | |      	 t        | ||       d t        | |       y# t        | |       w xY ww)zTemporarily replace a method with a new funtion

    The previously set method is passed as the first argument to the new function
    c                      g| i |S r>   r%   )rB   rC   newrX   s     r   patchedzmonkeypatch.<locals>.patchedY   s    3((((r   N)rB   r   rC   r   r(   r   )getattrsetattr)rO   attrr\   r]   rX   s     ` @r   monkeypatchra   R   sF     ) #t
C T7#T3T3s   A
8 A
AA
c                 <   t        j                         5  t        j                  dt               	 t	        j
                         cddd       S # t        $ r7 t	        j                         } t	        j                  |        | cY cddd       S w xY w# 1 sw Y   yxY w)a  Return the currently set event loop or create a new event loop if there
    is no set event loop.

    Starting from python3.10, asyncio.get_event_loop() raises a DeprecationWarning
    when there is no event loop set, this deprecation will be enforced starting from
    python3.12

    This function serves as a future-proof wrapper over asyncio.get_event_loop()
    that preserves the old behaviour.
    ignore)categoryN)	warningscatch_warningsfilterwarningsDeprecationWarningrJ   get_event_loopRuntimeErrornew_event_loopset_event_loop)loops    r   rF   rF   e   s     
	 	 	" 3EF	))+	 
  	))+D""4(K 
	 s(   BA4BBBBBc                \    t        dj                  t        |       j                              )zkUsed by type checkers for exhaustive match cases.

    https://github.com/microsoft/pyright/issues/767
    zUnhandled type: {})AssertionErrorformattyper*   values    r   assert_neverrt   {   s%    
 -44T%[5I5IJ
KKr   c                    | S )zHelper function for type checkers to change the given type to include None.

    This is useful in cases where you do not have an explicit type for a symbol (e.g. modules)
    but want to mark it as potentially None.
    r%   rr   s    r   make_optionalrv      s	     Lr   c                "    t        | t              S r>   )
isinstancedictrN   s    r   is_dictrz      s    c4  r   )r   strr(   r)   )   )r2   floatr3   intr(   r{   )r(   None)rA   zUnion[FuncType, CoroType]rB   r   rC   r   r(   object)rH   zCoroutine[Any, Any, _T]r(   r   )rO   r   r(   zTypeGuard[CoroType])rQ   r{   r(   r)   )rW   zDict[str, str]r(   zIterator[None])rO   r   r`   r{   r\   r   r(   r   )r(   zasyncio.AbstractEventLoop)rs   r
   r(   r
   )rs   r   r(   z	_T | None)rO   r   r(   zTypeGuard[dict[object, object]])+
__future__r   r   r0   rJ   rL   r9   re   
contextlibtypingr   r   r   r   r   r	   r
   r   importlib.utilr   _typesr   r   r   typing_extensionsr   r   r8   DEBUG_GENERATORr#   r5   r<   rD   r@   r?   rR   contextmanagerrY   ra   rF   rt   rv   rz   r%   r   r   <module>r      s    " 	       Z Z Z $ 1 1+T]A 	#$78 
<
!
#!! ! 	!?
P' 
 
    $,L!r   