
    BhI                         S SK r S SKJr  S SKJr  S SKJr  SSKJr  SSKJ	r	  \ R                  " S5      R                  rSS	 jr " S
 S5      rS rS rg)    N)urlparse)	parse_nth)ascii_lower   )parser)SelectorErrorz	[^ 	
]+c                 l    [         R                  " X5       Vs/ s H  n[        U5      PM     sn$ s  snf )ab  Compile a (comma-separated) list of selectors.

:param input:
    A string, or an iterable of tinycss2 component values such as
    the :attr:`tinycss2.ast.QualifiedRule.prelude` of a style rule.
:param namespaces:
    A optional dictionary of all `namespace prefix declarations
    <http://www.w3.org/TR/selectors/#nsdecl>`_ in scope for this selector.
    Keys are namespace prefixes as strings, or ``None`` for the default
    namespace.
    Values are namespace URLs as strings.
    If omitted, assume that no prefix is declared.
:returns:
    A list of opaque :class:`compiler.CompiledSelector` objects.

)r   parseCompiledSelector)input
namespacesselectors      E/var/www/html/env/lib/python3.13/site-packages/cssselect2/compiler.pycompile_selector_listr      s-    " 8>||E7VW7V8X&7VWWWs   1c                       \ rS rSrSrS rSrg)r   "   z&Abstract representation of a selector.c                    [        UR                  5      nUS:H  U l        [        [        [
        S.n[        SU-   U0 5      U l        UR                  U l        UR                  U l	        S U l
        S U l        S U l        S U l        S U l        SU l        UR                  n[!        U["        R$                  5      (       a  UR&                  nUR(                   GH  n[!        U["        R*                  5      (       a  UR,                  U l
        M6  [!        U["        R.                  5      (       a  UR                  U l        Mh  [!        U["        R0                  5      (       a$  UR                  U l        UR                  U l        M  [!        U["        R2                  5      (       a  UR                  U l        M  [!        U["        R4                  5      (       d  M  UR6                  S:X  d  GM  SU l        GM     g )N0)split_whitespacer   r   zlambda el: FlangT)_compile_nodeparsed_treenever_matchesr   r   r   evaltestspecificitypseudo_elementid
class_name
local_namelower_local_name	namespacerequires_lang_attr
isinstancer   CombinedSelectorrightsimple_selectors
IDSelectoridentClassSelectorLocalNameSelectorNamespaceSelectorAttributeSelectorname)selfparsed_selectorsourceeval_globalsnodesimple_selectors         r   __init__CompiledSelector.__init__$   s{   ::;#s] 0& 

 /rB	*66-<< $"'**dF3344::D#44O/6+<+<==)//OV-A-ABB"1"<"<OV-E-EFF"1"<"<(7(H(H%OV-E-EFF!0!:!:OV-E-EFF"''61.2D+  5    )
r   r   r    r!   r"   r   r   r#   r   r   N)__name__
__module____qualname____firstlineno____doc__r5   __static_attributes__ r7   r   r   r   "   s
    0!3r7   r   c           
         [        U [        R                  5      (       a  [        U R                  5      nUS:X  a  gUS:X  a<  U R
                  S;   a  SnOU R
                  S;   a  SnO[        SU R
                  5      eU R
                  S:X  a  S	U S
3nO[U R
                  S:X  a  SU S3nODU R
                  S:X  a  SU S3nO-U R
                  S:X  a  S	U S3nO[        SU R
                  5      e[        U R                  5      nUS:X  a  gUS:X  a  U$ SU SU S3$ [        U [        R                  5      (       ay  U R                   V s/ s H  n [        U 5      PM     sn  Vs/ s H  nUS:w  d  M  UPM     nn[        U5      S:X  a  US   $ SU;   a  gU(       a  SR                  S U 5       5      $ g[        U [        R                  5      (       al  U R                   V s/ s H  n [        U R                  5      PM     sn  Vs/ s H  nUS:w  d  M  UPM     nnU(       d  gSSR                  S U 5       5       S3$ [        U [        R                  5      (       a  / nU R                   H  n[        UR                   R                  5      nUS:X  a  M*  UR
                  S:X  a  SnO8UR
                  S:X  a  SnO%UR
                  S:X  a  SnOUR
                  S:X  a  SnUR#                  S U S!W S"35        M     SR                  U5      $ [        U [        R$                  [        R&                  45      (       ah  U R                   V s/ s H  n [        U R                  5      PM     sn  Vs/ s H  nUS:w  d  M  UPM     nnU(       d  gSR                  S# U 5       5      $ [        U [        R(                  5      (       aI  U R*                  U R,                  :X  a  S$U R,                  < 3$ S%U R*                  < S&U R,                  < S3$ [        U [        R.                  5      (       a  S'U R0                  < 3$ [        U [        R2                  5      (       a  U R4                  < S(3$ [        U [        R6                  5      (       a  S)U R8                  < 3$ [        U [        R:                  5      (       GaJ  U R0                  Gb6  U R0                  (       a  U R<                  U R>                  :X  a&  [A        S*U R0                   S+U R<                   35      n	OS*U R0                   S+U R>                   3n
S*U R0                   S+U R<                   3nSU
< S&U< S3n	ORU R<                  U R>                  :X  a  [A        U R<                  5      n	O"U R>                  U R<                  pSU
< S&U< S3n	U RB                  nS,U	 S-3nU RD                  S.L a  URG                  5       nUS/-  nU RH                  c  U	 S03$ U RH                  S1:X  a  U	 S2U S3U< 3$ U RH                  S4:X  a<  [        URK                  5       5      S:w  d  URM                  5       U:w  a  S$ U< S5U S3$ U RH                  S6:X  a  U	 S2U S3U< SU S7US8-   < S3
$ U RH                  S9:X  a  U(       a	  U S7U< S3$ gU RH                  S::X  a  U(       a	  U S;U< S3$ S$ U RH                  S<:X  a  U(       a  U< S=U 3$ S$ [        S>U RH                  5      e[N        e[        U [        RP                  5      (       Ga  U R<                  S?;   a)  [S        S@SASB5      nUSC-  nU R<                  SD:X  a  USE-  nU$ U R<                  SF:X  a5  [S        SGSHSISJSK5      n[S        SLSMSN5      n[S        S@SASB5      nSU SOU SPU SQ3$ U R<                  SR:X  a%  [S        SGSHSISJSK5      n[S        SLSMSN5      nSU SSU ST3$ U R<                  SU:X  a   [S        SHSM5      n[S        SK5      nSU SVU SW3$ U R<                  SX;   a  gU R<                  SY;   a  gZU R<                  S[:X  a  g\U R<                  S]:X  a  g^U R<                  S_:X  a   g`U R<                  Sa:X  a   gbU R<                  Sc:X  a  gdU R<                  Se:X  a   gfU R<                  Sg:X  a  gh[        SiU R<                  5      e[        U [        RT                  5      (       Ga  U R<                  Sj:X  Ga  / nU RV                   Vs/ s H  nURX                  Sk;  d  M  UPM     nnU(       a  UR[                  S5      nURX                  Sl:X  a  UR#                  UR\                  5        O@URX                  Sm:X  a%  UR#                  [_        URB                  5      5        O[        Sn5      eU(       a<  UR[                  S5      nURX                  Sl:w  a  URB                  So:w  a  [        Sn5      eU(       a  M  SR                  Sp U 5       5      $ / n/ nUnU RV                   H=  nURX                  Sl:X  a  URB                  Sq:X  a	  UUL a  UnM,  UR#                  U5        M?     U(       a  SR                  Sr [        R`                  " U5       5       5      nU R<                  Ss:X  a  StU S"3nO[U R<                  Su:X  a  SvU S"3nODU R<                  Sw:X  a  SxU Sy3nO-U R<                  Sz:X  a  S{U Sy3nO[        SiU R<                  5      eUS|U S}3-  nOUUL a  [        S~U R<                   S35      eU R<                  Ss:X  a  SnOOU R<                  Su:X  a  SnO<U R<                  Sw:X  a  SnO)U R<                  Sz:X  a  SnO[        SiU R<                  5      e[c        U5      nUc  [        S~U R<                   S35      eUu  nnUS-
  nUS:X  a  SU SU 3$ SU SU SU S3$ [e        [Y        U 5      U 5      es  sn f s  snf s  sn f s  snf s  sn f s  snf s  snf )zReturn a boolean expression, as a Python source string.

When evaluated in a context where the `el` variable is an
:class:`cssselect2.tree.Element` object, tells whether the element is a
subject of `selector`.

r   1) >zel.parent is not None)~+zel.previous is not NonezUnknown combinatorrA   zany((z) for el in el.ancestors)rB   znext(el is not None and (z) for el in [el.parent])rD   z) for el in [el.previous])rC   z!) for el in el.previous_siblings)(z) and ()r   r   z and c              3   .   #    U  H  nS U S3v   M     g7frE   rF   Nr>   ).0els     r   	<genexpr> _compile_node.<locals>.<genexpr>   s     DOb!B4q	O   znot (z or c              3   .   #    U  H  nS U S3v   M     g7frH   r>   rI   exprs     r   rK   rL      s     "K?4QtfA;?rM   zlist(el.iter_subtree())[1:]zel.iter_children()z!list(el.iter_next_siblings())[:1]zel.iter_next_siblings()z(any(z for el in ))c              3   .   #    U  H  nS U S3v   M     g7frH   r>   rO   s     r   rK   rL      s     C?4QtfA;?rM   zel.local_name == zel.local_name == (z if el.in_html_document else zel.namespace_url == z in el.classesz	el.id == {}zel.etree_element.get(z, "")Fz.lower()z in el.etree_element.attrib=z  in el.etree_element.attrib and z == z~=z in split_whitespace(z|=z.startswith(-z^=z$=z
.endswith(z*=z in zUnknown attribute operator)linkzany-link
local-linkaarearW   z. and el.etree_element.get("href") is not None rX   z5and not urlparse(el.etree_element.get("href")).schemeenabledbuttonr   selecttextareaoptionoptgroupmenuitemfieldsetzS and el.etree_element.get("disabled") is None  and not el.in_disabled_fieldset) or(z3 and el.etree_element.get("disabled") is None) or (z. and el.etree_element.get("href") is not None)disabledzT and (el.etree_element.get("disabled") is not None  or el.in_disabled_fieldset)) or(z2 and el.etree_element.get("disabled") is not None)checkedz and el.etree_element.get("checked") is not None and  ascii_lower(el.etree_element.get("type", ""))   in ("checkbox", "radio")) or (z2 and el.etree_element.get("selected") is not None))visitedhoveractivefocuszfocus-withinzfocus-visibletargetztarget-withincurrentpastfutureplayingpausedseeking	bufferingstalledmutedzvolume-lockedz
user-validzuser-invalid)rootscopezel.parent is Nonezfirst-childzel.index == 0z
last-childz&el.index + 1 == len(el.etree_siblings)zfirst-of-typezKall(s.tag != el.etree_element.tag    for s in el.etree_siblings[:el.index])zlast-of-typezOall(s.tag != el.etree_element.tag    for s in el.etree_siblings[el.index + 1:])z
only-childzlen(el.etree_siblings) == 1zonly-of-typez_all(s.tag != el.etree_element.tag or i == el.index    for i, s in enumerate(el.etree_siblings))emptyz0not (el.etree_children or el.etree_element.text)zUnknown pseudo-classr   )
whitespacecommentr)   stringzInvalid arguments for :lang(),c              3   >   #    U  H  nS U< SUS-   < S3v   M     g7f)zel.lang == z or el.lang.startswith(rV   rF   Nr>   )rI   r   s     r   rK   rL   H  s,      #!D dX%<dSj<LAN!   ofc              3   L   #    U  H  n[        UR                  5      v   M     g 7fN)r   r   )rI   r   s     r   rK   rL   W  s&      $A$? "("6"677$?s   "$z	nth-childz)sum(1 for el in el.previous_siblings if (znth-last-childzBsum(1 for el in    tuple(el.iter_siblings())[el.index + 1:]   if (znth-of-typez@sum(1 for s in (      el for el in el.previous_siblings     if (z5))    if s.etree_element.tag == el.etree_element.tag)znth-last-of-typezYsum(1 for s in (      el for el in      tuple(el.iter_siblings())[el.index + 1:]     if (zif (z) else float("nan")zInvalid arguments for :z()zel.indexz%len(el.etree_siblings) - el.index - 1zPsum(1 for s in el.etree_siblings[:el.index]    if s.tag == el.etree_element.tag)zTsum(1 for s in el.etree_siblings[el.index + 1:]    if s.tag == el.etree_element.tag)z) == z/next(r == 0 and n >= 0    for n, r in [divmod((z) - , z)]))3r$   r   r%   r   left
combinatorr   r&   CompoundSelectorr'   lenjoinNegationSelectorselector_listr   RelationalSelectorr   appendMatchesAnySelectorSpecificityAdjustmentSelectorr+   r!   r    r,   r"   r*   r   r(   r)   r-   r.   
lower_namereprvaluecase_sensitiveloweroperatorsplitstripNotImplementedErrorPseudoClassSelectorhtml_tag_eqFunctionalPseudoClassSelector	argumentstypepoplower_valuer   r
   r   	TypeError)r   left_insider   r&   rP   sub_expressionsrelative_selector
expressionelementskeyr   r.   r   attribute_valuer   r   grouprY   r_   langstokentokensnthr   current_listargumentcountresultbBs                                 r   r   r   H   s    (F3344#HMM2#C""j0.$$
20#$8(:M:MNN   C';-'@AD  C'+K= 9) )    C'+K= 9+ +    C';-'HID 4h6I6IJJhnn-C<c\K ugWTF!,,	Hf55	6	6 !) 9 9; 9H h' 9;;T s{  ; 	 
 1$"1%%O#<<DODDD	Hf55	6	6 !) 6 68 6H h223 688T s{  8 	 
 v{{"K?"KKLANN	Hf77	8	8!)!7!7&'8'A'A'M'MNJS  ++s28"--4/"--4>"--44""U:,k(2#NO "8 {{?++	H%%v'K'KM 
N 
N
 !) 6 68 6H h223 688T s{  8 	 
 {{C?CCC	Hf66	7	7$$(;(;;&x':':&=>> %X%>%>$A B//7/B/B.EQHI 
Hf66	7	7%h&8&8%;<<	Hf22	3	3%%(77	Hf//	0	08>>,--	Hf66	7	7)!!==H$7$77H$6$6#7r(--IJC !3!3 4Bx7J7J6KLE 2 232hmm_EDeY&CD81MC==H$7$77x}}-C"*"5"5x}}4eY&CD81MCNNE 5cU%@O&&%/:-  (9::""c)e;&'tE967 ""d*u{{}-2ekkmu6LCN!9$9/9J!LN ""d*e;&'tE9D&'|US[3DAGH ""d*-.l5)1EE""d*@E'z%!<PKNP""d*<A%$&78JsJ#$@(BSBSTT%%	Hf88	9	9==>>sFF3DDDD}},OOK]]i''8ZCE
J
CEC0AE7 7 3DFG
 ]]j('8ZCE
J
CEE7 7LNO ]]i'4E *FE7 3 (LNO
 ]]     ]]//&]]m+"]]l*;]]o-=> ]]n,AB ]]l*0]]n,@A ]]g%E 6FF	HfBB	C	C==F"E#+#5#5@#5%::%>> #5  @ 

1::(LL!2!23ZZ8+LLU[[!9:'(GHH"JJqMEzzW,1C+,KLL & ;; #!# # # CML$..==G+$0F#s*'4 ##H- / || $A$*LL$?$A A ==K/CD6L ]]&66""&r+  ]]m3$$(6 *NN 
 ]]&88$ %)6 *NN  ((>NN4v%899=0'1(--CE E==K/&E]]&66CE]]m3@  ]]&88@  ((>NNs^F~#-hmm_B?A ADAq
 AAAv5'qc**005wd1#Rs#GH
 X11w; 8:8b@sB   
o%$
o*2o*"o/
o4o4o90
o>>o>;ppc                      [        U 5      S:X  a  SU S    3nSU S   < SU< S3$ SR                  S U  5       5      nSR                  S	 U  5       5      nS
U SU S3$ )z;Generate expression testing equality with HTML local names.r   {http://www.w3.org/1999/xhtml}r   z((el.local_name == z7) if el.in_html_document else (el.etree_element.tag == rQ   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr~   r   )rI   ns     r   rK   html_tag_eq.<locals>.<genexpr>  s     7;a$q'';s   c              3   >   #    U  H  n[        S U 35      v   M     g7f)r   Nr   )rI   r.   s     r   rK   r     s'      %# 3D6:;;#r{   z((el.local_name in (z9)) if el.in_html_document else (el.etree_element.tag in (z))))r   r   )local_namestagnamestagss       r   r   r     s    
;10Q0@A!+a.!3 4--0G27	8 		7;77yy %#% % #5' *..2V38	9r7   r~   )reurllib.parser   tinycss2.nthr   webencodingsr    r   r   compilefindallr   r   r   r   r   r>   r7   r   <module>r      sK    	 ! " $  ! ::o.66 X(#3 #3LQ2h
9r7   