
    g                        d dl mZmZmZmZmZ dZdZ G d de      Z	 G d de      Z
 G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      ZdedefdZdedefdZdeee      dee   fdZdedee   defdZ	 	 	 d)dedee   dee   d ee   d!ed"edefd#Zddd$d%ed&ee   d'ee   ddfd(Zy)*    )AnyCallableListOptionalTypezTimothy Heysztheys@kayak.comc                       e Zd Zy)QueryExceptionN__name__
__module____qualname__     A/var/www/openai/venv/lib/python3.12/site-packages/pypika/utils.pyr	   r	          r   r	   c                       e Zd Zy)GroupingExceptionNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)CaseExceptionNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)JoinExceptionNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)SetOperationExceptionNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)RollupExceptionNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)DialectNotSupportedNr
   r   r   r   r   r      r   r   r   c                       e Zd Zy)FunctionExceptionNr
   r   r   r   r   r   #   r   r   r   funcreturnc                      ddl  fd}|S )a  
    Decorator for wrapper "builder" functions.  These are functions on the Query class or other classes used for
    building queries which mutate the query and return self.  To make the build functions immutable, this decorator is
    used which will deepcopy the current instance.  This decorator will return the return value of the inner function
    or the new copy of the instance.  The inner function does not need to return self.
    r   Nc                 h    t        | dd      rj                  |       n| } |g|i |}||S |S )N	immutableT)getattrcopy)selfargskwargs	self_copyresultr&   r    s        r   _copyzbuilder.<locals>._copy0   sC    '.t[$'GDIIdOT	i1$1&1 >r   )r&   )r    r,   r&   s   ` @r   builderr-   '   s     	 Lr   c                       fd}|S )a  
    Decorator for wrapping the __getattr__ function for classes that are copied via deepcopy.  This prevents infinite
    recursion caused by deepcopy looking for magic functions in the class. Any class implementing __getattr__ that is
    meant to be deepcopy'd should use this decorator.

    deepcopy is used by pypika in builder functions (decorated by @builder) to make the results immutable.  Any data
    model type class (stored in the Query instance) is copied.
    c                 j    |dv r&t        d| j                  j                  d|d       | |      S )N)__copy____deepcopy____getstate____setstate____getnewargs__'z' object has no attribute ')AttributeError	__class__r   )r'   namer    s     r   _getattrzignore_copy.<locals>._getattrH   s:     
 
 !H_H_ae!fggD$r   r   )r    r9   s   ` r   ignore_copyr:   >   s    
  Or   valuesc                 L    | D cg c]  }||	 }}|rt        |      S yc c}w )a  
    Resolves the is_aggregate flag for an expression that contains multiple terms.  This works like a voter system,
    each term votes True or False or abstains with None.

    :param values: A list of booleans (or None) for each term in the expression
    :return: If all values are True or None, True is returned.  If all values are None, None is returned. Otherwise,
        False is returned.
    N)all)r;   xr+   s      r   resolve_is_aggregater?   W   s1      1A1=aF16{ 2s   !!value
quote_charc                 0    dj                  | |xs d      S )Nz{quote}{value}{quote} )r@   quote)format)r@   rA   s     r   format_quotesrF   f   s    "))Z=M2)NNr   Nsqlaliasalias_quote_char
as_keywordr)   c           	      V    || S dj                  | |rdndt        ||xs |            S )Nz{sql}{_as}{alias}z AS  )rG   _asrH   )rE   rF   )rG   rH   rA   rI   rJ   r)   s         r   format_alias_sqlrN   j   s?     }
%%zVs-O_Omcm:n &  r   )exctyper(   rO   rP   c                 4    ||D ]  }t        ||      r|  y y )N)
isinstance)rO   rP   r(   args       r   validaterT   y   s&    Cc4(	  r   )NNF)typingr   r   r   r   r   
__author__	__email__	Exceptionr	   r   r   r   r   r   r   r   r-   r:   boolr?   strrF   rN   rT   r   r   r   <module>r[      sn   6 6
		Y 			 		I 		I 		I 		i 		) 			 	( x .h 8 2htn!5 (4. O O(3- OC O !%&*	C=  sm	
   	 59QU C hy1  Z^ r   