
    =wgH                     4   d dl Z d dlZd dlmZ d dlmZmZm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 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 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 d0 d1e      Zd2 Z y)3    N)query)get_single_textQueryParserErrorattachc                   v    e Zd ZdZdZdZdZdZd Zd Z	d Z
d Zd Zd	 Zd
 ZddZd Zd Zd Zd Zd Zd Zy)
SyntaxNodea  Base class for nodes that make up the abstract syntax tree (AST) of a
    parsed user query string. The AST is an intermediate step, generated
    from the query string, then converted into a :class:`whoosh.query.Query`
    tree by calling the ``query()`` method on the nodes.

    Instances have the following required attributes:

    ``has_fieldname``
        True if this node has a ``fieldname`` attribute.
    ``has_text``
        True if this node has a ``text`` attribute
    ``has_boost``
        True if this node has a ``boost`` attribute.
    ``startchar``
        The character position in the original text at which this node started.
    ``endchar``
        The character position in the original text at which this node ended.
    FNc                     d}| j                   r|d| j                  z  z  }|| j                         z  }| j                  r!| j                  dk7  r|d| j                  z  z  }|dz  }|S )N<z%r:      ?z ^%s>)has_fieldname	fieldnamer	has_boostboost)selfr   s     L/var/www/horilla/myenv/lib/python3.12/site-packages/whoosh/qparser/syntax.py__repr__zSyntaxNode.__repr__;   se    ''A	TVVX>>djjC/$**$$A	S    c                 L    | j                   j                  d| j                  S )zReturns a basic representation of this node. The base class's
        ``__repr__`` method calls this, then does the extra busy work of adding
        fieldname and boost where appropriate.
         )	__class____name____dict__r   s    r   r   zSyntaxNode.rE   s     ..114==AAr   c                     | S N )r   fns     r   applyzSyntaxNode.applyM   s    r   c                 "    fd |       S )Nc                 2     | j                              S r   )r    )nr   
fn_wrappers    r   r$   z%SyntaxNode.accept.<locals>.fn_wrapperQ   s    aggj)**r   r   )r   r   r$   s    `@r   acceptzSyntaxNode.acceptP   s    	+ $r   c                 @    t        | j                  j                        )zgReturns a :class:`whoosh.query.Query` instance corresponding to this
        syntax tree node.
        )NotImplementedErrorr   r   )r   parsers     r   r   zSyntaxNode.queryV   s    
 "$.."9"9::r   c                      y)z;Returns True if this node is ignorable whitespace.
        Fr   r   s    r   is_wszSyntaxNode.is_ws]   s     r   c                      y)NFr   r   s    r   is_textzSyntaxNode.is_textc   s    r   c                 J    | j                   sy| j                  |r|| _        | S )a  Sets the fieldname associated with this node. If ``override`` is
        False (the default), the fieldname will only be replaced if this node
        does not already have a fieldname set.

        For nodes that don't have a fieldname, this is a no-op.
        N)r   r   )r   nameoverrides      r   set_fieldnamezSyntaxNode.set_fieldnamef   s(     !!>>!X!DNr   c                 .    | j                   sy|| _        | S )zoSets the boost associated with this node.

        For nodes that don't have a boost, this is a no-op.
        N)r   r   )r   r   s     r   	set_boostzSyntaxNode.set_boostu   s     ~~
r   c                 "    || _         || _        | S )z<Sets the character range associated with this node.
        )	startcharendchar)r   r4   r5   s      r   	set_rangezSyntaxNode.set_range   s     #r   c                 <    | j                   r| j                         S y r   )_parentr   s    r   parentzSyntaxNode.parent   s    <<<<>! r   c                 J    | j                         }|r|j                  |       S y r   )r9   
node_afterr   ps     r   next_siblingzSyntaxNode.next_sibling   s$    KKM<<%% r   c                 J    | j                         }|r|j                  |       S y r   )r9   node_beforer<   s     r   prev_siblingzSyntaxNode.prev_sibling   s$    KKM==&& r   c                 8    t        j                  |      | _        y r   )weakrefrefr8   )r   r9   s     r   bakezSyntaxNode.bake   s    {{6*r   F)r   
__module____qualname____doc__r   has_textr   r8   r   r   r    r%   r   r*   r,   r0   r2   r6   r9   r>   rA   rE   r   r   r   r   r   "   sd    & MHIGB ;	"&
'
+r   r   c                       e Zd ZdZd Zy)
MarkerNodezEBase class for nodes that only exist to mark places in the tree.
    c                 .    | j                   j                  S r   )r   r   r   s    r   r   zMarkerNode.r   s    ~~&&&r   N)r   rG   rH   rI   r   r   r   r   rL   rL      s    'r   rL   c                       e Zd ZdZd Zd Zy)
Whitespacez8Abstract syntax tree node for ignorable whitespace.
    c                      yNr   r   r   s    r   r   zWhitespace.r   s    r   c                      yNTr   r   s    r   r*   zWhitespace.is_ws       r   N)r   rG   rH   rI   r   r*   r   r   r   rO   rO      s    r   rO   c                        e Zd ZdZdZd Zd Zy)FieldnameNodez:Abstract syntax tree node for field name assignments.
    Tc                      || _         || _        y r   )r   original)r   r   rX   s      r   __init__zFieldnameNode.__init__   s    " r   c                      d| j                   z  S )Nz<%r:>)r   r   s    r   r   zFieldnameNode.__repr__   s    ''r   N)r   rG   rH   rI   r   rY   r   r   r   r   rV   rV      s     M!(r   rV   c                       e Zd ZdZdZdZdZddZd Ze	d        Z
e	d        Zd Zd	 Zd
 ZddZd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z y)	GroupNodea  Base class for abstract syntax tree node types that group together
    sub-nodes.

    Instances have the following attributes:

    ``merging``
        True if side-by-side instances of this group can be merged into a
        single group.
    ``qclass``
        If a subclass doesn't override ``query()``, the base class will simply
        wrap this class around the queries returned by the subnodes.

    This class implements a number of list methods for operating on the
    subnodes.
    TNc                 6    |xs g | _         || _        || _        y r   )nodesr   kwargs)r   r^   r   r_   s       r   rY   zGroupNode.__init__   s    [b

r   c                 x    | j                   j                  ddj                  d | j                  D              S )Nr   z, c              3   2   K   | ]  }t        |        y wr   )repr).0r#   s     r   	<genexpr>zGroupNode.r.<locals>.<genexpr>   s     #@DG#@s   )r   r   joinr^   r   s    r   r   zGroupNode.r   s1    ..11))#@TZZ#@@B 	Br   c                 N    | j                   sy | j                   d   j                  S Nr   )r^   r4   r   s    r   r4   zGroupNode.startchar   s     zzzz!}&&&r   c                 N    | j                   sy | j                   d   j                  S )N)r^   r5   r   s    r   r5   zGroupNode.endchar   s     zzzz"~%%%r   c           	           | j                   | j                  | j                  D cg c]
  } ||       c}fd| j                  i| j                  S c c}w Nr   )r   typer^   r   r_   )r   r   nodes      r   r    zGroupNode.apply   sK    t~~diitzz)Jt"T()J ?$(JJ?26++? 	?)Js   A
c                     g }| j                   D ]'  }|j                  |      }||j                  |       )  | j                  |fd| j                  i| j
                  }t        ||       S rk   )r^   r   appendqclassr   r_   r   )r   r(   subsrm   subqqs         r   r   zGroupNode.query   sj    JJ 	"D::f%DD!	"
 DKK>DJJ>$++>ar   c                      | j                   di | j                  }| j                  r| j                  |_        | j                  r| j
                  |_        | j                  r| j                  |_        |S )a  Returns an empty copy of this group.

        This is used in the common pattern where a filter creates an new
        group and then adds nodes from the input group to it if they meet
        certain criteria, then returns the new group::

            def remove_whitespace(parser, group):
                newgroup = group.empty_copy()
                for node in group:
                    if not node.is_ws():
                        newgroup.append(node)
                return newgroup
        r   )r   r_   r   r   r   r   rJ   text)r   cs     r   
empty_copyzGroupNode.empty_copy   sX     DNN)T[[)>>jjAG..AK==YYAFr   c                 |    t         j                  | ||       | j                  D ]  }|j                  ||        y )N)r/   )r   r0   r^   )r   r.   r/   rm   s       r   r0   zGroupNode.set_fieldname  s=      th ?JJ 	8Dth7	8r   c                 L    | j                   D ]  }|j                  ||        | S r   )r^   r6   )r   r4   r5   rm   s       r   r6   zGroupNode.set_range  s(    JJ 	/DNN9g.	/r   c                 ,    t        | j                        S r   )boolr^   r   s    r   __nonzero__zGroupNode.__nonzero__      DJJr   c                 ,    t        | j                        S r   )iterr^   r   s    r   __iter__zGroupNode.__iter__  r}   r   c                 ,    t        | j                        S r   )lenr^   r   s    r   __len__zGroupNode.__len__!  s    4::r   c                 8    | j                   j                  |      S r   )r^   __getitem__r   r#   s     r   r   zGroupNode.__getitem__$  s    zz%%a((r   c                 <    | j                   j                  ||       y r   )r^   __setitem__r   r#   vs      r   r   zGroupNode.__setitem__'  s    

q!$r   c                 :    | j                   j                  |       y r   )r^   __delitem__r   s     r   r   zGroupNode.__delitem__*  s    

q!r   c                 <    | j                   j                  ||       y r   )r^   insertr   s      r   r   zGroupNode.insert-  s    

!Qr   c                 :    | j                   j                  |       y r   )r^   ro   r   r   s     r   ro   zGroupNode.append0  s    

!r   c                 :    | j                   j                  |       y r   )r^   extend)r   vss     r   r   zGroupNode.extend3  s    

"r   c                 :     | j                   j                  |i |S r   )r^   pop)r   argsr_   s      r   r   zGroupNode.pop6  s    tzz~~t.v..r   c                 8    | j                   j                          y r   )r^   reverser   s    r   r   zGroupNode.reverse9  s    

r   c                 8    | j                   j                  |      S r   )r^   indexr   s     r   r   zGroupNode.index<  s    zz""r   c                 t    t         j                  | |       | j                  D ]  }|j                  |         y r   )r   rE   r^   )r   r9   rm   s      r   rE   zGroupNode.bakeA  s.    f%JJ 	DIIdO	r   c                     	 | j                   j                  |      }|dkD  r| j                   |dz
     S y # t        $ r Y y w xY wNr      )r^   r   
ValueErrorr   r#   is      r   r@   zGroupNode.node_beforeF  sP    	

  #A q5::a!e$$   		s   5 	A Ac                     	 | j                   j                  |      }|t        | j                         dz
  k  r| j                   |dz      S y # t        $ r Y y w xY w)N   r   )r^   r   r   r   r   s      r   r;   zGroupNode.node_afterN  s^    	

  #A s4::""::a!e$$ #  		s   A 	AANr   rF   )!r   rG   rH   rI   r   mergingrp   rY   r   propertyr4   r5   r    r   rw   r0   r6   r|   __bool__r   r   r   r   r   r   ro   r   r   r   r   rE   r@   r;   r   r   r   r\   r\      s      IGF
B ' '
 & &
?08
  H )%" /#

%%r   r\   c                       e Zd ZdZdZdZd Zy)BinaryGroupzIntermediate base class for group nodes that have two subnodes and
    whose ``qclass`` initializer takes two arguments instead of a list.
    Fc                    t        | j                        dk(  sJ | j                  d   j                  |      }| j                  d   j                  |      }||t        j                  }nT||}nO||}nJ| j	                  | j                  d   j                  |      | j                  d   j                  |            }t        ||       S )Nr   r   r   )r   r^   r   	NullQueryrp   r   )r   r(   qaqbrs   s        r   r   zBinaryGroup.query_  s    4::!###ZZ]  (ZZ]  (:"*AZAZADJJqM//7 JJqM//79A ar   N)r   rG   rH   rI   r   r   r   r   r   r   r   r   W  s     GIr   r   c                       e Zd ZdZdZd Zy)WrapperzCIntermediate base class for nodes that wrap a single sub-node.
    Fc                 z    | j                   d   j                  |      }|rt        | j                  |      |       S y rg   )r^   r   r   rp   r   r(   rs   s      r   r   zWrapper.queryw  s7    JJqM'$++a.$// r   N)r   rG   rH   rI   r   r   r   r   r   r   r   q  s     G0r   r   c                   @    e Zd ZddZd Zed        Zed        Zd Zy)	ErrorNodeNc                      || _         || _        y r   )messagerm   )r   r   rm   s      r   rY   zErrorNode.__init__~  s    	r   c                 :    d| j                   d| j                  S )NzERR r   )rm   r   r   s    r   r   zErrorNode.r  s    "ii66r   c                 .    | j                   j                  S r   )rm   r4   r   s    r   r4   zErrorNode.startchar  s    yy"""r   c                 .    | j                   j                  S r   )rm   r5   r   s    r   r5   zErrorNode.endchar  s    yy   r   c                     | j                   r| j                   j                  |      }nt        j                  }t        t        j                  | j
                  |      |       S r   )rm   r   r   r   error_queryr   r   s      r   r   zErrorNode.query  sB    99		'AAe''a8$??r   r   )	r   rG   rH   rY   r   r   r4   r5   r   r   r   r   r   r   }  s:    7 # # ! !@r   r   c                   $    e Zd Zej                  Zy)AndGroupN)r   rG   rH   r   Andrp   r   r   r   r   r         YYFr   r   c                   6    e Zd Zej                  Zedd       Zy)OrGroupc                 .     G fddt               S )Nc                   &     e Zd Zd fd	Z xZS )&OrGroup.factory.<locals>.ScaledOrGroupc                 8    d|v r|d= t        |   d|d| y )Nscale)r^   r   r   )superrY   )r   r^   r_   ScaledOrGroupr   r   s      r   rY   z/OrGroup.factory.<locals>.ScaledOrGroup.__init__  s2    f$wmT3 >%u >6<>r   r   )r   rG   rH   rY   __classcell__)r   r   r   s   @r   r   r     s    > >r   r   )r   )clsr   r   s    `@r   factoryzOrGroup.factory  s    	>G 	> r   N)r   )r   rG   rH   r   Orrp   classmethodr   r   r   r   r   r     s    XXF r   r   c                   $    e Zd Zej                  Zy)DisMaxGroupN)r   rG   rH   r   DisjunctionMaxrp   r   r   r   r   r     s    !!Fr   r   c                   $    e Zd Zej                  Zy)OrderedGroupN)r   rG   rH   r   Orderedrp   r   r   r   r   r         ]]Fr   r   c                   $    e Zd Zej                  Zy)AndNotGroupN)r   rG   rH   r   AndNotrp   r   r   r   r   r     s    \\Fr   r   c                   $    e Zd Zej                  Zy)AndMaybeGroupN)r   rG   rH   r   AndMayberp   r   r   r   r   r     s    ^^Fr   r   c                   $    e Zd Zej                  Zy)RequireGroupN)r   rG   rH   r   Requirerp   r   r   r   r   r     r   r   r   c                   $    e Zd Zej                  Zy)NotGroupN)r   rG   rH   r   Notrp   r   r   r   r   r     r   r   r   c                   &    e Zd ZdZdZd Zd Zd Zy)	RangeNodez#Syntax node for range queries.
    Tc                 f    || _         || _        || _        || _        d| _        d | _        i | _        y r   )startend	startexclendexclr   r   r_   )r   r   r   r   r   s        r   rY   zRangeNode.__init__  s3    
"
r   c                     | j                   rdnd}| j                  rdnd}|| j                  d| j                  |S )N{[}]r   )r   r   r   r   )r   b1b2s      r   r   zRangeNode.r  s3    NNSLLSc $**dhh;;r   c                    | j                   xs |j                   }| j                  }| j                  }|j                  r||j                  v r|j                  |   }|j	                         rE	 |j                  |||| j                  | j                  | j                        }|t        ||       S 	 |rt        ||dd      }|rt        ||dd      }t        j                   |||| j                  | j                  | j                        }t        ||       S # t        $ r9 t        j                         d   }t        t        j                  |      |       cY S w xY w)N)r   r   F)tokenizeremovestops)r   r   r   schemaself_parsingparse_ranger   r   r   r   r   sysexc_infor   r   r   	TermRange)r   r(   r   r   r   fieldrs   es           r   r   zRangeNode.query  s<   NN6f&6&6	

hh==Y&--7MM),E!!#>)))UC*...$,,04

 * <A }%a. % 'uu49;%eS5279 OOIuc4>> LL

<a ( >q)A!%"3"3A"6==>s   -AD ?EEN)r   rG   rH   rI   r   rY   r   r   r   r   r   r   r     s     M<
r   r   c                   @    e Zd ZdZdZdZdZdZdZdZ	d Z
d Zd Zd Zy)	TextNodea  Intermediate base class for basic nodes that search for text, such as
    term queries, wildcards, prefixes, etc.

    Instances have the following attributes:

    ``qclass``
        If a subclass does not override ``query()``, the base class will use
        this class to construct the query.
    ``tokenize``
        If True and the subclass does not override ``query()``, the node's text
        will be tokenized before constructing the query
    ``removestops``
        If True and the subclass does not override ``query()``, and the field's
        analyzer has a stop word filter, stop words will be removed from the
        text before constructing the query.
    TNFc                 .    d | _         || _        d| _        y r   )r   ru   r   )r   ru   s     r   rY   zTextNode.__init__  s    	
r   c                 L    | j                   j                  d| j                  S rQ   )r   r   ru   r   s    r   r   z
TextNode.r  s    ..11499==r   c                      yrS   r   r   s    r   r,   zTextNode.is_text  rT   r   c                     | j                   xs |j                   }| j                  xs |j                  }|j                  || j                  || j
                  | j                  | j                        }t        ||       S )N)r   r   r   )	r   rp   	termclass
term_queryru   r   r   r   r   )r   r(   r   r   rs   s        r   r   zTextNode.query  sm    NN6f&6&6	KK36#3#3	iI$(JJ*.*:*:  < ar   )r   rG   rH   rI   r   rJ   r   rp   r   r   rY   r   r,   r   r   r   r   r   r     s;    " MHIFHK
>r   r   c                       e Zd ZdZdZdZd Zy)WordNodez"Syntax node for term queries.
    Tc                 ,    t        | j                        S r   )rb   ru   r   s    r   r   z
WordNode.r&  s    DIIr   N)r   rG   rH   rI   r   r   r   r   r   r   r  r    s     HKr   r  c                   $    e Zd ZdZddZd Zd Zy)Operatora5  Base class for PrefixOperator, PostfixOperator, and InfixOperator.

    Operators work by moving the nodes they apply to (e.g. for prefix operator,
    the previous node, for infix operator, the nodes on either side, etc.) into
    a group node. The group provides the code for what to do with the nodes.
    c                 .    || _         || _        || _        y)av  
        :param text: the text of the operator in the query string.
        :param grouptype: the type of group to create in place of the operator
            and the node(s) it operates on.
        :param leftassoc: for infix opeators, whether the operator is left
            associative. use ``leftassoc=False`` for right-associative infix
            operators.
        N)ru   	grouptype	leftassoc)r   ru   r  r  s       r   rY   zOperator.__init__4  s     	""r   c                      d| j                   z  S )NzOP %r)ru   r   s    r   r   z
Operator.rB  s    ""r   c                     t         )a)  Called with the parser, a group, and the position at which the
        operator occurs in that group. Should return a group with the operator
        replaced by whatever effect the operator has (e.g. for an infix op,
        replace the op and the nodes on either side with a sub-group).
        )r'   r   r(   grouppositions       r   replace_selfzOperator.replace_selfE  s
     "!r   N)T)r   rG   rH   rI   rY   r   r  r   r   r   r  r  ,  s    ##"r   r  c                       e Zd Zd Zy)PrefixOperatorc                 b    t        |      }||= ||dz
  k  r| j                  ||   g      ||<   |S )Nr   )r   r  )r   r(   r  r  lengths        r   r  zPrefixOperator.replace_selfP  s<    U(Ofqj "nneHo->?E(Or   Nr   rG   rH   r  r   r   r   r  r  O  s    r   r  c                       e Zd Zd Zy)PostfixOperatorc                 R    ||= |dkD  r| j                  ||dz
     g      ||dz
  <   |S r   )r  r  s       r   r  zPostfixOperator.replace_selfY  s8    (Oa<"&..%12E1F"GE(Q,r   Nr  r   r   r   r  r  X  s    r   r  c                       e Zd Zd Zy)InfixOperatorc                    | j                   }| j                  }|j                  }|dkD  r|t        |      dz
  k  r||dz
     }||dz      }|r)|r't	        ||      r|j                  |       |||dz   = |S |r0|s.t	        ||      r"|j                  d|       ||dz
  |dz   = |dz
  S  |||g      g||dz
  |dz    |S ||= |S )Nr   r   r   )r  r  r   r   
isinstancero   r   )	r   r(   r  r  lagtyper   leftrights	            r   r  zInfixOperator.replace_selfa  s    ^^--a<Hs5zA~5A&D(Q,'E 2*T5"9E"(8a</0  
5%(@Q%(Q,x!|34!|# 5:4-4H3Ihl8a<0  hr   Nr  r   r   r   r  r  `  s    r   r  c                 t    t        | j                        }| j                  |_        | j                  |_        |S r   )r  rX   r4   r5   )r#   rm   s     r   to_wordr     s+    AJJD[[DN99DLKr   )!r   rC   whooshr   whoosh.qparser.commonr   r   r   objectr   rL   rO   rV   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r   r   r   <module>r$     s8  8   K Kw+ w+t' ' (J (W%
 W%t) 4	0i 	0@
 @2y i ") "9 + K ; w /
 /d*z *Zx  "z  "FX h H Br   