
    EZc                        d Z ddlZddlZddlZddl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j.                  dd       Z G d de
e      Z G d d	      Z ej8                  d
      j:                  Z ej8                  d      j>                  Z  ej8                  d      j>                  Z! G d d      Z" G d de"      Z#y)a  
    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.

    N)Optional)parseparse_seriesPseudoElementSelectorSelectorErrorTreeElementHashClassFunctionPseudoAttribNegationRelationMatchingSpecificityAdjustmentCombinedSelectorc                 T    t        j                  dt        d       t        | ||      S )Nzb_unicode_safe_getattr is deprecated and will be removed in the next release, use getattr() instead   )
stacklevel)warningswarnDeprecationWarninggetattr)objnamedefaults      1/usr/lib/python3/dist-packages/cssselect/xpath.py_unicode_safe_getattrr    )   s*    MM	/	 3g&&    c                       e Zd ZdZy)ExpressionErrorz3Unknown or unsupported selector (eg. pseudo-class).N)__name__
__module____qualname____doc__ r!   r   r#   r#   4   s    =r!   r#   c                       e Zd Z	 ddededededdf
dZdefdZdefd	Zdded
edd fdZddZ	ddZ
	 	 ddedd dee   dedd f
dZy)	XPathExprpathelement	conditionstar_prefixreturnNc                 .    || _         || _        || _        y N)r+   r,   r-   )selfr+   r,   r-   r.   s        r   __init__zXPathExpr.__init__<   s     	"r!   c                     t        | j                        t        | j                        z   }| j                  r|d| j                  z  z  }|S )Nz[%s]strr+   r,   r-   )r2   r+   s     r   __str__zXPathExpr.__str__C   s<    499~DLL 11>>FT^^++Dr!   c                 :    | j                   j                  d| dS )N[])	__class__r$   r2   s    r   __repr__zXPathExpr.__repr__I   s    >>22D99r!   
conjuctionc                 f    | j                   rd| j                   d|d|d| _         | S || _         | S )N(z) z ())r-   )r2   r-   r>   s      r   add_conditionzXPathExpr.add_conditionL   s0    >>/3~~z9UDN  'DNr!   c                     | j                   dk(  ry | j                  dt        j                  | j                         z         d| _         y )N*zname() = %s)r,   rB   GenericTranslatorxpath_literalr<   s    r   add_name_testzXPathExpr.add_name_testS   s;    <<3=+<+J+J4<<+XXYr!   c                 .    | xj                   dz  c_         y)ze
        Append '*/' to the path to keep the context constrained
        to a single parent.
        */N)r+   r<   s    r   add_star_prefixzXPathExpr.add_star_prefixZ   s    
 			T	r!   combinerotherclosing_combinerhas_inner_conditionc                    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 )NrI   r9   r:   r5   )r2   rK   rL   rM   rN   r+   s         r   joinzXPathExpr.joina   s     4y8#::EJJD	"?O5==+;;UZUbUbDL"__DN  !==DLeoo 5 ;; 00r!   ) rD   rQ   F)and)r/   N)NF)r$   r%   r&   r6   boolr3   r7   r=   rB   rG   rJ   r   rP   r(   r!   r   r*   r*   ;   s    [`##'*#=@#TX#	# :# :s    +/$)  #3-	
 " 
r!   r*   z('+)z^[a-zA-Z_][a-zA-Z0-9_.-]*$z^[^ \t\r\n\f]+$c                   F   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d[dededefdZ	 	 d\dedededefdZdededefdZededefd       Zdedefd Zd!edefd"Zd#edefd$Zd%edefd&Zd'edefd(Zd'e defd)Z!d*e"defd+Z#d,e$defd-Z%de&defd.Z'd/e(defd0Z)d1e*defd2Z+de,defd3Z-d4ed5edefd6Z.d4ed5edefd7Z/d4ed5edefd8Z0d4ed5edefd9Z1d4ed5edefd:Z2d4ed5edefd;Z3d4ed5edefd<Z4d4ed5edefd=Z5	 d]ded*e"d>ed?edef
d@Z6ded*e"defdAZ7ded*e"defdBZ8ded*e"defdCZ9ded*e"defdDZ:ded*e"defdEZ;dedefdFZ<dedefdGZ=dedefdHZ>dedefdIZ?dedefdJZ@dedefdKZAdedefdLZBdedefdMZCdedefdNZDdedefdOZEeEZFeEZGeEZHeEZIeEZJeEZKeEZLeEZMeEZNdedPedQeOe   defdRZPdedPedQeOe   defdSZQdedPedQeOe   defdTZRdedPedQeOe   defdUZSdedPedQeOe   defdVZTdedPedQeOe   defdWZUdedPedQeOe   defdXZVdedPedQeOe   defdYZWyZ)^rE   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)r]   =z~=z|=z^=z$=z*=z!=idzxml:langFcssprefixr/   c                 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selectorrh   r2   s     r   	<genexpr>z1GenericTranslator.css_to_xpath.<locals>.<genexpr>   s+      
 ""8Vt"T
s   !)rP   r   )r2   rg   rh   s   ` `r   css_to_xpathzGenericTranslator.css_to_xpath   s'    & zz 
!#J
 
 	
r!   rn   rk   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 rQ   )r   	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr6   )r2   rn   rh   rk   treert   s         r   rl   z#GenericTranslator.selector_to_xpath   s}    4 x5HNOO

4 %!3!3444$)@)@--eX5L5LME"E
**r!   rt   rw   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#   )r2   rt   rw   s      r   rx   z&GenericTranslator.xpath_pseudo_element  s     BCCr!   sc                     t        |       } d| vrd| z  } | S d| vrd| z  } | S ddj                  t        |       D cg c]  }|rd|v xr dxs d|z   c}      z  } | S c c}w )N'z'%s'"z"%s"z
concat(%s),)r6   rP   split_at_single_quotes)r{   parts     r   rF   zGenericTranslator.xpath_literal  s    Fa<
A  \
A  sxx !7q 9 Tk-v74?  A s   A
parsed_selectorc                     t        |      j                  }t        | d|j                         z  d      }|t	        d|z        t        j                  t         ||            S )z%Translate any parsed selector object.zxpath_%sNz%s is not supported.)typer$   r   lowerr#   typingcastr*   )r2   r   	type_namemethods       r   rt   zGenericTranslator.xpath   sX    )22	zIOO,==tD>!"89"DEE{{9f_&=>>r!   combinedc           	          | j                   |j                     }t        | d|z        }t        j                  t
         || j                  |j                        | j                  |j                                    S )zTranslate a combined selector.zxpath_%s_combinator)	combinator_mapping
combinatorr   r   r   r*   rt   rn   subselector)r2   r   r   r   s       r   xpath_combinedselectorz(GenericTranslator.xpath_combinedselector*  se    ,,X-@-@A
4zAB{{vdjj):):;TZZH\H\=]^
 	
r!   negationc                    | j                  |j                        }| j                  |j                        }|j                          |j                  r|j                  d|j                  z        S |j                  d      S )Nznot(%s)0)rt   rn   r   rG   r-   rB   )r2   r   rt   	sub_xpaths       r   xpath_negationz GenericTranslator.xpath_negation2  sl    

8,,-JJx334	!&&y93F3F'FGG&&s++r!   relationc           	      \   | j                  |j                        }|j                  }|j                  }| j                  |j                        }t        | d| j                  t        j                  t        |j                           z        }t        j                  t         |||            S )Nzxpath_relation_%s_combinator)rt   rn   r   r   rr   r   r   r   r   r6   valuer*   )r2   r   rt   r   r   rightr   s          r   xpath_relationz GenericTranslator.xpath_relation;  s    

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

;223*%%fkk#z7G7G&HIJ

 {{9fUE&:;;r!   matchingc                    | j                  |j                        }|j                  D cg c]  }| j                  |       }}|D ];  }|j                          |j                  s |j                  |j                  d       = |S c c}w Norrt   rn   selector_listrG   r-   rB   r2   r   rt   rn   exprses         r   xpath_matchingz GenericTranslator.xpath_matchingG  y    

8,,-6>6L6LM(H%MM 	7AOO{{##AKK6	7  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_specificityadjustmentP  r   r   functionc                    d|j                   j                  dd      z  }t        | |d      }|st        d|j                   z        t	        j
                  t         || j                  |j                        |            S )z$Translate a functional pseudo-class.zxpath_%s_function-_Nz!The pseudo-class :%s() is unknown)	r   replacer   r#   r   r   r*   rt   rn   )r2   r   method_namer   s       r   xpath_functionz GenericTranslator.xpath_functionY  sj    )HMM,A,A#s,KK{D1!"E"UVV{{9fTZZ8I8I-JH&UVVr!   pseudoc                     d|j                   j                  dd      z  }t        | |d      }|st        d|j                   z        t	        j
                  t         || j                  |j                                    S )zTranslate a pseudo-class.zxpath_%s_pseudor   r   NzThe pseudo-class :%s is unknown)	identr   r   r#   r   r   r*   rt   rn   )r2   r   r   r   s       r   xpath_pseudozGenericTranslator.xpath_pseudoa  sf    '&,,*>*>sC*HH{D1!"Cfll"RSS{{9fTZZ-H&IJJr!   c                    | j                   |j                     }t        | d|z        }| j                  r|j                  j                         }n|j                  }t        |      }|j                  r*|j                  d|}|xr t        |j                        }|rd|z   }nd| j                  |      z  }|j                  d}n_| j                  r=t        j                  t        |j                  j                        j                         }n|j                  j                  }t        j                  t         || j                  |j                         ||            S )z Translate an attribute selector.zxpath_attrib_%s:@zattribute::*[name() = %s]N)attribute_operator_mappingoperatorr   lower_case_attribute_namesattribr   is_safe_name	namespacerF   r   lower_case_attribute_valuesr   r   r6   r*   rt   rn   )r2   rn   r   r   r   safer   r   s           r   xpath_attribzGenericTranslator.xpath_attribj  s   2283D3DE08;<**??((*D??DD!&00$7D<L););<D4ZF043E3Ed3KKF>>!E--KKX^^%9%9:@@BENN((E{{9fTZZ8I8I-JFTY&Z[[r!   class_selectorc                 r    | j                  |j                        }| j                  |d|j                        S )zTranslate a class selector.z@class)rt   rn   xpath_attrib_includes
class_name)r2   r   rt   s      r   xpath_classzGenericTranslator.xpath_class  s3     

>223))%>;T;TUUr!   id_selectorc                 r    | j                  |j                        }| j                  |d|j                        S )zTranslate an ID selector.z@id)rt   rn   xpath_attrib_equalsrf   )r2   r   rt   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.rD   Tr   )r,   )r,   rS   r   lower_case_element_namesr   r   rv   rG   )r2   rn   r,   r   rt   s        r   xpath_elementzGenericTranslator.xpath_element  s    ""GDW-.D,,!--/ "*!3!3W=GBDh.@.@!ABD""7"3!r!   leftr   c                 &    |j                  d|      S )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/rP   r2   r   r   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)rP   rG   rB   r2   r   r   rt   s       r    xpath_direct_adjacent_combinatorz2GenericTranslator.xpath_direct_adjacent_combinator  s1    		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::r:   T)rM   rN   r   r   s      r   $xpath_relation_descendant_combinatorz6GenericTranslator.xpath_relation_descendant_combinator  s    yy%#[_y``r!   c                 *    |j                  d|d      S )z0right is an immediate child of left; select leftz[./r:   rM   r   r   s      r   xpath_relation_child_combinatorz1GenericTranslator.xpath_relation_child_combinator  s    yyy<<r!   c                 Z    |j                  dj                  |j                              }|S )z6right is a sibling immediately after left; select leftz:following-sibling::*[(name() = '{}') and (position() = 1)])rB   formatr,   r   s       r   )xpath_relation_direct_adjacent_combinatorz;GenericTranslator.xpath_relation_direct_adjacent_combinator  s0     ""HOOPUP]P]^
 r!   c                 *    |j                  d|d      S )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r:   r   r   r   s      r   +xpath_relation_indirect_adjacent_combinatorz=GenericTranslator.xpath_relation_indirect_adjacent_combinator  s     yy/yMMr!   lastrG   c                    	 t        |j                        \  }}|dz
  }|dk(  r|dk  r|S |dk  r|dk  r|j	                  d      S |rd}nd|j
                  z  }|sd|z  }	nd|z  }	|dk(  r|j	                  |	d	|      S g }
|dkD  r|dkD  r-|
j                  |	d
|       n|
j                  |	d|       t        |      dk7  r;|	}| t        |      z  }|dk7  rd|z  }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                  z        w xY w)NzInvalid series: '%r'   r   r   rD   z%szcount(preceding-sibling::%s)zcount(following-sibling::%s) = z >= z <= z+%sr@   rY   rA   z mod z = 0z(%s)z and c              3   (   K   | ]	  }|z    y wr1   r(   )rm   
expressiontemplates     r   ro   z=GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>P  s     (]:J)>(]s   )
r   	arguments
ValueErrorr#   rB   r,   appendabslenrP   )r2   rt   r   r   rG   abb_min_1nodetestsiblings_countexpressionsr   b_negb_neg_as_strr   s                 @r   xpath_nth_child_functionz*GenericTranslator.xpath_nth_child_function  s   	O 2 23DAqZ a% 6glL
 q5Wq[&&s++
 Hemm+H ;hFN;hFN 6&&NG'LMMq5 {""#IJ
 ^WEF q6Q;!D
 XQ'Ez$u}$(,7$:;{aHHGLL(]Q\(]]^}  	O!"88;M;M"MNN	Os   E "E%c                 *    | j                  ||d      S )NT)r   )r   r2   rt   r   s      r   xpath_nth_last_child_functionz/GenericTranslator.xpath_nth_last_child_functionS  s    ,,UH4,HHr!   c                 ^    |j                   dk(  rt        d      | j                  ||d      S )NrD   "*:nth-of-type() is not implementedF)rG   r,   r#   r   r   s      r   xpath_nth_of_type_functionz,GenericTranslator.xpath_nth_of_type_functionV  s2    ==C!"FGG,,UHE,RRr!   c                 `    |j                   dk(  rt        d      | j                  ||dd      S )NrD   r   TF)r   rG   r   r   s      r   xpath_nth_last_of_type_functionz1GenericTranslator.xpath_nth_last_of_type_function[  s5    ==C!"FGG,,UH4W\,]]r!   c                    |j                         dgdgfvrt        d|j                  z        t        j                  t
        |j                  d   j                        }|j                  d| j                  |      z        S )NSTRINGIDENTz9Expected a single string or ident for :contains(), got %rr   zcontains(., %s)	argument_typesr#   r   r   r   r6   r   rB   rF   r2   rt   r   r   s       r   xpath_contains_functionz)GenericTranslator.xpath_contains_function`  s~     ""$hZ',CC!KhN`N``  C!3!3A!6!<!<=""#4t7I7I%7P#PQQr!   c                    |j                         dgdgfvrt        d|j                  z        t        j                  t
        |j                  d   j                        }|j                  d| j                  |      z        S )Nr  r  5Expected a single string or ident for :lang(), got %rr   zlang(%s)r  r  s       r   xpath_lang_functionz%GenericTranslator.xpath_lang_functionj  s{    ""$hZ',CC!G(J\J\\  C!3!3A!6!<!<="":1C1CE1J#KLLr!   c                 $    |j                  d      S )Nznot(parent::*)rB   r2   rt   s     r   xpath_root_pseudoz#GenericTranslator.xpath_root_pseudot  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                 r    |j                   dk(  rt        d      |j                  d|j                   z        S )NrD   z"*:first-of-type is not implementedz count(preceding-sibling::%s) = 0r,   r#   rB   r  s     r   xpath_first_of_type_pseudoz,GenericTranslator.xpath_first_of_type_pseudo  s5    ==C!"FGG""#E#UVVr!   c                 r    |j                   dk(  rt        d      |j                  d|j                   z        S )NrD   z!*:last-of-type is not implementedz count(following-sibling::%s) = 0r  r  s     r   xpath_last_of_type_pseudoz+GenericTranslator.xpath_last_of_type_pseudo  s5    ==C!"EFF""#E#UVVr!   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                 r    |j                   dk(  rt        d      |j                  d|j                   z        S )NrD   z!*:only-of-type is not implementedzcount(parent::*/child::%s) = 1r  r  s     r   xpath_only_of_type_pseudoz+GenericTranslator.xpath_only_of_type_pseudo  s5    ==C!"EFF""#Cemm#STTr!   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!   r   r   c                 0    |rJ |j                  |       |S r1   r  r2   rt   r   r   s       r   xpath_attrib_existsz%GenericTranslator.xpath_attrib_exists  s    yD!r!   c                 X    |J |j                  |d| j                  |             |S )Nr   rB   rF   r%  s       r   r   z%GenericTranslator.xpath_attrib_equals  s1       t/A/A%/HIJr!   c           
          |J |r+|j                  d|d|d| j                  |             |S |j                  |d| j                  |             |S )Nznot(z) or z != r(  r%  s       r   xpath_attrib_differentz(GenericTranslator.xpath_attrib_different  s`        tTEWEWX]E^ _`  dD4F4Fu4M NOr!   c           
          |r<t        |      r1|j                  |d|d| j                  d|z   dz         d       |S |j                  d       |S )Nz* and contains(concat(' ', normalize-space(z	), ' '), rY   rA   r   )is_non_whitespacerB   rF   r%  s       r   r   z'GenericTranslator.xpath_attrib_includes  sZ     &u-t11#+2CDF  $r!   c                     |J |j                  |d|d| j                  |      d|d| j                  |dz         d
       |S )Nz and (r   z or starts-with(, r   z))r(  r%  s       r   xpath_attrib_dashmatchz(GenericTranslator.xpath_attrib_dashmatch  sQ        T4--e4dD<N<NuWZ{<[]	
 r!   c           	          |r+|j                  |d|d| j                  |      d       |S |j                  d       |S )Nz and starts-with(r.  rA   r   r(  r%  s       r   xpath_attrib_prefixmatchz*GenericTranslator.xpath_attrib_prefixmatch  sF     04dD<N<Nu<UV
  $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   )rB   r   rF   r%  s       r   xpath_attrib_suffixmatchz*GenericTranslator.xpath_attrib_suffixmatch  sU     tSZ!^T5G5G5NP  $r!   c           	          |r+|j                  |d|d| j                  |      d       |S |j                  d       |S )Nz and contains(r.  rA   r   r(  r%  s       r   xpath_attrib_substringmatchz-GenericTranslator.xpath_attrib_substringmatch  sF     -149K9KE9RS
  $r!   N)descendant-or-self::)r6  F)FT)Xr$   r%   r&   r'   r   r   id_attributelang_attributer   r   r   r*   rv   r6   rp   r   rS   rl   r   rx   staticmethodrF   r	   rt   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  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&  r   r*  r   r/  r1  r3  r5  r(   r!   r   rE   rE      s   *  	 	" L  N   %!&"' M
 
S 
c 
6 -*/	!+!+ !+ $(	!+
 
!+FD) D] DW` D     ?T ?i ?
/? 
I 
,x ,I ,
<x 
<I 
<x I 4I i Wx WI WK6 Ki K\V \	 \0V% VI VFd Fy F
g ) ,;	 ;) ;PY ;%9 %Y %9 %5Y 5y 5U^ 58y 8 8W` 8a a9 aYb a=I =i =T] =&/	NN&/N	N _cCC*2C:>CW[C	CJI9 I IU^ IS	 SX SR[ S
^Y ^( ^W` ^
RY R( Ry RM Mh M9 M5y 5Y 5(	 (i (Fi FI FFY F9 FW	 Wi W
Wy WY W
DY D9 DUy UY U
F	 Fi F() (	 ( -/-.-./0/ # hsm Xa 
 # hsm Xa 
		&)	2:3-			

&)
2:3-
	
		&)	2:3-					&)	2:3-			&)2:3-	

&)
2:3-
	
r!   rE   c                   z    e Zd ZdZdZddeddfdZdedefdZded	e	defd
Z
dedefdZdedefdZdedef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.

    langxhtmlr/   Nc                 4    || _         |sd| _        d| _        y y )NT)rF  r   r   )r2   rF  s     r   r3   zHTMLTranslator.__init__  s!    
,0D).2D+ r!   rt   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   rB  z#HTMLTranslator.xpath_checked_pseudo  s    "";
 	
r!   r   c           	         |j                         dgdgfvrt        d|j                  z        |j                  d   j                  }|sJ |j	                  d| j
                  d| j                  |j                         dz         d      S )	Nr  r  r	  r   z<ancestor-or-self::*[@lang][1][starts-with(concat(translate(@zE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), r   z)])r  r#   r   r   rB   r8  rF   r   r  s       r   r
  z"HTMLTranslator.xpath_lang_function  s    ""$hZ',CC!G(J\J\\  ""1%++u""
 !//1C1CEKKMTWDW1X	Z
 	
r!   c                 $    |j                  d      S )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')r  r  s     r   r:  z HTMLTranslator.xpath_link_pseudo-  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   rA  z$HTMLTranslator.xpath_disabled_pseudo5  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   r@  z#HTMLTranslator.xpath_enabled_pseudoS  s    ""
 	
r!   )F)r$   r%   r&   r'   r8  rS   r3   r*   rB  r   r
  r:  rA  r@  r(   r!   r   rD  rD    s      N3d 3t 3
) 
	 

 
h 
9 

y 
Y 

9 
 
< 
)  
	  
r!   rD  r1   )$r'   rer   r   r   cssselect.parserr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   no_type_checkr    RuntimeErrorr#   r*   compilesplitr   matchr   r,  rE   rD  r(   r!   r   <module>rT     s    
       * ' '>m\ >; ;| $F+11 
 rzz67== BJJ1288 q	 q	hx
& x
r!   