
    W
hZ                         S SK r S SKrS SKJr  S SKJr  SrS r " S S5      r " S S	\5      r	 " S
 S\5      r
 " S S\5      r " S S5      r " S S\5      r " S S\5      rg)    N)InvalidQueryError)	transform)QQNodec                  <    Sn [         R                  " U [        SS9  g )NzD'empty' property is deprecated in favour of using 'not bool(filter)'   )
stacklevel)warningswarnDeprecationWarning)msgs    dC:\Users\julio\Documents\inmuebles-mzt\backend\env\Lib\site-packages\mongoengine/queryset/visitor.pywarn_empty_is_deprecatedr   
   s    
PCMM#)a8    c                   $    \ rS rSrSrS rS rSrg)QNodeVisitor   z?Base visitor class for visiting Q-object nodes in a query tree.c                     U$ )zCalled by QCombination objects. )selfcombinations     r   visit_combinationQNodeVisitor.visit_combination   s    r   c                     U$ )zCalled by (New)Q objects.r   r   querys     r   visit_queryQNodeVisitor.visit_query   s    r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__r   r   r   r   r      s    Ir   r   c                       \ rS rSrSrg)DuplicateQueryConditionsError   r   N)r   r    r!   r"   r$   r   r   r   r&   r&      s    r   r&   c                   $    \ rS rSrSrS rS rSrg)SimplificationVisitor   z_Simplifies query trees by combining unnecessary 'and' connection nodes
into a single Q-object.
c                 (   UR                   UR                  :X  aa  [        S UR                   5       5      (       a@  UR                   Vs/ s H  o"R                  PM     nn [        S0 U R                  U5      D6$ U$ s  snf ! [         a     U$ f = f)Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancer   ).0nodes     r   	<genexpr>:SimplificationVisitor.visit_combination.<locals>.<genexpr>'   s     H3G4:dA&&3Gs   r   )	operationANDallchildrenr   r   _query_conjunctionr&   )r   r   nqueriess       r   r   'SimplificationVisitor.visit_combination$   s      KOO3H;3G3GHHH,7,@,@A,@q77,@A@t66w?@@  B 5 s   
A>"B 
BBc                    [        5       n0 nU Ht  n[        UR                  5       5      nUR                  U5      nU(       a
  [        5       eUR	                  U5        UR	                  [
        R                  " U5      5        Mv     U$ )z4Merges query dicts - effectively &ing them together.)setkeysintersectionr&   updatecopydeepcopy)r   r9   	query_opscombined_queryr   opsr>   s          r   r7   (SimplificationVisitor._query_conjunction0   ss    E	Eejjl#C ++I6L355S!!!$--"67  r   r   N)r   r    r!   r"   r#   r   r7   r$   r   r   r   r)   r)      s    
r   r)   c                   *    \ rS rSrSrS rS rS rSrg)QueryCompilerVisitorA   zMCompiles the nodes in a query tree to a PyMongo-compatible query
dictionary.
c                     Xl         g r-   document)r   rK   s     r   __init__QueryCompilerVisitor.__init__F   s     r   c                 X    SnUR                   UR                  :X  a  SnX!R                  0$ )Nz$andz$or)r3   ORr6   )r   r   operators      r   r   &QueryCompilerVisitor.visit_combinationI   s-      KNN2H..//r   c                 X    [         R                  " U R                  40 UR                  D6$ r-   )r   r   rK   r   s     r   r    QueryCompilerVisitor.visit_queryO   s    t}}<<<r   rJ   N)	r   r    r!   r"   r#   rL   r   r   r$   r   r   r   rG   rG   A   s    !0=r   rG   c                   N    \ rS rSrSrSrSrS rS rS r	\
S 5       rS	 rS
 rSrg)r   S   z$Base class for nodes in query trees.r      c                 l    U R                  [        5       5      nUR                  [        U5      5      nU$ r-   )acceptr)   rG   )r   rK   r   s      r   to_queryQNode.to_queryY   s-    1341(;<r   c                     [         er-   )NotImplementedErrorr   visitors     r   rX   QNode.accept^   s    !!r   c                 d    [        U5      (       d  U $ [        U 5      (       d  U$ [        X U/5      $ )z@Combine this node with another node into a QCombination
object.
)boolQCombination)r   otherr3   s      r   _combineQNode._combinea   s1    
 E{{K DzzLIe}55r   c                     [        5         g)NF)r   r   s    r   emptyQNode.emptyo   s     "r   c                 8    U R                  XR                  5      $ r-   )rd   rO   r   rc   s     r   __or__QNode.__or__t   s    }}UGG,,r   c                 8    U R                  XR                  5      $ r-   )rd   r4   rk   s     r   __and__QNode.__and__w   s    }}UHH--r   r   N)r   r    r!   r"   r#   r4   rO   rY   rX   rd   propertyrh   rl   ro   r$   r   r   r   r   r   S   s<    .
C	
B
"6  -.r   r   c                   F    \ rS rSrSrS rS rS rS r\	S 5       r
S rS	rg
)rb   {   zNRepresents the combination of several conditions by a given
logical operator.
c                     Xl         / U l        U Hd  n[        U[        5      (       a1  UR                   U:X  a!  U =R                  UR                  -  sl        MI  U R                  R	                  U5        Mf     g r-   )r3   r6   r.   rb   append)r   r3   r6   r0   s       r   rL   QCombination.__init__   sV    "D $--$..I2M.$$T* r   c           	          U R                   U R                  L a  SOSnSUR                  U R                   Vs/ s H  n[	        U5      PM     sn5      -  $ s  snf )Nz & z | z(%s))r3   r4   joinr6   repr)r   opr0   s      r   __repr__QCombination.__repr__   sF    nn0Ue Fd FGGG Fs   A
c                 ,    [        U R                  5      $ r-   )ra   r6   rg   s    r   __bool__QCombination.__bool__   s    DMM""r   c                    [        [        U R                  5      5       HR  n[        U R                  U   [        5      (       d  M'  U R                  U   R                  U5      U R                  U'   MT     UR                  U 5      $ r-   )rangelenr6   r.   r   rX   r   )r   r^   is      r   rX   QCombination.accept   se    s4==)*A$--*E22#'==#3#:#:7#Ca  + ((..r   c                 J    [        5         [        U R                  5      (       + $ r-   )r   ra   r6   rg   s    r   rh   QCombination.empty   s     "&&&r   c                     U R                   UR                   :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r-   )	__class__r3   r6   rk   s     r   __eq__QCombination.__eq__   sA    NNeoo- 0%//10/	
r   )r6   r3   N)r   r    r!   r"   r#   rL   r{   r~   rX   rq   rh   r   r$   r   r   r   rb   rb   {   s5    	+H#/ ' '
r   rb   c                   F    \ rS rSrSrS rS rS rS rS r	\
S 5       rS	rg
)r      zWA simple query object, used in a query tree to build up more complex
query structures.
c                     Xl         g r-   r   r   s     r   rL   
Q.__init__   s    
r   c                 2    S[        U R                  5      -  $ )NzQ(**%s))ry   r   rg   s    r   r{   
Q.__repr__   s    4

+++r   c                 ,    [        U R                  5      $ r-   )ra   r   rg   s    r   r~   
Q.__bool__   s    DJJr   c                 t    U R                   UR                   :H  =(       a    U R                  UR                  :H  $ r-   )r   r   rk   s     r   r   Q.__eq__   s'    ~~0NTZZ5;;5NNr   c                 $    UR                  U 5      $ r-   )r   r]   s     r   rX   Q.accept   s    ""4((r   c                 J    [        5         [        U R                  5      (       + $ r-   )r   ra   r   rg   s    r   rh   Q.empty   s     "

###r   r   N)r   r    r!   r"   r#   rL   r{   r~   r   rX   rq   rh   r$   r   r   r   r   r      s5    , O) $ $r   r   )r@   r
   mongoengine.errorsr   mongoengine.querysetr   __all__r   r   r&   r)   rG   r   rb   r   r   r   r   <module>r      so      0 *
9
	 		$5 	L D=< =$%. %.P(
5 (
V$ $r   