
     h4                       d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ erddlmZ  G d d	ee      Z G d
 d      Z  ejB                  d      jD                  Z# ejB                  d      jH                  Z% ejB                  d      jH                  Z& G d d      Z' G d de'      Z(y)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                      e Zd ZdZy)ExpressionErrorz3Unknown or unsupported selector (eg. pseudo-class).N)__name__
__module____qualname____doc__     O/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/cssselect/xpath.pyr   r   -   s    =r!   r   c                  z    e Zd Z	 	 	 	 d		 	 	 	 	 	 	 	 	 d
dZddZddZdddZddZddZ	 	 d	 	 	 	 	 	 	 	 	 ddZ	y)	XPathExprc                .    || _         || _        || _        y N)pathelement	condition)selfr'   r(   r)   star_prefixs        r"   __init__zXPathExpr.__init__5   s     	"r!   c                    t        | j                        t        | j                        z   }| j                  r|d| j                   dz  }|S N[]strr'   r(   r)   )r*   r'   s     r"   __str__zXPathExpr.__str__@   sA    499~DLL 11>>a'q))Dr!   c                :    | j                   j                   d|  dS r.   )	__class__r   r*   s    r"   __repr__zXPathExpr.__repr__F   s     ..))*!D633r!   c                f    | j                   rd| j                    d| d| d| _         | S || _         | S )N(z) z ())r)   )r*   r)   
conjuctions      r"   add_conditionzXPathExpr.add_conditionI   s?    >>  0:,b1MDN  'DNr!   c                    | j                   dk(  ry | j                  dt        j                  | j                                 d| _         y )N*z	name() = )r(   r<   GenericTranslatorxpath_literalr6   s    r"   add_name_testzXPathExpr.add_name_testP   s>    <<3Y'8'F'Ft||'T&UVWr!   c                .    | xj                   dz  c_         y)ze
        Append '*/' to the path to keep the context constrained
        to a single parent.
        */N)r'   r6   s    r"   add_star_prefixzXPathExpr.add_star_prefixW   s    
 			T	r!   Nc                   t        |       |z   }|j                  dk7  r||j                  z  }|| _        |s5|r|j                  |z   n|j                  | _        |j                  | _        | S |j                  | _        |j                  r%| xj                  d|j                  z   dz   z  c_        |r| xj                  |z  c_        | S )NrC   r/   r0   r1   )r*   combinerotherclosing_combinerhas_inner_conditionr'   s         r"   joinzXPathExpr.join^   s     4y8#::EJJD	"4D 00%-- L #__DN  !==DLeoo 5 ;; 00r!   ) r>   rK   F)
r'   r2   r(   r2   r)   r2   r+   boolreturnNone)rM   r2   )and)r)   r2   r;   r2   rM   r   )rM   rN   )NF)
rF   r2   rG   r$   rH   
str | NonerI   rL   rM   r   )
r   r   r   r,   r3   r7   r<   rA   rD   rJ   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            	      8   e Zd ZdZdddddZddd	d
dddddZdZdZdZdZ	dZ
eZdDdEdZ	 	 dF	 	 	 	 	 	 	 dGdZ	 	 	 	 	 	 dHdZedId       ZdJdZdKdZdLdZdMdZdNdZdOdZdPdZdQdZdRdZdSd ZdTd!ZdUd"Z	 	 	 	 	 	 dVd#ZdVd$Z	 	 	 	 	 	 dVd%Z 	 	 	 	 	 	 dVd&Z!	 	 	 	 	 	 dVd'Z"	 	 	 	 	 	 dVd(Z#	 	 	 	 	 	 dVd)Z$	 	 	 	 	 	 dVd*Z%	 	 dW	 	 	 	 	 	 	 	 	 dXd+Z&	 	 	 	 	 	 dYd,Z'	 	 	 	 	 	 dYd-Z(	 	 	 	 	 	 dYd.Z)	 	 	 	 	 	 dYd/Z*dYd0Z+dZd1Z,dZd2Z-dZd3Z.dZd4Z/dZd5Z0dZd6Z1dZd7Z2dZd8Z3dZd9Z4dZd:Z5e5Z6e5Z7e5Z8e5Z9e5Z:e5Z;e5Z<e5Z=e5Z>	 	 	 	 	 	 	 	 d[d;Z?	 	 	 	 	 	 	 	 d[d<Z@	 	 	 	 	 	 	 	 d[d=ZA	 	 	 	 	 	 	 	 d[d>ZB	 	 	 	 	 	 	 	 d[d?ZC	 	 	 	 	 	 	 	 d[d@ZD	 	 	 	 	 	 	 	 d[dAZE	 	 	 	 	 	 	 	 d[dBZFyC)\r?   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)rZ   =z~=z|=z^=z$=z*=z!=idzxml:langFc                N     dj                   fdt        |      D              S )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   K   | ]  }j                  |d         yw)T)translate_pseudo_elementsN)selector_to_xpath).0selectorprefixr*   s     r"   	<genexpr>z1GenericTranslator.css_to_xpath.<locals>.<genexpr>   s+      
& ""8Vt"T&s   !)rJ   r   )r*   cssrj   s   ` `r"   css_to_xpathzGenericTranslator.css_to_xpath   s'    & zz 
!#J
 
 	
r!   c                   t        |dd      }|st        d|      | j                  |      }t        || j                        sJ |r(|j
                  r| j                  ||j
                        }|xs dt        |      z   S )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 rK   )getattr	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr2   )r*   ri   rj   rf   treerr   s         r"   rg   z#GenericTranslator.selector_to_xpath   s    4 x5>xlKLL

4 %!3!3444$)@)@--eX5L5LME"E
**r!   c                    t        d      )zTranslate 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*   rr   ru   s      r"   rv   z&GenericTranslator.xpath_pseudo_element  s     BCCr!   c                    t        |       } d| vrd|  d} | S d| vrd|  d} | S t        |       D cg c]  }|rd|v rd| dnd| d }}dj                  dj                  |            } | S c c}w )N'"z
concat({}),)r2   split_at_single_quotesformatrJ   )spartparts_quoteds      r"   r@   zGenericTranslator.xpath_literal  s    Fa<A3aA  \A3aA 	 3155D  #d{!D6!D6;5  
 ##CHH\$:;As   A.c           	         t        |      j                  }t        t        t        t
        gt        f      t        | d|j                          d            }|t        | d       ||      S )z%Translate any parsed selector object.xpath_Nz is not supported.)
typer   r   r   r   r   r$   rp   lowerr   )r*   parsed_selector	type_namemethods       r"   rr   zGenericTranslator.xpath   sp    )22	Xtfi/01DF9??#4"56=
 >!YK/A"BCCo&&r!   c           	        | j                   |j                     }t        t        t        t        gt        f   t        | d| d            } || j                  |j                        | j                  |j                              S )zTranslate a combined selector.r   _combinator)	combinator_mapping
combinatorr   r   r$   rp   rr   ri   subselector)r*   combinedr   r   s       r"   xpath_combinedselectorz(GenericTranslator.xpath_combinedselector-  st    ,,X-@-@A
i+Y67DF:,k:;
 djj!2!23TZZ@T@T5UVVr!   c                   | j                  |j                        }| j                  |j                        }|j                          |j                  r|j                  d|j                   d      S |j                  d      S )Nnot(r:   0)rr   ri   r   rA   r)   r<   )r*   negationrr   	sub_xpaths       r"   xpath_negationz GenericTranslator.xpath_negation6  sq    

8,,-JJx334	!&&i.A.A-B!'DEE""3''r!   c                \   | j                  |j                        }|j                  }|j                  }| j                  |j                        }t        t        t        t        gt        f   t        | d| j                  t        t        |j                            d            } |||      S )Nxpath_relation_r   )rr   ri   r   r   ro   r   r   r$   rp   r   r2   value)r*   relationrr   r   r   rightr   s          r"   xpath_relationz GenericTranslator.xpath_relation>  s    

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

;223i+Y67!$"9"9$sJDTDT:U"V!WWbc
 eU##r!   c                   | j                  |j                        }|j                  D cg c]  }| j                  |       }}|D ];  }|j                          |j                  s |j                  |j                  d       = |S c c}w Norrr   ri   selector_listrA   r)   r<   r*   matchingrr   ri   exprses         r"   xpath_matchingz GenericTranslator.xpath_matchingL  w    

8,,-6>6L6LM6L(H%6LMAOO{{##AKK6   N   Bc                   | j                  |j                        }|j                  D cg c]  }| j                  |       }}|D ];  }|j                          |j                  s |j                  |j                  d       = |S c c}w r   r   r   s         r"   xpath_specificityadjustmentz-GenericTranslator.xpath_specificityadjustmentU  r   r   c                <   dj                  |j                  j                  dd            }t        t        t
        t        t        gt        f      t        | |d            }|st        d|j                   d       || j                  |j                        |      S )z$Translate a functional pseudo-class.zxpath_{}_function-_NThe pseudo-class :z() is unknown)r~   namereplacer   r   r   r$   r   rp   r   rr   ri   )r*   functionmethod_namer   s       r"   xpath_functionz GenericTranslator.xpath_function^  s    )001F1FsC1PQXy(3Y>?@D+t,
 !$6x}}o]"STTdjj!2!23X>>r!   c                0   dj                  |j                  j                  dd            }t        t        t
        t        gt        f      t        | |d            }|st        d|j                   d       || j                  |j                              S )zTranslate a pseudo-class.zxpath_{}_pseudor   r   Nr   z is unknown)r~   identr   r   r   r   r$   rp   r   rr   ri   )r*   pseudor   r   s       r"   xpath_pseudozGenericTranslator.xpath_pseudoi  s    '..v||/C/CC/MNXyk9456kSW8X
 !$6v||nK"PQQdjj122r!   c                   | j                   |j                     }t        t        t        t
        t        t
           gt        f   t        | d|             }| j                  r|j                  j                         }n|j                  }t        |      }|j                  r*|j                   d| }|xr t        |j                        }|rd|z   }nd| j                  |       d}|j                  d}nU| j                  r3t        t
        |j                  j                        j                         }n|j                  j                  } || j!                  |j"                        ||      S )z Translate an attribute selector.xpath_attrib_:@zattribute::*[name() = r0   N)attribute_operator_mappingoperatorr   r   r$   r2   r   rp   lower_case_attribute_namesattribr   is_safe_name	namespacer@   r   lower_case_attribute_valuesrr   ri   )r*   ri   r   r   r   safer   r   s           r"   xpath_attribzGenericTranslator.xpath_attribt  s:   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3VUCCr!   c                r    | j                  |j                        }| j                  |d|j                        S )zTranslate a class selector.z@class)rr   ri   xpath_attrib_includes
class_name)r*   class_selectorrr   s      r"   xpath_classzGenericTranslator.xpath_class  s3     

>223))%>;T;TUUr!   c                r    | j                  |j                        }| j                  |d|j                        S )zTranslate an ID selector.z@id)rr   ri   xpath_attrib_equalsrc   )r*   id_selectorrr   s      r"   
xpath_hashzGenericTranslator.xpath_hash  s/    

;//0''uknnEEr!   c                R   |j                   }|sd}d}n0t        t        |            }| j                  r|j	                         }|j
                  r3|j
                   d| }|xr t        t        |j
                              }| j                  |      }|s|j                          |S )z'Translate a type or universal selector.r>   Tr   )r(   )r(   rL   r   lower_case_element_namesr   r   rt   rA   )r*   ri   r(   r   rr   s        r"   xpath_elementzGenericTranslator.xpath_element  s    ""GDW-.D,,!--/ "++,AgY7GBDh.@.@!ABD""7"3!r!   c                &    |j                  d|      S )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/rJ   r*   leftr   s      r"   xpath_descendant_combinatorz-GenericTranslator.xpath_descendant_combinator  s     yy2E::r!   c                &    |j                  d|      S )z#right is an immediate child of left/r   r   s      r"   xpath_child_combinatorz(GenericTranslator.xpath_child_combinator  s    yye$$r!   c                h    |j                  d|      }|j                          |j                  d      S )z)right is a sibling immediately after left/following-sibling::zposition() = 1)rJ   rA   r<   )r*   r   r   rr   s       r"    xpath_direct_adjacent_combinatorz2GenericTranslator.xpath_direct_adjacent_combinator  s3     		0%8""#344r!   c                &    |j                  d|      S )z1right is a sibling after left, immediately or notr   r   r   s      r"   "xpath_indirect_adjacent_combinatorz4GenericTranslator.xpath_indirect_adjacent_combinator  s     yy/77r!   c                ,    |j                  d|dd      S )zHright is a child, grand-child or further descendant of left; select leftz[descendant::r0   T)rH   rI   r   r   s      r"   $xpath_relation_descendant_combinatorz6GenericTranslator.xpath_relation_descendant_combinator  s#     yyUSd  
 	
r!   c                *    |j                  d|d      S )z0right is an immediate child of left; select leftz[./r0   rH   r   r   s      r"   xpath_relation_child_combinatorz1GenericTranslator.xpath_relation_child_combinator  s     yyy<<r!   c                @    |j                  d|j                   d      S )z6right is a sibling immediately after left; select leftz following-sibling::*[(name() = 'z') and (position() = 1)])r<   r(   r   s      r"   )xpath_relation_direct_adjacent_combinatorz;GenericTranslator.xpath_relation_direct_adjacent_combinator  s(     !!.u}}o=UV
 	
r!   c                *    |j                  d|d      S )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r0   r   r   r   s      r"   +xpath_relation_indirect_adjacent_combinatorz=GenericTranslator.xpath_relation_indirect_adjacent_combinator  s     yy/yMMr!   c                   	 t        |j                        \  }}|dz
  }|dk(  r|dk  r|S |dk  r|dk  r|j	                  d      S |rdn|j
                   }	|sd|	 d}
nd	|	 d}
|dk(  r|j	                  |
 d
|       S g }|dkD  r|dkD  r-|j                  |
 d|        n|j                  |
 d|        t        |      dk7  r6|
}| t        |      z  }|dk7  r	d| d| d}|j                  | d| d       t        |      dkD  rdnd|j	                  dj                  fd|D                     |S # t        $ r}t        d|j                  d      |d }~ww xY w)NzInvalid series: 'rz      r   r   r>   count(preceding-sibling::r:   count(following-sibling:: = z >= z <= r9   z +z mod z = 0z(%s)z%sz and c              3  (   K   | ]	  }|z    y wr&   r    )rh   
expressiontemplates     r"   rk   z=GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>f  s     M:J.s   )
r   	arguments
ValueErrorr   r<   r(   appendabslenrJ   )r*   rr   r   lastrA   abexb_min_1nodetestsiblings_countexpressionsr   b_negr   s                 @r"   xpath_nth_child_functionz*GenericTranslator.xpath_nth_child_function  s   	W 2 23DAqZ 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   D< <	E$EE$c                *    | j                  ||d      S )NT)r   )r   r*   rr   r   s      r"   xpath_nth_last_child_functionz/GenericTranslator.xpath_nth_last_child_functionj  s     ,,UH4,HHr!   c                ^    |j                   dk(  rt        d      | j                  ||d      S )Nr>   "*:nth-of-type() is not implementedF)rA   r(   r   r   r   s      r"   xpath_nth_of_type_functionz,GenericTranslator.xpath_nth_of_type_functiono  s4     ==C!"FGG,,UHE,RRr!   c                `    |j                   dk(  rt        d      | j                  ||dd      S )Nr>   r  TF)r   rA   r  r   s      r"   xpath_nth_last_of_type_functionz1GenericTranslator.xpath_nth_last_of_type_functionv  s=     ==C!"FGG,,8$e - 
 	
r!   c                    |j                         dgdgfvrt        d|j                        t        t        |j                  d   j
                        }|j                  d| j                  |       d      S )NSTRINGIDENTz7Expected a single string or ident for :contains(), got r   zcontains(., r:   argument_typesr   r   r   r2   r   r<   r@   r*   rr   r   r   s       r"   xpath_contains_functionz)GenericTranslator.xpath_contains_function  s    
 ""$hZ',CC!I(J\J\I_`  S(,,Q/556""\$2D2DU2K1LA#NOOr!   c                    |j                         dgdgfvrt        d|j                        t        t        |j                  d   j
                        }|j                  d| j                  |       d      S )Nr  r  3Expected a single string or ident for :lang(), got r   zlang(r:   r	  r  s       r"   xpath_lang_functionz%GenericTranslator.xpath_lang_function  s    ""$hZ',CC!EhFXFXE[\  S(,,Q/556""U4+=+=e+D*EQ#GHHr!   c                $    |j                  d      S )Nznot(parent::*)r<   r*   rr   s     r"   xpath_root_pseudoz#GenericTranslator.xpath_root_pseudo  s    ""#344r!   c                $    |j                  d      S )N1r  r  s     r"   xpath_scope_pseudoz$GenericTranslator.xpath_scope_pseudo  s    ""3''r!   c                $    |j                  d      S )Nzcount(preceding-sibling::*) = 0r  r  s     r"   xpath_first_child_pseudoz*GenericTranslator.xpath_first_child_pseudo      ""#DEEr!   c                $    |j                  d      S )Nzcount(following-sibling::*) = 0r  r  s     r"   xpath_last_child_pseudoz)GenericTranslator.xpath_last_child_pseudo  r  r!   c                t    |j                   dk(  rt        d      |j                  d|j                    d      S )Nr>   z"*:first-of-type is not implementedr   ) = 0r(   r   r<   r  s     r"   xpath_first_of_type_pseudoz,GenericTranslator.xpath_first_of_type_pseudo  s9    ==C!"FGG""%>u}}oU#STTr!   c                t    |j                   dk(  rt        d      |j                  d|j                    d      S )Nr>   z!*:last-of-type is not implementedr   r  r  r  s     r"   xpath_last_of_type_pseudoz+GenericTranslator.xpath_last_of_type_pseudo  s9    ==C!"EFF""%>u}}oU#STTr!   c                $    |j                  d      S )Nzcount(parent::*/child::*) = 1r  r  s     r"   xpath_only_child_pseudoz)GenericTranslator.xpath_only_child_pseudo  s    ""#BCCr!   c                t    |j                   dk(  rt        d      |j                  d|j                    d      S )Nr>   z!*:only-of-type is not implementedzcount(parent::*/child::z) = 1r  r  s     r"   xpath_only_of_type_pseudoz+GenericTranslator.xpath_only_of_type_pseudo  s9    ==C!"EFF""%<U]]O5#QRRr!   c                $    |j                  d      S )Nznot(*) and not(string-length())r  r  s     r"   xpath_empty_pseudoz$GenericTranslator.xpath_empty_pseudo  r  r!   c                $    |j                  d      S )z:Common implementation for pseudo-classes that never match.r   r  r  s     r"   pseudo_never_matchesz&GenericTranslator.pseudo_never_matches  s    ""3''r!   c                0    |rJ |j                  |       |S r&   r  r*   rr   r   r   s       r"   xpath_attrib_existsz%GenericTranslator.xpath_attrib_exists  s     yD!r!   c                X    |J |j                  | d| j                  |              |S )Nr   r<   r@   r+  s       r"   r   z%GenericTranslator.xpath_attrib_equals  s:        tfC(:(:5(A'BCDr!   c           
         |J |r+|j                  d| d| d| j                  |              |S |j                  | d| j                  |              |S )Nr   z) or z != r.  r+  s       r"   xpath_attrib_differentz(GenericTranslator.xpath_attrib_different  ss        $tfE$tD<N<Nu<U;V WX  4&T-?-?-F,G HIr!   c                    |r>t        |      r3| j                  d|z   dz         }|j                  | d| d| d       |S |j                  d       |S )NrV   z* and contains(concat(' ', normalize-space(z	), ' '), r:   r   )is_non_whitespacer@   r<   )r*   rr   r   r   args        r"   r   z'GenericTranslator.xpath_attrib_includes  sl     &u-$$S5[3%67C&B4&	RUQVVWX
  $r!   c                    |J | j                  |      }| j                  |dz         }|j                  | d| d| d| d| d
       |S )Nr   z and (r   z or starts-with(, z)))r@   r<   )r*   rr   r   r   r3  arg_dashs         r"   xpath_attrib_dashmatchz(GenericTranslator.xpath_attrib_dashmatch  sl          '%%eck2fF4&C5(8b
"M	
 r!   c           	         |r+|j                  | d| d| j                  |       d       |S |j                  d       |S )Nz and starts-with(r5  r:   r   r.  r+  s       r"   xpath_attrib_prefixmatchz*GenericTranslator.xpath_attrib_prefixmatch  sT     &)$r$2D2DU2K1LAN
  $r!   c                    |r<|j                  | d| d| dt        |      dz
   d| j                  |       	       |S |j                  d       |S )Nz and substring(z, string-length(z)-r   z) = r   )r<   r   r@   r+  s       r"   xpath_attrib_suffixmatchz*GenericTranslator.xpath_attrib_suffixmatch  sk     &v-=dV2c%jSTnEUUYZ^ZlZlmrZsYtu
  $r!   c           	         |r+|j                  | d| d| j                  |       d       |S |j                  d       |S )Nz and contains(r5  r:   r   r.  r+  s       r"   xpath_attrib_substringmatchz-GenericTranslator.xpath_attrib_substringmatch  sS     &tfBt/A/A%/H.IK
  $r!   N)descendant-or-self::)rl   r2   rj   r2   rM   r2   )r>  F)ri   r   rj   r2   rf   rL   rM   r2   )rr   r$   ru   r   rM   r$   )r   r2   rM   r2   )r   r   rM   r$   )r   r
   rM   r$   )r   r   rM   r$   )r   r   rM   r$   )r   r   rM   r$   )r   r   rM   r$   )r   r   rM   r$   )r   r   rM   r$   )ri   r   rM   r$   )r   r	   rM   r$   )r   r   rM   r$   )ri   r   rM   r$   )r   r$   r   r$   rM   r$   )FT)
rr   r$   r   r   r   rL   rA   rL   rM   r$   rr   r$   r   r   rM   r$   rr   r$   rM   r$   )rr   r$   r   r2   r   rP   rM   r$   )Gr   r   r   r   r   r   id_attributelang_attributer   r   r   r$   rt   rm   rg   rv   staticmethodr@   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  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   r0  r   r7  r9  r;  r=  r    r!   r"   r?   r?      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!   r?   c                  F    e Zd ZdZdZd
ddZddZddZddZddZ	ddZ
y	)HTMLTranslatora  
    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                4    || _         |sd| _        d| _        y y )NT)xhtmlr   r   )r*   rQ  s     r"   r,   zHTMLTranslator.__init__3  s!    
,0D).2D+ r!   c                $    |j                  d      S )Nz(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio'))r  r  s     r"   rL  z#HTMLTranslator.xpath_checked_pseudo:  s    "";
 	
r!   c                    |j                         dgdgfvrt        d|j                        |j                  d   j                  }|sJ | j	                  |j                         dz         }|j                  d| j                   d| d      S )	Nr  r  r  r   r   z<ancestor-or-self::*[@lang][1][starts-with(concat(translate(@zE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), z)])r
  r   r   r   r@   r   r<   rB  )r*   rr   r   r   r3  s        r"   r  z"HTMLTranslator.xpath_lang_functionC  s    ""$hZ',CC!EhFXFXE[\  ""1%++u  !45""--. /E	
 	
r!   c                $    |j                  d      S )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')r  r  s     r"   rD  z HTMLTranslator.xpath_link_pseudoS  s    ""O
 	
r!   c                $    |j                  d      S )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"   rK  z$HTMLTranslator.xpath_disabled_pseudo[  s    ""
 	
r!   c                $    |j                  d      S )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"   rJ  z#HTMLTranslator.xpath_enabled_pseudoy  s    ""
 	
r!   N)F)rQ  rL   rM   rN   r@  r?  )r   r   r   r   rB  r,   rL  r  rD  rK  rJ  r    r!   r"   rN  rN     s,      N3

 

< 
r!   rN  ))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   r2  r?   rN  r    r!   r"   <module>ra     s    # 	 $ 0 0    ( &>m\ >A AH $F+11 
 rzz67== BJJ1288 W
 W
ty
& y
r!   