+
    l|i܁                       R t ^ RIHt ^ RIt^ RIHtHt ^ RIHtH	t	H
t
HtHtHtHtHtHtHtHtHtHtHtHtHtHt ]'       d   ^ RIHt ^ RIHt  ! R R]]4      t ! R	 R
4      t]P@                  ! R4      PB                  t"]P@                  ! R4      PF                  t$]P@                  ! R4      PF                  t% ! R R4      t& ! R R]&4      t'R# )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)TYPE_CHECKINGcast)AttribClassCombinedSelectorElementFunctionHashMatchingNegationPseudoPseudoElementRelationSelectorSelectorErrorSpecificityAdjustmentTreeparseparse_series)Callable)Selfc                      ] tR t^.tRtRtR# )ExpressionErrorz3Unknown or unsupported selector (eg. pseudo-class). N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       1/usr/lib/python3/dist-packages/cssselect/xpath.pyr   r   .   s    =r!   r   c                  v    ] tR t^5tRR R lltR R ltR R ltRR R lltR	 R
 ltR R lt	RR R llt
RtR# )	XPathExprc          
     ,    V ^8  d   QhRRRRRRRRRR/# )	   pathstrelement	conditionstar_prefixboolreturnNoner   )formats   "r"   __annotate__XPathExpr.__annotate__6   s<     	# 	#	# 	# 		#
 	# 
	#r!   c                	*    Wn         W n        W0n        R # N)r'   r)   r*   )selfr'   r)   r*   r+   s   &&&&&r"   __init__XPathExpr.__init__6   s     	"r!   c                   V ^8  d   QhRR/# r&   r-   r(   r   )r/   s   "r"   r0   r1   A   s       r!   c                	    \        V P                  4      \        V P                  4      ,           pV P                  '       d   VR V P                   R2,          pV# []r(   r'   r)   r*   )r4   r'   s   & r"   __str__XPathExpr.__str__A   sC    499~DLL 11>>>a'q))Dr!   c                   V ^8  d   QhRR/# r8   r   )r/   s   "r"   r0   r1   G   s     4 4# 4r!   c                	:    V P                   P                   R V  R2# r:   )	__class__r   r4   s   &r"   __repr__XPathExpr.__repr__G   s     ..))*!D633r!   c               $    V ^8  d   QhRRRRRR/# )r&   r*   r(   
conjuctionr-   r   r   )r/   s   "r"   r0   r1   J   s!      s   r!   c                	p    V P                   '       d   R V P                    RV RV R2V n         V # Wn         V # )(z) z ())r*   )r4   r*   rG   s   &&&r"   add_conditionXPathExpr.add_conditionJ   s?    >>>  0:,b1MDN  'Nr!   c                   V ^8  d   QhRR/# r&   r-   r.   r   )r/   s   "r"   r0   r1   Q   s      t r!   c                	    V P                   R 8X  d   R# V P                  R\        P                  V P                   4       24       R V n         R# )*Nz	name() = )r)   rK   GenericTranslatorxpath_literalrC   s   &r"   add_name_testXPathExpr.add_name_testQ   s>    <<3Y'8'F'Ft||'T&UVWr!   c                   V ^8  d   QhRR/# rN   r   )r/   s   "r"   r0   r1   X   s       r!   c                8    V ;P                   R,          un         R# )zM
Append '*/' to the path to keep the context constrained
to a single parent.
*/N)r'   rC   s   &r"   add_star_prefixXPathExpr.add_star_prefixX   s    
 			T	r!   Nc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r&   combinerr(   otherr$   closing_combiner
str | Nonehas_inner_conditionr,   r-   r   r   )r/   s   "r"   r0   r1   _   s<        %	
 " 
r!   c                	   \        V 4      V,           pVP                  R 8w  d   WRP                  ,          pWPn        V'       g@   V'       d   VP                  V,           MVP                  V n        VP                  V n        V # VP                  V n        VP                  '       d2   V ;P                  RVP                  ,           R,           ,          un        V'       d   V ;P                  V,          un        V # )rW   r;   r<   r=   )r4   r[   r\   r]   r_   r'   s   &&&&& r"   joinXPathExpr.join_   s     4y8#::JJD	"4D 00%-- L #__DN  !==DLeoo 5 ;; 00r!   )r*   r)   r'   ) rP   rc   F)and)NF)r   r   r   r   r5   r>   rD   rK   rS   rX   ra   r    r   r!   r"   r$   r$   5   s*    	#4 r!   r$   z('+)z^[a-zA-Z_][a-zA-Z0-9_.-]*$z^[^ \t\r\n\f]+$c                     ] tR t^tRtRRRRRRRR	/tR
R
RRRRRRRRRRRRRR/tRtRtRt	Rt
Rt]tR~R R lltRR R lltR  R! lt]R" R# l4       tR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 ltR4 R5 ltR6 R7 ltR8 R9 ltR: R; ltR< R= ltR> R? lt R@ RA lt!RB RC lt"RD RE lt#RF RG lt$RH RI lt%RJ RK lt&RRL RM llt'RN RO lt(RP RQ lt)RR RS lt*RT RU lt+RV RW lt,RX RY lt-RZ R[ lt.R\ R] lt/R^ R_ lt0R` Ra lt1Rb Rc lt2Rd Re lt3Rf Rg lt4Rh Ri lt5Rj Rk lt6]6t7]6t8]6t9]6t:]6t;]6t<]6t=]6t>]6t?Rl Rm lt@Rn Ro ltARp Rq ltBRr Rs ltCRt Ru ltDRv Rw ltERx Ry ltFRz R{ ltGR|tHR}# )rQ   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=equalsz~=includesz|=	dashmatchz^=prefixmatchz$=suffixmatchz*=substringmatchz!=	differentidzxml:langFc               $    V ^8  d   QhRRRRRR/# )r&   cssr(   prefixr-   r   )r/   s   "r"   r0   GenericTranslator.__annotate__   s!     
 
 
S 
c 
r!   c                P   a a RP                  VV 3R l\        V4       4       4      # )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  L   <"   T F  pSP                  VSR R7      x  K  	  R# 5i)T)translate_pseudo_elementsN)selector_to_xpath).0selectorrz   r4   s   & r"   	<genexpr>1GenericTranslator.css_to_xpath.<locals>.<genexpr>   s-      
& ""8Vt"TT&s   !$)ra   r   )r4   ry   rz   s   f&fr"   css_to_xpathGenericTranslator.css_to_xpath   s'    & zz 
!#J
 
 	
r!   c               (    V ^8  d   QhRRRRRRRR/# )r&   r   r   rz   r(   r~   r,   r-   r   )r/   s   "r"   r0   r{      s2     !+ !+!+ !+ $(	!+
 
!+r!   c                H   \        VRR4      pV'       g   \        RV: 24      hV P                  V4      p\        WPP                  4      '       g   Q hV'       d.   VP
                  '       d   V P                  WQP
                  4      pT;'       g    R\        V4      ,           # )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 rc   )getattr	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr(   )r4   r   rz   r~   treer   s   &&&&  r"   r   #GenericTranslator.selector_to_xpath   s    4 x5>xlKLL

4 %!3!34444$)@)@)@--e5L5LME"E
**r!   c               $    V ^8  d   QhRRRRRR/# )r&   r   r$   r   r   r-   r   )r/   s   "r"   r0   r{     s)     	D 	D	D0=	D		Dr!   c                    \        R4      h)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   )r4   r   r   s   &&&r"   r   &GenericTranslator.xpath_pseudo_element  s     BCCr!   c                    V ^8  d   QhRRRR/# )r&   sr(   r-   r   )r/   s   "r"   r0   r{     s        r!   c                	   \        V 4      p R V 9  d	   R V  R 2p V # RV 9  d	   RV  R2p V # \        V 4       Uu. uF   pV'       g   K  R V9   d   RV R2MR V R 2NK"  	  ppRP                  RP                  V4      4      p V # u upi )'"z
concat({}),)r(   split_at_single_quotesr/   ra   )r   partparts_quoteds   &  r"   rR   GenericTranslator.xpath_literal  s    Fa<A3aA  \A3aA 	 3155D <sd{!D6!D6;5  
 ##CHH\$:;As   
BBc                    V ^8  d   QhRRRR/# )r&   parsed_selectorr   r-   r$   r   )r/   s   "r"   r0   r{   !  s     	' 	'T 	'i 	'r!   c           	         \        V4      P                  p\        R\        V RVP	                  4        2R4      4      pVf   \        V R24      hV! V4      # )z%Translate any parsed selector object.z"Callable[[Tree], XPathExpr] | Nonexpath_Nz is not supported.)typer   r   r   lowerr   )r4   r   	type_namemethods   &&  r"   r   GenericTranslator.xpath!  s_    )22	0DF9??#4"56=
 >!YK/A"BCCo&&r!   c                    V ^8  d   QhRRRR/# )r&   combinedr   r-   r$   r   )r/   s   "r"   r0   r{   .  s     W W/? WI Wr!   c           	         V P                   VP                  ,          p\        R\        V RV R24      4      pV! V P	                  VP
                  4      V P	                  VP                  4      4      # )zTranslate a combined selector.+Callable[[XPathExpr, XPathExpr], XPathExpr]r   _combinator)combinator_mapping
combinatorr   r   r   r   subselector)r4   r   r   r   s   &&  r"   xpath_combinedselector(GenericTranslator.xpath_combinedselector.  se    ,,X-@-@A
9DF:,k:;
 djj!2!23TZZ@T@T5UVVr!   c                    V ^8  d   QhRRRR/# )r&   negationr   r-   r$   r   )r/   s   "r"   r0   r{   7  s     ( (x (I (r!   c                	   V P                  VP                  4      pV P                  VP                  4      pVP                  4        VP                  '       d    VP                  R VP                   R24      # VP                  R4      # )not(rJ   0)r   r   r   rS   r*   rK   )r4   r   r   	sub_xpaths   &&  r"   xpath_negation GenericTranslator.xpath_negation7  st    

8,,-JJx334	!&&i.A.A-B!'DEE""3''r!   c                    V ^8  d   QhRRRR/# )r&   relationr   r-   r$   r   )r/   s   "r"   r0   r{   ?  s     $ $x $I $r!   c                	,   V P                  VP                  4      pVP                  pVP                  pV P                  VP                  4      p\        R \        V RV P                  \        RVP                  4      ,           R24      4      pV! W%4      # )r   xpath_relation_r(   r   )	r   r   r   r   r   r   r   r   value)r4   r   r   r   r   rightr   s   &&     r"   xpath_relation GenericTranslator.xpath_relation?  s    

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

;2239!$"9"9$ujFVFV:W"X!YYde
 e##r!   c                    V ^8  d   QhRRRR/# )r&   matchingr   r-   r$   r   )r/   s   "r"   r0   r{   M  s      x I r!   c                	*   V P                  VP                  4      pVP                   Uu. uF  q0P                  V4      NK  	  ppV FC  pVP                  4        VP                  '       g   K'  VP                  VP                  R 4       KE  	  V# u upi orr   r   selector_listrS   r*   rK   r4   r   r   r   exprses   &&    r"   xpath_matching GenericTranslator.xpath_matchingM  w    

8,,-6>6L6LM6L(H%6LMAOO{{{##AKK6   N   Bc                    V ^8  d   QhRRRR/# )r&   r   r   r-   r$   r   )r/   s   "r"   r0   r{   V  s      4I i r!   c                	*   V P                  VP                  4      pVP                   Uu. uF  q0P                  V4      NK  	  ppV FC  pVP                  4        VP                  '       g   K'  VP                  VP                  R 4       KE  	  V# u upi r   r   r   s   &&    r"   xpath_specificityadjustment-GenericTranslator.xpath_specificityadjustmentV  r   r   c                    V ^8  d   QhRRRR/# )r&   functionr	   r-   r$   r   )r/   s   "r"   r0   r{   _  s     	? 	?x 	?I 	?r!   c                
   RP                  VP                  P                  RR4      4      p\        R\	        WR4      4      pV'       g   \        RVP                   R24      hV! V P                  VP                  4      V4      # )z$Translate a functional pseudo-class.zxpath_{}_function-_z1Callable[[XPathExpr, Function], XPathExpr] | NoneNThe pseudo-class :z() is unknown)r/   namereplacer   r   r   r   r   )r4   r   method_namer   s   &&  r"   xpath_function GenericTranslator.xpath_function_  st    )001F1FsC1PQ?Dt,
 !$6x}}o]"STTdjj!2!23X>>r!   c                    V ^8  d   QhRRRR/# )r&   pseudor   r-   r$   r   )r/   s   "r"   r0   r{   j  s     
3 
36 
3i 
3r!   c                   RP                  VP                  P                  RR4      4      p\        R\	        WR4      4      pV'       g   \        RVP                   R24      hV! V P                  VP                  4      4      # )zTranslate a pseudo-class.zxpath_{}_pseudor   r   z'Callable[[XPathExpr], XPathExpr] | NoneNr   z is unknown)r/   identr   r   r   r   r   r   )r4   r   r   r   s   &&  r"   xpath_pseudoGenericTranslator.xpath_pseudoj  sp    '..v||/C/CC/MN5Dt,
 !$6v||nK"PQQdjj122r!   c                    V ^8  d   QhRRRR/# )r&   r   r   r-   r$   r   )r/   s   "r"   r0   r{   v  s     D DV D	 Dr!   c                   V P                   VP                  ,          p\        R\        V RV 24      4      pV P                  '       d   VP
                  P                  4       pMVP
                  p\        V4      pVP                  '       d1   VP                   RV 2pT;'       d    \        VP                  4      pV'       d   RV,           pMRV P                  V4       R2pVP                  f   RpMWV P                  '       d0   \        RVP                  P                  4      P                  4       pMVP                  P                  pV! V P                  VP                  4      Wg4      # )	z Translate an attribute selector.z1Callable[[XPathExpr, str, str | None], XPathExpr]xpath_attrib_:@zattribute::*[name() = r<   Nr(   )attribute_operator_mappingoperatorr   r   lower_case_attribute_namesattribr   is_safe_name	namespacerR   r   lower_case_attribute_valuesr   r   )r4   r   r   r   r   safer   r   s   &&      r"   xpath_attribGenericTranslator.xpath_attribv  s/   2283D3DE?DM(45
 ***??((*D??DD!(()4&1D<<L););<D4ZF-d.@.@.F-GqIF>>!E--- 4 45;;=ENN((Edjj!2!23VCCr!   c                    V ^8  d   QhRRRR/# )r&   class_selectorr   r-   r$   r   )r/   s   "r"   r0   r{     s     V V% VI Vr!   c                r    V P                  VP                  4      pV P                  VRVP                  4      # )zTranslate a class selector.z@class)r   r   xpath_attrib_includes
class_name)r4   r   r   s   && r"   xpath_classGenericTranslator.xpath_class  s3     

>223))%>;T;TUUr!   c                    V ^8  d   QhRRRR/# )r&   id_selectorr
   r-   r$   r   )r/   s   "r"   r0   r{     s     F Fd Fy Fr!   c                r    V P                  VP                  4      pV P                  VRVP                  4      # )zTranslate an ID selector.z@id)r   r   xpath_attrib_equalsrw   )r4   r   r   s   && r"   
xpath_hashGenericTranslator.xpath_hash  s/    

;//0''uknnEEr!   c                    V ^8  d   QhRRRR/# )r&   r   r   r-   r$   r   )r/   s   "r"   r0   r{     s      g ) r!   c                   VP                   pV'       g   RpRpM6\        \        V4      4      pV P                  '       d   VP	                  4       pVP
                  '       d:   VP
                   RV 2pT;'       d    \        \        VP
                  4      4      pV P                  VR7      pV'       g   VP                  4        V# )z'Translate a type or universal selector.rP   Tr   )r)   )r)   r,   r   lower_case_element_namesr   r   r   rS   )r4   r   r)   r   r   s   &&   r"   xpath_elementGenericTranslator.xpath_element  s    ""GDW-.D,,,!--/ "++,AgY7GBBDh.@.@!ABD""7"3!r!   c               $    V ^8  d   QhRRRRRR/# r&   leftr$   r   r-   r   )r/   s   "r"   r0   r{     s$     ; ;;&/;	;r!   c                &    VP                  RV4      # )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/ra   r4   r  r   s   &&&r"   xpath_descendant_combinator-GenericTranslator.xpath_descendant_combinator  s     yy2E::r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     s!     % %9 %Y %9 %r!   c                &    VP                  RV4      # )z#right is an immediate child of left/r
  r  s   &&&r"   xpath_child_combinator(GenericTranslator.xpath_child_combinator  s    yye$$r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     s$     5 55&/5	5r!   c                h    VP                  RV4      pVP                  4        VP                  R4      # )z)right is a sibling immediately after left/following-sibling::zposition() = 1)ra   rS   rK   )r4   r  r   r   s   &&& r"    xpath_direct_adjacent_combinator2GenericTranslator.xpath_direct_adjacent_combinator  s3     		0%8""#344r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     s$     8 88&/8	8r!   c                &    VP                  RV4      # )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               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     $     
 

&/
	
r!   c                ,    VP                  RVRRR7      # )zHright is a child, grand-child or further descendant of left; select leftz[descendant::r<   T)r]   r_   r
  r  s   &&&r"   $xpath_relation_descendant_combinator6GenericTranslator.xpath_relation_descendant_combinator  s#     yyUSd  
 	
r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     s$     = ==&/=	=r!   c                *    VP                  RVRR7      # )z0right is an immediate child of left; select leftz[./r<   r]   r
  r  s   &&&r"   xpath_relation_child_combinator1GenericTranslator.xpath_relation_child_combinator  s     yyy<<r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     r  r!   c                @    VP                  RVP                   R24      # )z6right is a sibling immediately after left; select leftz following-sibling::*[(name() = 'z') and (position() = 1)])rK   r)   r  s   &&&r"   )xpath_relation_direct_adjacent_combinator;GenericTranslator.xpath_relation_direct_adjacent_combinator  s(     !!.u}}o=UV
 	
r!   c               $    V ^8  d   QhRRRRRR/# r  r   )r/   s   "r"   r0   r{     s)     N NN&/N	Nr!   c                *    VP                  RVRR7      # )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r<   r#  r
  r  s   &&&r"   +xpath_relation_indirect_adjacent_combinator=GenericTranslator.xpath_relation_indirect_adjacent_combinator  s     yy/yMMr!   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r&   r   r$   r   r	   lastr,   rS   r-   r   )r/   s   "r"   r0   r{     sC     B BB B 	B
 B 
Br!   c                	$  a  \        VP                  4      w  rVT^,
          pT^8X  d
   T^ 8:  d   T# T^ 8  d   T^ 8  d   TP	                  R4      # T'       d   RMTP
                   p	T'       g   RT	 R2p
MRT	 R2p
T^ 8X  d   TP	                  T
 RT 24      # . pT^ 8  d   T^ 8  d   TP                  T
 R	T 24       MTP                  T
 R
T 24       \        T4      ^8w  d=   T
pT) \        T4      ,          pT^ 8w  d
   RT RT R2pTP                  T RT R24       \        T4      ^8  d   RMRoTP	                  RP                  T3R lT 4       4      4       T#   \         d!   p\        R TP                  : R24      ThRp?ii ; i)zInvalid series: 'r   Nr   rP   count(preceding-sibling::rJ   count(following-sibling:: = z >= z <= rI   z +z mod z = 0z(%s)z%sz and c              3  6   <"   T F  pSV,          x  K  	  R # 5ir3   r   )r   
expressiontemplates   & r"   r   =GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>h  s     M:J..s   )
r   	arguments
ValueErrorr   rK   r)   appendabslenra   )r4   r   r   r/  rS   abexb_min_1nodetestsiblings_countexpressionsr  b_negr6  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$ $F/F

Fc               $    V ^8  d   QhRRRRRR/# r&   r   r$   r   r	   r-   r   )r/   s   "r"   r0   r{   l  s)     I II*2I	Ir!   c                	(    V P                  WR R7      # )T)r/  )rE  r4   r   r   s   &&&r"   xpath_nth_last_child_function/GenericTranslator.xpath_nth_last_child_functionl  s     ,,U4,HHr!   c               $    V ^8  d   QhRRRRRR/# rH  r   )r/   s   "r"   r0   r{   q  s)     S SS*2S	Sr!   c                	`    VP                   R 8X  d   \        R4      hV P                  WRR7      # )rP   "*:nth-of-type() is not implementedF)rS   r)   r   rE  rJ  s   &&&r"   xpath_nth_of_type_function,GenericTranslator.xpath_nth_of_type_functionq  s2     ==C!"FGG,,UE,RRr!   c               $    V ^8  d   QhRRRRRR/# rH  r   )r/   s   "r"   r0   r{   x  s$     
 

*2
	
r!   c                	b    VP                   R 8X  d   \        R4      hV P                  WRRR7      # )rP   rO  TF)r/  rS   rP  rJ  s   &&&r"   xpath_nth_last_of_type_function1GenericTranslator.xpath_nth_last_of_type_functionx  s;     ==C!"FGG,,$e - 
 	
r!   c               $    V ^8  d   QhRRRRRR/# rH  r   )r/   s   "r"   r0   r{     s)     
P 
P
P*2
P	
Pr!   c                	    VP                  4       R .R.39  d   \        RVP                  : 24      h\        RVP                  ^ ,          P                  4      pVP                  RV P                  V4       R24      # )STRINGIDENTz7Expected a single string or ident for :contains(), got r(   zcontains(., rJ   argument_typesr   r8  r   r   rK   rR   r4   r   r   r   s   &&& r"   xpath_contains_function)GenericTranslator.xpath_contains_function  s    
 ""$hZ',CC!I(J\J\I_`  UH..q1778""\$2D2DU2K1LA#NOOr!   c               $    V ^8  d   QhRRRRRR/# rH  r   )r/   s   "r"   r0   r{     s&     I I Ih I9 Ir!   c                	    VP                  4       R .R.39  d   \        RVP                  : 24      h\        RVP                  ^ ,          P                  4      pVP                  RV P                  V4       R24      # )rY  rZ  3Expected a single string or ident for :lang(), got r(   zlang(rJ   r[  r]  s   &&& r"   xpath_lang_function%GenericTranslator.xpath_lang_function  s    ""$hZ',CC!EhFXFXE[\  UH..q1778""U4+=+=e+D*EQ#GHHr!   c                    V ^8  d   QhRRRR/# r&   r   r$   r-   r   )r/   s   "r"   r0   r{     s     5 5y 5Y 5r!   c                	$    VP                  R 4      # )znot(parent::*)rK   r4   r   s   &&r"   xpath_root_pseudo#GenericTranslator.xpath_root_pseudo  s    ""#344r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     ( (	 (i (r!   c                	$    VP                  R 4      # )1rh  ri  s   &&r"   xpath_scope_pseudo$GenericTranslator.xpath_scope_pseudo  s    ""3''r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     F Fi FI Fr!   c                	$    VP                  R 4      # )zcount(preceding-sibling::*) = 0rh  ri  s   &&r"   xpath_first_child_pseudo*GenericTranslator.xpath_first_child_pseudo      ""#DEEr!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     F FY F9 Fr!   c                	$    VP                  R 4      # )zcount(following-sibling::*) = 0rh  ri  s   &&r"   xpath_last_child_pseudo)GenericTranslator.xpath_last_child_pseudo  ru  r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     U U	 Ui Ur!   c                	x    VP                   R 8X  d   \        R4      hVP                  RVP                    R24      # )rP   z"*:first-of-type is not implementedr1  ) = 0r)   r   rK   ri  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 ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     U Uy UY Ur!   c                	x    VP                   R 8X  d   \        R4      hVP                  RVP                    R24      # )rP   z!*:last-of-type is not implementedr2  r|  r}  ri  s   &&r"   xpath_last_of_type_pseudo+GenericTranslator.xpath_last_of_type_pseudo  s9    ==C!"EFF""%>u}}oU#STTr!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     D DY D9 Dr!   c                	$    VP                  R 4      # )zcount(parent::*/child::*) = 1rh  ri  s   &&r"   xpath_only_child_pseudo)GenericTranslator.xpath_only_child_pseudo  s    ""#BCCr!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     S Sy SY Sr!   c                	x    VP                   R 8X  d   \        R4      hVP                  RVP                    R24      # )rP   z!*:only-of-type is not implementedzcount(parent::*/child::z) = 1r}  ri  s   &&r"   xpath_only_of_type_pseudo+GenericTranslator.xpath_only_of_type_pseudo  s9    ==C!"EFF""%<U]]O5#QRRr!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     F F	 Fi Fr!   c                	$    VP                  R 4      # )znot(*) and not(string-length())rh  ri  s   &&r"   xpath_empty_pseudo$GenericTranslator.xpath_empty_pseudo  ru  r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r{     s     ( () (	 (r!   c                $    VP                  R4      # )z:Common implementation for pseudo-classes that never match.r   rh  ri  s   &&r"   pseudo_never_matches&GenericTranslator.pseudo_never_matches  s    ""3''r!   c               (    V ^8  d   QhRRRRRRRR/# r&   r   r$   r   r(   r   r^   r-   r   )r/   s   "r"   r0   r{     ,      &)2<	r!   c                	<    V'       d   Q hVP                  V4       V# r3   rh  r4   r   r   r   s   &&&&r"   xpath_attrib_exists%GenericTranslator.xpath_attrib_exists  s     yD!r!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     r  r!   c                	\    Vf   Q hVP                  V RV P                  V4       24       V# )Nr3  rK   rR   r  s   &&&&r"   r   %GenericTranslator.xpath_attrib_equals  s:        tfC(:(:5(A'BCDr!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     ,     	 		&)	2<			r!   c           
     	    Vf   Q hV'       d,   VP                  RV RV RV P                  V4       24       V# VP                  V RV P                  V4       24       V# )Nr   z) or z != r  r  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               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     ,     
 

&)
2<
	
r!   c                	    V'       dM   \        V4      '       d<   V P                  R V,           R ,           4      pVP                  V RV RV R24       V# VP                  R4       V# )rf   z* and contains(concat(' ', normalize-space(z	), ' '), rJ   r   )is_non_whitespacerR   rK   )r4   r   r   r   args   &&&& r"   r   'GenericTranslator.xpath_attrib_includes  so     &u--$$S5[3%67C&B4&	RUQVVWX
  $r!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     r  r!   c                	    Vf   Q hV P                  V4      pV P                  VR,           4      pVP                  V RV RV RV RV R2
4       V# )Nr   z and (r3  z or starts-with(, z)))rR   rK   )r4   r   r   r   r  arg_dashs   &&&&  r"   xpath_attrib_dashmatch(GenericTranslator.xpath_attrib_dashmatch  sl          '%%eck2fF4&C5(8b
"M	
 r!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     r  r!   c           	     	    V'       d,   VP                  V R V RV P                  V4       R24       V# VP                  R4       V# )z and starts-with(r  rJ   r   r  r  s   &&&&r"   xpath_attrib_prefixmatch*GenericTranslator.xpath_attrib_prefixmatch  sT     &)$r$2D2DU2K1LAN
  $r!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{   	  r  r!   c                	    V'       dA   VP                  V R V RV R\        V4      ^,
           RV P                  V4       2	4       V# VP                  R4       V# )z and substring(z, string-length(z)-z) = r   )rK   r<  rR   r  s   &&&&r"   xpath_attrib_suffixmatch*GenericTranslator.xpath_attrib_suffixmatch	  sk     &v-=dV2c%jSTnEUUYZ^ZlZlmrZsYtu
  $r!   c               (    V ^8  d   QhRRRRRRRR/# r  r   )r/   s   "r"   r0   r{     r  r!   c           	     	    V'       d,   VP                  V R V RV P                  V4       R24       V# VP                  R4       V# )z and contains(r  rJ   r   r  r  s   &&&&r"   xpath_attrib_substringmatch-GenericTranslator.xpath_attrib_substringmatch  sS     &tfBt/A/A%/H.IK
  $r!   r   N)descendant-or-self::)r  F)FT)Ir   r   r   r   r   r   r   id_attributelang_attributer  r   r   r$   r   r   r   r   staticmethodrR   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r$  r(  r,  rE  rK  rQ  rU  r^  rc  rj  ro  rs  rx  r~  r  r  r  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_pseudor  r   r  r   r  r  r  r  r    r   r!   r"   rQ   rQ      s   * 	\W 	 	(Xjkmmk	" L  N   %!&"' M
0!+F	D  	'W($	?
3D6VF
,;%58
=
NBHI
S

PI5(FFU
U
DS
F( -/-.-./0/	

	

 
r!   rQ   c                  j    ] tR tRtRtRtRR R lltR R ltR R	 ltR
 R lt	R R lt
R R ltRtR# )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                    V ^8  d   QhRRRR/# )r&   xhtmlr,   r-   r.   r   )r/   s   "r"   r0   HTMLTranslator.__annotate__5  s     3 3d 3t 3r!   c                	B    Wn         V'       g   R V n        R V n        R# R# )TN)r  r  r   )r4   r  s   &&r"   r5   HTMLTranslator.__init__5  s    
,0D).2D+ r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r  <  s     
 
) 
	 
r!   c                	$    VP                  R 4      # )z(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio'))rh  ri  s   &&r"   r  #HTMLTranslator.xpath_checked_pseudo<  s    "";
 	
r!   c               $    V ^8  d   QhRRRRRR/# rH  r   )r/   s   "r"   r0   r  E  s!     
 
 
h 
9 
r!   c                	D   VP                  4       R .R.39  d   \        RVP                  : 24      hVP                  ^ ,          P                  pV'       g   Q hV P	                  VP                  4       R,           4      pVP                  RV P                   RV R24      # )rY  rZ  rb  r   z<ancestor-or-self::*[@lang][1][starts-with(concat(translate(@zE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), z)])r\  r   r8  r   rR   r   rK   r  )r4   r   r   r   r  s   &&&  r"   rc  "HTMLTranslator.xpath_lang_functionE  s    ""$hZ',CC!EhFXFXE[\  ""1%++u  !45""--. /E	
 	
r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r  U  s     
 
y 
Y 
r!   c                	$    VP                  R 4      # )zA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')rh  ri  s   &&r"   r   HTMLTranslator.xpath_link_pseudoU  s    ""O
 	
r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r  ]  s     
 
9 
 
r!   c                	$    VP                  R 4      # )a  
        (
            @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]
        )
        rh  ri  s   &&r"   r  $HTMLTranslator.xpath_disabled_pseudo]  s    ""
 	
r!   c                    V ^8  d   QhRRRR/# rf  r   )r/   s   "r"   r0   r  {  s      
  
)  
	  
r!   c                	$    VP                  R 4      # )a'  
        (
            @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]
            )
        )
        rh  ri  s   &&r"   r  #HTMLTranslator.xpath_enabled_pseudo{  s    ""
 	
r!   )r   r  r  N)F)r   r   r   r   r   r  r5   r  rc  r  r  r  r    r   r!   r"   r  r  "  s1      N3

 

< 
  
r!   r  )(r   
__future__r   retypingr   r   cssselect.parserr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   collections.abcr   typing_extensionsr   RuntimeErrorr   r$   compilesplitr   matchr   r  rQ   r  r   r!   r"   <module>r     s    # 	 &    ( ( '>m\ >A AH F+11 
 zz67== JJ1288 X
 X
vy
& y
r!   