
    Cjt=                       S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
  SSKrSSKJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJrJr  \(       a  SSKJr  SSKJr   " S S\5      r  " S S\ 5      r! " S S\ 5      r" " S S\ 5      r# " S S\ 5      r$\" SSS9r% \" S5      r& \RN                  RQ                  SS9 " S S\\%   5      5       r)g)a  
This module contains the `DOMQuery` class and related objects.

A DOMQuery is a set of DOM nodes returned by [query][textual.dom.DOMNode.query].

The set of nodes may be further refined with [filter][textual.css.query.DOMQuery.filter] and [exclude][textual.css.query.DOMQuery.exclude].
Additional methods apply actions to all nodes in the query.

!!! info

    If this sounds like JQuery, a (once) popular JS library, it is no coincidence.
    )annotations)TYPE_CHECKINGGenericIterableIteratorTypeVarcastoverloadN)
active_app)AwaitRemove)DeclarationError
TokenErrormatch)SelectorSet)parse_declarationsparse_selectors)DOMNodeWidgetc                      \ rS rSrSrSrg)
QueryError    z%Base class for a query related error. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       c/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/css/query.pyr   r       s    /r"   r   c                      \ rS rSrSrSrg)InvalidQueryFormat$   zQuery did not parse correctly.r   Nr   r   r"   r#   r%   r%   $   s    (r"   r%   c                      \ rS rSrSrSrg)	NoMatches(   zNo nodes matched the query.r   Nr   r   r"   r#   r(   r(   (   s    %r"   r(   c                      \ rS rSrSrSrg)TooManyMatches,   z!Too many nodes matched the query.r   Nr   r   r"   r#   r+   r+   ,   s    +r"   r+   c                      \ rS rSrSrSrg)	WrongType0   z)Query result was not of the correct type.r   Nr   r   r"   r#   r.   r.   0   s    3r"   r.   	QueryTyper   )bound
ExpectTypeT)angularc                     \ rS rSr/ SQrSSSSS.           S-S jjr\S.S j5       r\S/S j5       rS0S	 jr	S1S
 jr
S2S jrS2S jr\(       a  \S3S j5       r\S4S j5       rS5S jrS6S jrS7S jrS7S jr\(       a  \S8S j5       r\S9S j5       r S:   S;S jjr\(       a  \S8S j5       r\S9S j5       r S:   S;S jjr\(       a  \S8S j5       r\S9S j5       r S:   S;S jjr\(       a  \S2S j5       r\S<S j5       r S:   S=S jjrS>S jrS?S  jrS@S! jrS@S" jrS@S# jrSAS$ jr S:   SBS% jjrSS&S&S'.       SCS( jjrSDS) jrSDS* jr     SE         SFS+ jjr!S,r"g)GDOMQuery:   )_node_nodes_filters	_excludes_deepNT)filterexcludedeepparentc                  SnXl         SU l        U(       a  UR                  R                  5       O/ U l        U(       a  UR                  R                  5       O/ U l        X@l        Ub%   U R                  R                  [        U5      5        Ub&   U R                  R                  [        U5      5        gg! [         a    [        SU< S35      ef = f! [         a    [        SU< S35      ef = f)a  Initialize a query object.

!!! warning

    You won't need to construct this manually, as `DOMQuery` objects are returned by [query][textual.dom.DOMNode.query].

Args:
    node: A DOM node.
    filter: Query to filter children in the node.
    exclude: Query to exclude children in the node.
    deep: Query should be deep, i.e. recursive.
    parent: The parent query, if this is the result of filtering another query.

Raises:
    InvalidQueryFormat: If the format of the query is invalid.
TNzUnable to parse filter z	 as query)
r7   r8   r9   copyr:   r;   appendr   r   r%   )selfnoder<   r=   r>   r?   _rich_traceback_omits          r#   __init__DOMQuery.__init__>   s    2  $
.2&,FOO  "" 	 (.F!!#2 	 
X$$_V%<=
 X%%og&>? 	  X(+B6*I)VWWX  X(+B6*I)VWWXs   *$B8 $C 8CC1c                    U R                   $ )zThe node being queried.)r7   rC   s    r#   rD   DOMQuery.noden   s     zzr"   c                  ^ SSK Jn  U R                  c  [        U R                  (       a  U R
                  R                  U5      OU R
                  R                  5      nU V^s/ s H+  m[        U4S jU R                   5       5      (       d  M)  TPM-     nnU V^s/ s H+  m[        U4S jU R                   5       5      (       a  M)  TPM-     nn[        SU5      U l        U R                  $ s  snf s  snf )zLazily evaluate nodes.r   r   c              3  <   >#    U  H  n[        UT5      v   M     g 7fNr   .0selector_setrD   s     r#   	<genexpr>!DOMQuery.nodes.<locals>.<genexpr>   s     S]\u\400]   c              3  <   >#    U  H  n[        UT5      v   M     g 7frM   r   rN   s     r#   rQ   rR      s     X5t44rS   list[QueryType])textual.widgetr   r8   listr;   r7   walk_childrenallr9   anyr:   r	   )rC   r   initial_nodesrD   nodess      ` r#   r\   DOMQuery.nodess   s     	*;; 48JJ

((0DJJDUDUM
 *)DST]]SS )   "!DXXX !  
 0%8DK{{
s   %(C/C/(C4
C4c                ,    [        U R                  5      $ rM   )lenr\   rI   s    r#   __len__DOMQuery.__len__   s    4::r"   c                ,    [        U R                  5      $ )z#True if non-empty, otherwise False.)boolr\   rI   s    r#   __bool__DOMQuery.__bool__   s    DJJr"   c                ,    [        U R                  5      $ rM   )iterr\   rI   s    r#   __iter__DOMQuery.__iter__   s    DJJr"   c                ,    [        U R                  5      $ rM   )reversedr\   rI   s    r#   __reversed__DOMQuery.__reversed__   s    

##r"   c                    g rM   r   rC   indexs     r#   __getitem__DOMQuery.__getitem__   s    8;r"   c                    g rM   r   ro   s     r#   rq   rr      s    @Cr"   c                     U R                   U   $ rM   )r\   ro   s     r#   rq   rr      s    zz%  r"   c              #    #     U R                   (       a&  SSR                  S U R                    5       5      4v   U R                  (       a'  SSR                  S U R                   5       5      4v   g g ! [         a     g f = f7f)Nqueryz AND c              3  R   #    U  H  nS R                  S U 5       5      v   M     g7f),c              3  8   #    U  H  oR                   v   M     g 7frM   cssrO   selectors     r#   rQ   3DOMQuery.__rich_repr__.<locals>.<genexpr>.<genexpr>         Hi(i   NjoinrO   	selectorss     r#   rQ   )DOMQuery.__rich_repr__.<locals>.<genexpr>   s)      !)6I  Hi HHH)6   %'r=   z OR c              3  R   #    U  H  nS R                  S U 5       5      v   M     g7f)rx   c              3  8   #    U  H  oR                   v   M     g 7frM   rz   r|   s     r#   rQ   r~      r   r   Nr   r   s     r#   rQ   r      s)       )7I  Hi HHH)7r   )r9   r   r:   AttributeErrorrI   s    r#   __rich_repr__DOMQuery.__rich_repr__   s     	}}LL !)-!   ~~KK  )-      		s)   BA.A4 2B4
B>B BBc                B    [        U R                  UU R                  U S9$ )zmFilter this set by the given CSS selector.

Args:
    selector: A CSS selector.

Returns:
    New DOM Query.
)r<   r>   r?   r5   rD   r;   rC   r}   s     r#   r<   DOMQuery.filter   s%     II	
 	
r"   c                B    [        U R                  UU R                  U S9$ )zmExclude nodes that match a given selector.

Args:
    selector: A CSS selector.

Returns:
    New DOM query.
)r=   r>   r?   r   r   s     r#   r=   DOMQuery.exclude   s%     II	
 	
r"   c                    g rM   r   rI   s    r#   firstDOMQuery.first   s    &)r"   c                    g rM   r   rC   expect_types     r#   r   r      s    FIr"   c                    SnU R                   (       a@  U R                   S   nUb,  [        X15      (       d  [        SUR                  < SU 35      eU$ [	        SU < SU R
                  < 35      e)a  Get the *first* matching node.

Args:
    expect_type: Require matched node is of this type,
        or None for any type.

Raises:
    WrongType: If the wrong type was found.
    NoMatches: If there are no matching nodes in the query.

Returns:
    The matching Widget.
Tr   -Query value is the wrong type; expected type , found No nodes match z on )r\   
isinstancer.   r   r(   rD   )rC   r   rE   r   s       r#   r   r      sy       $::JJqME&!%55#GH\H\G__ghmgno  LodXT$))GHHr"   c                    g rM   r   rI   s    r#   only_oneDOMQuery.only_one   s    ),r"   c                    g rM   r   r   s     r#   r   r      s    ILr"   c                    SnUb  U R                  U5      OU R                  5       n U R                  S   n[        S5      e! [         a     U$ f = f)aI  Get the *only* matching node.

Args:
    expect_type: Require matched node is of this type,
        or None for any type.

Raises:
    WrongType: If the wrong type was found.
    NoMatches: If no node matches the query.
    TooManyMatches: If there is more than one matching node in the query.

Returns:
    The matching Widget.
T   z7Call to only_one resulted in more than one matched node)r   r\   r+   
IndexError)rC   r   rE   the_one_s        r#   r   r     si    "  $ (3'>DJJ{#DJJL 		 

1A I   	 		s   A 
AAc                    g rM   r   rI   s    r#   lastDOMQuery.last,  s    %(r"   c                    g rM   r   r   s     r#   r   r   /  s    EHr"   c                    U R                   (       d  [        SU < SU R                  < 35      eU R                   S   nUb,  [        X!5      (       d  [	        SUR
                  < SU 35      eU$ )a  Get the *last* matching node.

Args:
    expect_type: Require matched node is of this type,
        or None for any type.

Raises:
    WrongType: If the wrong type was found.
    NoMatches: If there are no matching nodes in the query.

Returns:
    The matching Widget.
r   z on domr   r   )r\   r(   rD   r   r.   r   )rC   r   r   s      r#   r   r   2  sr      zzodXWTYYMJKKzz"~":d+H+H?@T@T?WW_`d_ef  r"   c                    g rM   r   rI   s    r#   resultsDOMQuery.resultsM  s    25r"   c                    g rM   r   )rC   filter_types     r#   r   r   P  s    RUr"   c              #  j   #    Uc  U  Sh  vN   gU  H  n[        X!5      (       d  M  Uv   M     g N%7f)zGet query results, optionally filtered by a given type.

Args:
    filter_type: A Widget class to filter results,
        or None for no filter.

Yields:
    Iterator[Widget | ExpectType]: An iterator of Widget instances.
N)r   )rC   r   rD   s      r#   r   r   S  s3      OOd00J  s   	313
3c                >    U  H  nUR                   " U/UQ76   M     U $ )zSet the given class name(s) according to a condition.

Args:
    add: Add the classes if True, otherwise remove them.

Returns:
    Self.
)	set_class)rC   addclass_namesrD   s       r#   r   DOMQuery.set_classf  s$     DNN3-- r"   c                    [        U[        5      (       a  U  H  nUR                  U5        M     U $ [        U5      nU  H  nUR                  U5        M     U $ )zSet the classes on nodes to exactly the given set.

Args:
    classes: A string of space separated classes, or an iterable of class names.

Returns:
    Self.
)r   strset_classesrW   )rC   classesrD   r   s       r#   r   DOMQuery.set_classess  sX     gs##  )   w-K  - r"   c                6    U  H  nUR                   " U6   M     U $ )z%Add the given class name(s) to nodes.)	add_classrC   r   rD   s      r#   r   DOMQuery.add_class  s    DNNK( r"   c                6    U  H  nUR                   " U6   M     U $ )z,Remove the given class names from the nodes.)remove_classr   s      r#   r   DOMQuery.remove_class      D{+ r"   c                6    U  H  nUR                   " U6   M     U $ )z0Toggle the given class names from matched nodes.)toggle_classr   s      r#   r   DOMQuery.toggle_class  r   r"   c                x    [         R                  " 5       nUR                  " U R                  SU R                  06$ )zoRemove matched nodes from the DOM.

Returns:
    An awaitable object that waits for the widgets to be removed.
r?   )r   get_pruner\   r7   )rC   apps     r#   removeDOMQuery.remove  s,     nnzz4::9djj99r"   c                >   SnU  H  nUR                   " S0 UD6  M     Ub>   [        USS9nU  H-  nUR                  R                  U5        UR                  SS9  M/     U $ ! [         a1  n[        UR                  UR                  UR
                  5      SeSnAff = f)zRSet styles on matched nodes.

Args:
    css: CSS declarations to parser, or None.
TN)
set_styles )	read_from)layoutr   )	r   r   r   nametokenmessage_inline_stylesmergerefresh)rC   r{   update_stylesrE   rD   
new_styleserrors          r#   r   DOMQuery.set_styles  s      $DOO,m, ?Y/?QR
 ##))*5D)   $ Y&uzz5;;NTXXYs   
A! !
B+,BBFrepaintr   	recomposec               8    U  H  nUR                  XUS9  M     U $ )zRefresh matched nodes.

Args:
    repaint: Repaint node(s).
    layout: Layout node(s).
    recompose: Recompose node(s).

Returns:
    Query for chaining.
r   )r   )rC   r   r   r   rD   s        r#   r   DOMQuery.refresh  s#     DLL9LM r"   c                h    U  H+  nUR                  5       (       d  M  UR                  5           U $    U $ )zTFocus the first matching node that permits focus.

Returns:
    Query for chaining.
)allow_focusfocus)rC   rD   s     r#   r   DOMQuery.focus  s5     D!!

	  r"   c                    U R                   R                  R                  nUb3  [        U 5      nX;   a#  U R                   R                  R	                  XS9  U $ )zPBlur the first matching node that is focused.

Returns:
    Query for chaining.
)avoiding)r7   screenfocusedrW   _reset_focus)rC   r   r\   s      r#   blurDOMQuery.blur  sN     **##++"&t*E

!!..w.Gr"   c                d    U  H)  nUb  Xl         Ub  X%l        Ub  X5l        Uc  M#  XEl        M+     U $ )at  Sets common attributes on matched nodes.

Args:
    display: Set `display` attribute on nodes, or `None` for no change.
    visible: Set `visible` attribute on nodes, or `None` for no change.
    disabled: Set `disabled` attribute on nodes, or `None` for no change.
    loading: Set `loading` attribute on nodes, or `None` for no change.

Returns:
    Query for chaining.
)displayvisibledisabledloading)rC   r   r   r   r   rD   s         r#   setDOMQuery.set  sA    $ D"&"&# ("&  r"   )r;   r:   r9   r7   r8   )rD   r   r<   
str | Noner=   r   r>   rc   r?   zDOMQuery | NonereturnNone)r   r   )r   rU   )r   int)r   rc   )r   zIterator[QueryType])rp   r   r   r0   )rp   slicer   rU   )rp   zint | slicer   zQueryType | list[QueryType])r   zrich.repr.Result)r}   r   r   DOMQuery[QueryType])r   r0   )r   type[ExpectType]r   r2   rM   )r   type[ExpectType] | Noner   zQueryType | ExpectType)r   r   r   zIterator[ExpectType])r   r   r   z Iterator[QueryType | ExpectType])r   rc   r   r   r   r   )r   zstr | Iterable[str]r   r   )r   r   r   r   )r   r   )r{   r   r   r   )r   rc   r   rc   r   rc   r   r   )r   r   )NNNN)
r   bool | Noner   r   r   r   r   r   r   r   )#r   r   r   r   	__slots__rF   propertyrD   r\   r`   rd   rh   rl   r   r
   rq   r   r<   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r"   r#   r5   r5   :   su   EI """&.X.X 	.X
 .X .X  .X 
.X`    *  $ 	; 
;	C 
C!*
"
  	) 
)	I 
I 6:I2I	I8 	, 
,	L 
L 6:%2%	%N 	( 
(	H 
H 6:2	2 	5 
5	U 
U 6:2	)&&: !%	. "&eu/3HL	"
  $# $#  	
  
 r"   r5   )*r    
__future__r   typingr   r   r   r   r   r	   r
   	rich.reprrichtextual._contextr   textual.await_remover   textual.css.errorsr   r   textual.css.matchr   textual.css.modelr   textual.css.parser   r   textual.domr   rV   r   	Exceptionr   r%   r(   r+   r.   r0   r2   reprautor5   r   r"   r#   <module>r     s    # V V V  ' , ; # ) A#%0 0) )&
 &,Z ,4
 4 Kx0	 1\"
 5 Awy! A Ar"   