
    h4                       S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  SSK
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  \(       a  SSKJr   " S S	\\5      r " S
 S5      r \RB                  " S5      RD                  r#\RB                  " S5      RH                  r%\RB                  " S5      RH                  r& " S S5      r' " S S\'5      r(g)z
cssselect.xpath
===============

Translation of parsed CSS selectors to XPath expressions.


:copyright: (c) 2007-2012 Ian Bicking and contributors.
See AUTHORS for more details.
:license: BSD, see LICENSE for more details.

    )annotationsN)Callable)TYPE_CHECKINGOptionalcast)AttribClassCombinedSelectorElementFunctionHashMatchingNegationPseudoPseudoElementRelationSelectorSelectorErrorSpecificityAdjustmentTreeparseparse_series)Selfc                      \ rS rSrSrSrg)ExpressionError-   z3Unknown or unsupported selector (eg. pseudo-class). N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       V/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/cssselect/xpath.pyr   r   -   s    =r$   r   c                      \ rS rSr    S         SS jjrSS jrSS jrSSS jjrSS jrSS jr	  S         SS	 jjr
S
rg)	XPathExpr4   c                (    Xl         X l        X0l        g N)pathelement	condition)selfr+   r,   r-   star_prefixs        r%   __init__XPathExpr.__init__5   s     	"r$   c                    [        U R                  5      [        U R                  5      -   nU R                  (       a  USU R                   S3-  nU$ N[]strr+   r,   r-   )r.   r+   s     r%   __str__XPathExpr.__str__@   sA    499~DLL 11>>a'q))Dr$   c                :    U R                   R                   SU  S3$ r3   )	__class__r   r.   s    r%   __repr__XPathExpr.__repr__F   s     ..))*!D633r$   c                n    U R                   (       a  SU R                    SU SU S3U l         U $ Xl         U $ )N(z) z ())r-   )r.   r-   
conjuctions      r%   add_conditionXPathExpr.add_conditionI   s=    >>  0:,b1MDN  'Nr$   c                    U R                   S:X  a  g U R                  S[        R                  U R                   5       35        SU l         g )N*z	name() = )r,   rC   GenericTranslatorxpath_literalr<   s    r%   add_name_testXPathExpr.add_name_testP   s>    <<3Y'8'F'Ft||'T&UVWr$   c                .    U =R                   S-  sl         g)zM
Append '*/' to the path to keep the context constrained
to a single parent.
*/N)r+   r<   s    r%   add_star_prefixXPathExpr.add_star_prefixW   s    
 			T	r$   Nc                   [        U 5      U-   nUR                  S:w  a  XRR                  -  nXPl        U(       d:  U(       a  UR                  U-   OUR                  U l        UR                  U l        U $ UR                  U l        UR                  (       a%  U =R                  SUR                  -   S-   -  sl        U(       a  U =R                  U-  sl        U $ )NrL   r4   r5   r6   )r.   combinerotherclosing_combinerhas_inner_conditionr+   s         r%   joinXPathExpr.join^   s     4y8#::JJD	"4D 00%-- L #__DN  !==DLeoo 5 ;; 00r$   )r-   r,   r+   ) rF   rV   F)
r+   r7   r,   r7   r-   r7   r/   boolreturnNone)rX   r7   )and)r-   r7   rB   r7   rX   r   )rX   rY   )NF)
rP   r7   rQ   r'   rR   
str | NonerS   rW   rX   r   )r   r   r    r!   r0   r8   r=   rC   rI   rM   rT   r#   r   r$   r%   r'   r'   4   s     !	#	# 	# 		#
 	# 
	#4 (,$)  %	
 " 
 r$   r'   z('+)z^[a-zA-Z_][a-zA-Z0-9_.-]*$z^[^ \t\r\n\f]+$c            	         \ rS rSrSrSSSSS.rSS	S
SSSSSS.rSrSrSr	Sr
Sr\rSFSGS jjr  SH       SIS jjr      SJS jr\SKS j5       rSLS jrSMS jrSNS jrSOS jrSPS jrSQS jrSRS jrSSS jrSTS  jrSUS! jrSVS" jrSWS# jr      SXS$ jrSXS% jr       SXS& jr!      SXS' jr"      SXS( jr#      SXS) jr$      SXS* jr%      SXS+ jr&  SY         SZS, jjr'      S[S- jr(      S[S. jr)      S[S/ jr*      S[S0 jr+S[S1 jr,S\S2 jr-S\S3 jr.S\S4 jr/S\S5 jr0S\S6 jr1S\S7 jr2S\S8 jr3S\S9 jr4S\S: jr5S\S; jr6\6r7\6r8\6r9\6r:\6r;\6r<\6r=\6r>\6r?        S]S< jr@        S]S= jrA        S]S> jrB        S]S? jrC        S]S@ jrD        S]SA jrE        S]SB jrF        S]SC jrGSDrHgE)^rG      z
Translator for "generic" XML documents.

Everything is case-sensitive, no assumption is made on the meaning
of element names and attribute names.


descendantchilddirect_adjacentindirect_adjacent) >+~existsequalsincludes	dashmatchprefixmatchsuffixmatchsubstringmatch	different)rf   =z~=z|=z^=z$=z*=z!=idzxml:langFc                P   ^ ^ SR                  UU 4S j[        U5       5       5      $ )u>  Translate a *group of selectors* to XPath.

Pseudo-elements are not supported here since XPath only knows
about "real" elements.

:param css:
    A *group of selectors* as a string.
:param prefix:
    This string is prepended to the XPath expression for each selector.
    The default makes selectors scoped to the context node’s subtree.
:raises:
    :class:`~cssselect.SelectorSyntaxError` on invalid selectors,
    :class:`ExpressionError` on unknown/unsupported selectors,
    including pseudo-elements.
:returns:
    The equivalent XPath 1.0 expression as a string.

z | c              3  F   >#    U  H  nTR                  UTS S9v   M     g7f)T)translate_pseudo_elementsN)selector_to_xpath).0selectorprefixr.   s     r%   	<genexpr>1GenericTranslator.css_to_xpath.<locals>.<genexpr>   s*      
& ""8Vt"T&s   !)rT   r   )r.   cssrv   s   ` `r%   css_to_xpathGenericTranslator.css_to_xpath   s'    & zz 
!#J
 
 	
r$   c                6   [        USS5      nU(       d  [        SU< 35      eU R                  U5      n[        XPR                  5      (       d   eU(       a,  UR
                  (       a  U R                  XQR
                  5      nU=(       d    S[        U5      -   $ )u  Translate a parsed selector to XPath.


:param selector:
    A parsed :class:`Selector` object.
:param prefix:
    This string is prepended to the resulting XPath expression.
    The default makes selectors scoped to the context node’s subtree.
:param translate_pseudo_elements:
    Unless this is set to ``True`` (as :meth:`css_to_xpath` does),
    the :attr:`~Selector.pseudo_element` attribute of the selector
    is ignored.
    It is the caller's responsibility to reject selectors
    with pseudo-elements, or to account for them somehow.
:raises:
    :class:`ExpressionError` on unknown/unsupported selectors.
:returns:
    The equivalent XPath 1.0 expression as a string.

parsed_treeNz Expected a parsed selector, got rV   )getattr	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr7   )r.   ru   rv   rr   treer   s         r%   rs   #GenericTranslator.selector_to_xpath   s    4 x5>xlKLL

4 %!3!34444$)@)@--e5L5LME"E
**r$   c                    [        S5      e)zwTranslate a pseudo-element.

Defaults to not supporting pseudo-elements at all,
but can be overridden by sub-classes.

z"Pseudo-elements are not supported.)r   )r.   r   r   s      r%   r   &GenericTranslator.xpath_pseudo_element  s     BCCr$   c                   [        U 5      n SU ;  a  SU  S3n U $ SU ;  a  SU  S3n U $ [        U 5       Vs/ s H  nU(       d  M  SU;   a  SU S3OSU S3PM      nnSR                  SR                  U5      5      n U $ s  snf )N'"z
concat({}),)r7   split_at_single_quotesformatrT   )spartparts_quoteds      r%   rH   GenericTranslator.xpath_literal  s    Fa<A3aA  \A3aA 	 3155D <sd{!D6!D6;5  
 ##CHH\$:;As   A>A>c           	         [        U5      R                  n[        [        [        [
        /[        4      [        U SUR                  5        3S5      5      nUc  [        U S35      eU" U5      $ )z%Translate any parsed selector object.xpath_Nz is not supported.)
typer   r   r   r   r   r'   r~   lowerr   )r.   parsed_selector	type_namemethods       r%   r   GenericTranslator.xpath   sp    )22	Xtfi/01DF9??#4"56=
 >!YK/A"BCCo&&r$   c           	        U R                   UR                     n[        [        [        [        /[        4   [        U SU S35      5      nU" U R                  UR                  5      U R                  UR                  5      5      $ )zTranslate a combined selector.r   _combinator)	combinator_mapping
combinatorr   r   r'   r~   r   ru   subselector)r.   combinedr   r   s       r%   xpath_combinedselector(GenericTranslator.xpath_combinedselector-  st    ,,X-@-@A
i+Y67DF:,k:;
 djj!2!23TZZ@T@T5UVVr$   c                   U R                  UR                  5      nU R                  UR                  5      nUR                  5         UR                  (       a  UR                  SUR                   S35      $ UR                  S5      $ )Nnot(rA   0)r   ru   r   rI   r-   rC   )r.   negationr   	sub_xpaths       r%   xpath_negation GenericTranslator.xpath_negation6  sq    

8,,-JJx334	!&&i.A.A-B!'DEE""3''r$   c                Z   U R                  UR                  5      nUR                  nUR                  nU R                  UR                  5      n[        [        [        [        /[        4   [        U SU R                  [        [        UR                  5          S35      5      nU" X%5      $ )Nxpath_relation_r   )r   ru   r   r   r}   r   r   r'   r~   r   r7   value)r.   relationr   r   r   rightr   s          r%   xpath_relation GenericTranslator.xpath_relation>  s    

8,,-((
**

;223i+Y67!$"9"9$sJDTDT:U"V!WWbc
 e##r$   c                *   U R                  UR                  5      nUR                   Vs/ s H  o0R                  U5      PM     nnU HB  nUR                  5         UR                  (       d  M&  UR                  UR                  S5        MD     U$ s  snf Norr   ru   selector_listrI   r-   rC   r.   matchingr   ru   exprses         r%   xpath_matching GenericTranslator.xpath_matchingL  w    

8,,-6>6L6LM6L(H%6LMAOO{{{##AKK6   N   Bc                *   U R                  UR                  5      nUR                   Vs/ s H  o0R                  U5      PM     nnU HB  nUR                  5         UR                  (       d  M&  UR                  UR                  S5        MD     U$ s  snf r   r   r   s         r%   xpath_specificityadjustment-GenericTranslator.xpath_specificityadjustmentU  r   r   c                D   SR                  UR                  R                  SS5      5      n[        [        [
        [        [        /[        4      [        XS5      5      nU(       d  [        SUR                   S35      eU" U R                  UR                  5      U5      $ )z$Translate a functional pseudo-class.zxpath_{}_function-_NThe pseudo-class :z() is unknown)r   namereplacer   r   r   r'   r   r~   r   r   ru   )r.   functionmethod_namer   s       r%   xpath_function GenericTranslator.xpath_function^  s    )001F1FsC1PQXy(3Y>?@Dt,
 !$6x}}o]"STTdjj!2!23X>>r$   c                8   SR                  UR                  R                  SS5      5      n[        [        [
        [        /[        4      [        XS5      5      nU(       d  [        SUR                   S35      eU" U R                  UR                  5      5      $ )zTranslate a pseudo-class.zxpath_{}_pseudor   r   Nr   z is unknown)r   identr   r   r   r   r'   r~   r   r   ru   )r.   pseudor   r   s       r%   xpath_pseudoGenericTranslator.xpath_pseudoi  s    '..v||/C/CC/MNXyk9456SW8X
 !$6v||nK"PQQdjj122r$   c                   U R                   UR                     n[        [        [        [
        [        [
           /[        4   [        U SU 35      5      nU R                  (       a  UR                  R                  5       nOUR                  n[        U5      nUR                  (       a/  UR                   SU 3nU=(       a    [        UR                  5      nU(       a  SU-   nOSU R                  U5       S3nUR                  c  SnOZU R                  (       a3  [        [
        UR                  R                  5      R                  5       nOUR                  R                  nU" U R!                  UR"                  5      Xg5      $ )z Translate an attribute selector.xpath_attrib_:@zattribute::*[name() = r5   N)attribute_operator_mappingoperatorr   r   r'   r7   r   r~   lower_case_attribute_namesattribr   is_safe_name	namespacerH   r   lower_case_attribute_valuesr   ru   )r.   ru   r   r   r   safer   r   s           r%   xpath_attribGenericTranslator.xpath_attribt  s8   2283D3DEihsm4i?@DM(45
 **??((*D??DD!(()4&1D<L););<D4ZF-d.@.@.F-GqIF>>!E--hnn22399;ENN((Edjj!2!23VCCr$   c                r    U R                  UR                  5      nU R                  USUR                  5      $ )zTranslate a class selector.z@class)r   ru   xpath_attrib_includes
class_name)r.   class_selectorr   s      r%   xpath_classGenericTranslator.xpath_class  s3     

>223))%>;T;TUUr$   c                r    U R                  UR                  5      nU R                  USUR                  5      $ )zTranslate an ID selector.z@id)r   ru   xpath_attrib_equalsro   )r.   id_selectorr   s      r%   
xpath_hashGenericTranslator.xpath_hash  s/    

;//0''uknnEEr$   c                ~   UR                   nU(       d  SnSnO5[        [        U5      5      nU R                  (       a  UR	                  5       nUR
                  (       a8  UR
                   SU 3nU=(       a    [        [        UR
                  5      5      nU R                  US9nU(       d  UR                  5         U$ )z'Translate a type or universal selector.rF   Tr   )r,   )r,   rW   r   lower_case_element_namesr   r   r   rI   )r.   ru   r,   r   r   s        r%   xpath_elementGenericTranslator.xpath_element  s    ""GDW-.D,,!--/ "++,AgY7GBDh.@.@!ABD""7"3!r$   c                &    UR                  SU5      $ )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/rT   r.   leftr   s      r%   xpath_descendant_combinator-GenericTranslator.xpath_descendant_combinator  s     yy2E::r$   c                &    UR                  SU5      $ )z#right is an immediate child of left/r   r   s      r%   xpath_child_combinator(GenericTranslator.xpath_child_combinator  s    yye$$r$   c                h    UR                  SU5      nUR                  5         UR                  S5      $ )z)right is a sibling immediately after left/following-sibling::zposition() = 1)rT   rI   rC   )r.   r   r   r   s       r%    xpath_direct_adjacent_combinator2GenericTranslator.xpath_direct_adjacent_combinator  s3     		0%8""#344r$   c                &    UR                  SU5      $ )z1right is a sibling after left, immediately or notr   r   r   s      r%   "xpath_indirect_adjacent_combinator4GenericTranslator.xpath_indirect_adjacent_combinator  s     yy/77r$   c                &    UR                  SUSSS9$ )zHright is a child, grand-child or further descendant of left; select leftz[descendant::r5   T)rR   rS   r   r   s      r%   $xpath_relation_descendant_combinator6GenericTranslator.xpath_relation_descendant_combinator  s#     yyUSd  
 	
r$   c                $    UR                  SUSS9$ )z0right is an immediate child of left; select leftz[./r5   rR   r   r   s      r%   xpath_relation_child_combinator1GenericTranslator.xpath_relation_child_combinator  s     yyy<<r$   c                @    UR                  SUR                   S35      $ )z6right is a sibling immediately after left; select leftz following-sibling::*[(name() = 'z') and (position() = 1)])rC   r,   r   s      r%   )xpath_relation_direct_adjacent_combinator;GenericTranslator.xpath_relation_direct_adjacent_combinator  s(     !!.u}}o=UV
 	
r$   c                $    UR                  SUSS9$ )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r5   r  r   r   s      r%   +xpath_relation_indirect_adjacent_combinator=GenericTranslator.xpath_relation_indirect_adjacent_combinator  s     yy/yMMr$   c                  ^  [        UR                  5      u  pVUS-
  nUS:X  a  US::  a  U$ US:  a  US:  a  UR	                  S5      $ U(       a  SOUR
                   n	U(       d  SU	 S3n
OS	U	 S3n
US:X  a  UR	                  U
 S
U 35      $ / nUS:  a  US:  a  UR                  U
 SU 35        OUR                  U
 SU 35        [        U5      S:w  a7  U
nU* [        U5      -  nUS:w  a	  SU SU S3nUR                  U SU S35        [        U5      S:  a  SOSmUR	                  SR                  U4S jU 5       5      5        U$ ! [         a   n[        SUR                  < S35      UeS nAff = f)NzInvalid series: 'r      r   r   rF   count(preceding-sibling::rA   count(following-sibling:: = z >= z <= r@   z +z mod z = 0z(%s)z%sz and c              3  .   >#    U  H
  nTU-  v   M     g 7fr*   r   )rt   
expressiontemplates     r%   rw   =GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>f  s     M:J.s   )
r   	arguments
ValueErrorr   rC   r,   appendabslenrT   )r.   r   r   lastrI   abexb_min_1nodetestsiblings_countexpressionsr   b_negr  s                 @r%   xpath_nth_child_function*GenericTranslator.xpath_nth_child_function  s   	W 2 23DAZ a% 6glL
 q5Wq[&&s++
 (3 8
!DN8
!DN 6&&.)9WI'FGGq5 {""n%5T'#CD
 .!1gY?@ q6Q;!D
 XQ'Ez4&5'+$uQCt45 -16tLLMMM	
 s  	W!$5h6H6H5K1"MNTVV	Ws   E 
E:E55E:c                "    U R                  XSS9$ )NT)r  )r"  r.   r   r   s      r%   xpath_nth_last_child_function/GenericTranslator.xpath_nth_last_child_functionj  s     ,,U4,HHr$   c                X    UR                   S:X  a  [        S5      eU R                  XSS9$ )NrF   "*:nth-of-type() is not implementedF)rI   r,   r   r"  r%  s      r%   xpath_nth_of_type_function,GenericTranslator.xpath_nth_of_type_functiono  s2     ==C!"FGG,,UE,RRr$   c                Z    UR                   S:X  a  [        S5      eU R                  XSSS9$ )NrF   r)  TF)r  rI   r*  r%  s      r%   xpath_nth_last_of_type_function1GenericTranslator.xpath_nth_last_of_type_functionv  s;     ==C!"FGG,,$e - 
 	
r$   c                    UR                  5       S/S/4;  a  [        SUR                  < 35      e[        [        UR                  S   R
                  5      nUR                  SU R                  U5       S35      $ )NSTRINGIDENTz7Expected a single string or ident for :contains(), got r   zcontains(., rA   argument_typesr   r  r   r7   r   rC   rH   r.   r   r   r   s       r%   xpath_contains_function)GenericTranslator.xpath_contains_function  s    
 ""$hZ',CC!I(J\J\I_`  S(,,Q/556""\$2D2DU2K1LA#NOOr$   c                    UR                  5       S/S/4;  a  [        SUR                  < 35      e[        [        UR                  S   R
                  5      nUR                  SU R                  U5       S35      $ )Nr1  r2  3Expected a single string or ident for :lang(), got r   zlang(rA   r3  r5  s       r%   xpath_lang_function%GenericTranslator.xpath_lang_function  s    ""$hZ',CC!EhFXFXE[\  S(,,Q/556""U4+=+=e+D*EQ#GHHr$   c                $    UR                  S5      $ )Nznot(parent::*)rC   r.   r   s     r%   xpath_root_pseudo#GenericTranslator.xpath_root_pseudo  s    ""#344r$   c                $    UR                  S5      $ )N1r=  r>  s     r%   xpath_scope_pseudo$GenericTranslator.xpath_scope_pseudo  s    ""3''r$   c                $    UR                  S5      $ )Nzcount(preceding-sibling::*) = 0r=  r>  s     r%   xpath_first_child_pseudo*GenericTranslator.xpath_first_child_pseudo      ""#DEEr$   c                $    UR                  S5      $ )Nzcount(following-sibling::*) = 0r=  r>  s     r%   xpath_last_child_pseudo)GenericTranslator.xpath_last_child_pseudo  rH  r$   c                v    UR                   S:X  a  [        S5      eUR                  SUR                    S35      $ )NrF   z"*:first-of-type is not implementedr  ) = 0r,   r   rC   r>  s     r%   xpath_first_of_type_pseudo,GenericTranslator.xpath_first_of_type_pseudo  s9    ==C!"FGG""%>u}}oU#STTr$   c                v    UR                   S:X  a  [        S5      eUR                  SUR                    S35      $ )NrF   z!*:last-of-type is not implementedr  rM  rN  r>  s     r%   xpath_last_of_type_pseudo+GenericTranslator.xpath_last_of_type_pseudo  s9    ==C!"EFF""%>u}}oU#STTr$   c                $    UR                  S5      $ )Nzcount(parent::*/child::*) = 1r=  r>  s     r%   xpath_only_child_pseudo)GenericTranslator.xpath_only_child_pseudo  s    ""#BCCr$   c                v    UR                   S:X  a  [        S5      eUR                  SUR                    S35      $ )NrF   z!*:only-of-type is not implementedzcount(parent::*/child::z) = 1rN  r>  s     r%   xpath_only_of_type_pseudo+GenericTranslator.xpath_only_of_type_pseudo  s9    ==C!"EFF""%<U]]O5#QRRr$   c                $    UR                  S5      $ )Nznot(*) and not(string-length())r=  r>  s     r%   xpath_empty_pseudo$GenericTranslator.xpath_empty_pseudo  rH  r$   c                $    UR                  S5      $ )z:Common implementation for pseudo-classes that never match.r   r=  r>  s     r%   pseudo_never_matches&GenericTranslator.pseudo_never_matches  s    ""3''r$   c                :    U(       a   eUR                  U5        U$ r*   r=  r.   r   r   r   s       r%   xpath_attrib_exists%GenericTranslator.xpath_attrib_exists  s     yD!r$   c                Z    Uc   eUR                  U SU R                  U5       35        U$ )Nr  rC   rH   ra  s       r%   r   %GenericTranslator.xpath_attrib_equals  s:        tfC(:(:5(A'BCDr$   c           
         Uc   eU(       a+  UR                  SU SU SU R                  U5       35        U$ UR                  U SU R                  U5       35        U$ )Nr   z) or z != re  ra  s       r%   xpath_attrib_different(GenericTranslator.xpath_attrib_different  ss        $tfE$tD<N<Nu<U;V WX  4&T-?-?-F,G HIr$   c                    U(       aC  [        U5      (       a3  U R                  SU-   S-   5      nUR                  U SU SU S35        U$ UR                  S5        U$ )Nrb   z* and contains(concat(' ', normalize-space(z	), ' '), rA   r   )is_non_whitespacerH   rC   )r.   r   r   r   args        r%   r   'GenericTranslator.xpath_attrib_includes  so     &u--$$S5[3%67C&B4&	RUQVVWX
  $r$   c                    Uc   eU R                  U5      nU R                  US-   5      nUR                  U SU SU SU SU S3
5        U$ )Nr   z and (r  z or starts-with(, z)))rH   rC   )r.   r   r   r   rl  arg_dashs         r%   xpath_attrib_dashmatch(GenericTranslator.xpath_attrib_dashmatch  sl          '%%eck2fF4&C5(8b
"M	
 r$   c           	         U(       a+  UR                  U SU SU R                  U5       S35        U$ UR                  S5        U$ )Nz and starts-with(ro  rA   r   re  ra  s       r%   xpath_attrib_prefixmatch*GenericTranslator.xpath_attrib_prefixmatch  sT     &)$r$2D2DU2K1LAN
  $r$   c                    U(       a<  UR                  U SU SU S[        U5      S-
   SU R                  U5       3	5        U$ UR                  S5        U$ )Nz and substring(z, string-length(z)-r  z) = r   )rC   r  rH   ra  s       r%   xpath_attrib_suffixmatch*GenericTranslator.xpath_attrib_suffixmatch  sk     &v-=dV2c%jSTnEUUYZ^ZlZlmrZsYtu
  $r$   c           	         U(       a+  UR                  U SU SU R                  U5       S35        U$ UR                  S5        U$ )Nz and contains(ro  rA   r   re  ra  s       r%   xpath_attrib_substringmatch-GenericTranslator.xpath_attrib_substringmatch  sS     &tfBt/A/A%/H.IK
  $r$   r   N)descendant-or-self::)ry   r7   rv   r7   rX   r7   )r|  F)ru   r   rv   r7   rr   rW   rX   r7   )r   r'   r   r   rX   r'   )r   r7   rX   r7   )r   r   rX   r'   )r   r
   rX   r'   )r   r   rX   r'   )r   r   rX   r'   )r   r   rX   r'   )r   r   rX   r'   )r   r   rX   r'   )r   r   rX   r'   )ru   r   rX   r'   )r   r	   rX   r'   )r   r   rX   r'   )ru   r   rX   r'   )r   r'   r   r'   rX   r'   )FT)
r   r'   r   r   r  rW   rI   rW   rX   r'   r   r'   r   r   rX   r'   r   r'   rX   r'   )r   r'   r   r7   r   r[   rX   r'   )Ir   r   r    r!   r"   r   r   id_attributelang_attributer   r   r   r'   r   rz   rs   r   staticmethodrH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r"  r&  r+  r.  r6  r:  r?  rC  rF  rJ  rO  rR  rU  rX  r[  r^  xpath_link_pseudoxpath_visited_pseudoxpath_hover_pseudoxpath_active_pseudoxpath_focus_pseudoxpath_target_pseudoxpath_enabled_pseudoxpath_disabled_pseudoxpath_checked_pseudorb  r   rh  r   rq  rt  rw  rz  r#   r   r$   r%   rG   rG      sM   *  	 	" L  N   %!&"' M
6 -*/	!+!+ !+ $(	!+
 
!+F	D	D0=	D		D  	'W($	?	3D6VF
,;;&/;	;%55&/5	588&/8	8

&/
	
==&/=	=

&/
	
NN&/N	N "BB B 	B
 B 
BHII*2I	I
SS*2S	S

*2
	

P
P*2
P	
PI5(FFU
U
DS
F( -/-.-./0/&)2<	&)2<			&)	2<			

&)
2<
	


&)
2<
	
		&)	2<			

&)
2<
	


&)
2<
	
r$   rG   c                  \    \ rS rSrSrS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S
rg)HTMLTranslatori   a  
Translator for (X)HTML documents.

Has a more useful implementation of some pseudo-classes based on
HTML-specific element names and attribute names, as described in
the `HTML5 specification`_. It assumes no-quirks mode.
The API is the same as :class:`GenericTranslator`.

.. _HTML5 specification: http://www.w3.org/TR/html5/links.html#selectors

:param xhtml:
    If false (the default), element names and attribute names
    are case-insensitive.

langc                <    Xl         U(       d  SU l        SU l        g g )NT)xhtmlr   r   )r.   r  s     r%   r0   HTMLTranslator.__init__3  s    
,0D).2D+ r$   c                $    UR                  S5      $ )Nz(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio'))r=  r>  s     r%   r  #HTMLTranslator.xpath_checked_pseudo:  s    "";
 	
r$   c                0   UR                  5       S/S/4;  a  [        SUR                  < 35      eUR                  S   R                  nU(       d   eU R	                  UR                  5       S-   5      nUR                  SU R                   SU S35      $ )	Nr1  r2  r9  r   r   z<ancestor-or-self::*[@lang][1][starts-with(concat(translate(@zE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), z)])r4  r   r  r   rH   r   rC   r  )r.   r   r   r   rl  s        r%   r:  "HTMLTranslator.xpath_lang_functionC  s    ""$hZ',CC!EhFXFXE[\  ""1%++u  !45""--. /E	
 	
r$   c                $    UR                  S5      $ )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')r=  r>  s     r%   r   HTMLTranslator.xpath_link_pseudoS  s    ""O
 	
r$   c                $    UR                  S5      $ )Na  
        (
            @disabled and
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea' or
                name(.) = 'command' or
                name(.) = 'fieldset' or
                name(.) = 'optgroup' or
                name(.) = 'option'
            )
        ) or (
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea'
            )
            and ancestor::fieldset[@disabled]
        )
        r=  r>  s     r%   r  $HTMLTranslator.xpath_disabled_pseudo[  s    ""
 	
r$   c                $    UR                  S5      $ )Na'  
        (
            @href and (
                name(.) = 'a' or
                name(.) = 'link' or
                name(.) = 'area'
            )
        ) or (
            (
                name(.) = 'command' or
                name(.) = 'fieldset' or
                name(.) = 'optgroup'
            )
            and not(@disabled)
        ) or (
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea' or
                name(.) = 'keygen'
            )
            and not (@disabled or ancestor::fieldset[@disabled])
        ) or (
            name(.) = 'option' and not(
                @disabled or ancestor::optgroup[@disabled]
            )
        )
        r=  r>  s     r%   r  #HTMLTranslator.xpath_enabled_pseudoy  s    ""
 	
r$   )r   r   r  N)F)r  rW   rX   rY   r~  r}  )r   r   r    r!   r"   r  r0   r  r:  r  r  r  r#   r   r$   r%   r  r     s,      N3

 

< 
r$   r  ))r"   
__future__r   recollections.abcr   typingr   r   r   cssselect.parserr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   RuntimeErrorr   r'   compilesplitr   matchr   rk  rG   r  r   r$   r%   <module>r     s    # 	 $ 0 0    ( &>m\ >A AH F+11 
 zz67== JJ1288 W
 W
ty
& y
r$   