
    hZ                         d dl Z d dlZd dlmZ d dlmZ dZd Z G d d      Z G d d	e      Z	 G d
 de      Z
 G d de      Z G d d      Z G d de      Z G d de      Zy)    N)InvalidQueryError)	transform)QQNodec                  @    d} t        j                  | t        d       y )NzD'empty' property is deprecated in favour of using 'not bool(filter)'   )
stacklevel)warningswarnDeprecationWarning)msgs    Z/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/mongoengine/queryset/visitor.pywarn_empty_is_deprecatedr   
   s    
PCMM#)a8    c                       e Zd ZdZd Zd Zy)QNodeVisitorz?Base visitor class for visiting Q-object nodes in a query tree.c                     |S )zCalled by QCombination objects. )selfcombinations     r   visit_combinationzQNodeVisitor.visit_combination   s    r   c                     |S )zCalled by (New)Q objects.r   r   querys     r   visit_queryzQNodeVisitor.visit_query   s    r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    Ir   r   c                       e Zd Zy)DuplicateQueryConditionsErrorN)r   r   r   r   r   r   r!   r!      s    r   r!   c                       e Zd ZdZd Zd Zy)SimplificationVisitorzgSimplifies query trees by combining unnecessary 'and' connection nodes
    into a single Q-object.
    c                    |j                   |j                  k(  rZt        d |j                  D              r>|j                  D cg c]  }|j                   }}	 t        di | j                  |      S |S c c}w # t        $ r Y |S w xY w)Nc              3   <   K   | ]  }t        |t                y wN)
isinstancer   ).0nodes     r   	<genexpr>z:SimplificationVisitor.visit_combination.<locals>.<genexpr>'   s     H4:dA&Hs   r   )	operationANDallchildrenr   r   _query_conjunctionr!   )r   r   nqueriess       r   r   z'SimplificationVisitor.visit_combination$   s      KOO3H;3G3GHH,7,@,@Aq177AA@t66w?@@  B 5 s   A6A; ;	BBc                    t               }i }|D ]m  }t        |j                               }|j                  |      }|r
t               |j	                  |       |j	                  t        j                  |             o |S )z4Merges query dicts - effectively &ing them together.)setkeysintersectionr!   updatecopydeepcopy)r   r1   	query_opscombined_queryr   opsr5   s          r   r/   z(SimplificationVisitor._query_conjunction0   sx    E	 		8Eejjl#C ++I6L355S!!!$--"67		8 r   N)r   r   r   r   r   r/   r   r   r   r#   r#      s    
r   r#   c                   "    e Zd ZdZd Zd Zd Zy)QueryCompilerVisitorzUCompiles the nodes in a query tree to a PyMongo-compatible query
    dictionary.
    c                     || _         y r&   )document)r   r?   s     r   __init__zQueryCompilerVisitor.__init__F   s	     r   c                 X    d}|j                   |j                  k(  rd}||j                  iS )Nz$andz$or)r+   ORr.   )r   r   operators      r   r   z&QueryCompilerVisitor.visit_combinationI   s/      KNN2H+..//r   c                 V    t        j                  | j                  fi |j                  S r&   )r   r   r?   r   s     r   r   z QueryCompilerVisitor.visit_queryO   s    t}}<<<r   N)r   r   r   r   r@   r   r   r   r   r   r=   r=   A   s    !0=r   r=   c                   F    e Zd ZdZdZdZd Zd Zd Ze	d        Z
d Zd	 Zy
)r   z$Base class for nodes in query trees.r      c                 l    | j                  t                     }|j                  t        |            }|S r&   )acceptr#   r=   )r   r?   r   s      r   to_queryzQNode.to_queryY   s-    1341(;<r   c                     t         r&   )NotImplementedErrorr   visitors     r   rH   zQNode.accept^   s    !!r   c                 R    t        |      s| S t        |       s|S t        || |g      S )zPCombine this node with another node into a QCombination
        object.
        )boolQCombination)r   otherr+   s      r   _combinezQNode._combinea   s/    
 E{K DzLIe}55r   c                     t                y)NF)r   r   s    r   emptyzQNode.emptyo   s     "r   c                 :    | j                  || j                        S r&   )rR   rB   r   rQ   s     r   __or__zQNode.__or__t   s    }}UDGG,,r   c                 :    | j                  || j                        S r&   )rR   r,   rW   s     r   __and__zQNode.__and__w   s    }}UDHH--r   N)r   r   r   r   r,   rB   rI   rH   rR   propertyrU   rX   rZ   r   r   r   r   r   S   s<    .
C	
B
"6  -.r   r   c                   >    e Zd ZdZd Zd Zd Zd Zed        Z	d Z
y)	rP   zVRepresents the combination of several conditions by a given
    logical operator.
    c                     || _         g | _        |D ]\  }t        |t              r/|j                   |k(  r | xj                  |j                  z  c_        B| j                  j	                  |       ^ y r&   )r+   r.   r'   rP   append)r   r+   r.   r)   s       r   r@   zQCombination.__init__   sZ    " 	+D $-$..I2M.$$T*	+r   c           	          | j                   | j                  u rdnd}d|j                  | j                  D cg c]  }t	        |       c}      z  S c c}w )Nz & z | z(%s))r+   r,   joinr.   repr)r   opr)   s      r   __repr__zQCombination.__repr__   sB    nn0Ue Fd FGGG Fs   A
c                 ,    t        | j                        S r&   )rO   r.   rT   s    r   __bool__zQCombination.__bool__   s    DMM""r   c                     t        t        | j                              D ]K  }t        | j                  |   t              s!| j                  |   j                  |      | j                  |<   M |j                  |       S r&   )rangelenr.   r'   r   rH   r   )r   rM   is      r   rH   zQCombination.accept   si    s4==)* 	DA$--*E2#'==#3#:#:7#Ca 	D ((..r   c                 B    t                t        | j                         S r&   )r   rO   r.   rT   s    r   rU   zQCombination.empty   s     "&&&r   c                     | j                   |j                   k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r&   )	__class__r+   r.   rW   s     r   __eq__zQCombination.__eq__   sA    NNeoo- 0%//10/	
r   N)r   r   r   r   r@   rc   re   rH   r[   rU   rm   r   r   r   rP   rP   {   s5    	+H#/ ' '
r   rP   c                   >    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
y)	r   z_A simple query object, used in a query tree to build up more complex
    query structures.
    c                     || _         y r&   )r   r   s     r   r@   z
Q.__init__   s	    
r   c                 2    dt        | j                        z  S )NzQ(**%s))ra   r   rT   s    r   rc   z
Q.__repr__   s    4

+++r   c                 ,    t        | j                        S r&   )rO   r   rT   s    r   re   z
Q.__bool__   s    DJJr   c                 j    | j                   |j                   k(  xr | j                  |j                  k(  S r&   )rl   r   rW   s     r   rm   zQ.__eq__   s'    ~~0NTZZ5;;5NNr   c                 $    |j                  |       S r&   )r   rL   s     r   rH   zQ.accept   s    ""4((r   c                 B    t                t        | j                         S r&   )r   rO   r   rT   s    r   rU   zQ.empty   s     "

###r   N)r   r   r   r   r@   rc   re   rm   rH   r[   rU   r   r   r   r   r      s5    , O) $ $r   r   )r7   r
   mongoengine.errorsr   mongoengine.querysetr   __all__r   r   r!   r#   r=   r   rP   r   r   r   r   <module>rx      so      0 *
9
	 		$5 	L D=< =$%. %.P(
5 (
V$ $r   