
    !}g                        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j        d
          j        Z ej        d          j        Z  ej        d          j        Z! G d d          Z" G d de"          Z#dS )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          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      O/var/www/py-google-trends/myenv/lib/python3.11/site-packages/cssselect/xpath.py_unicode_safe_getattrr    )   s:    M	/	    3g&&&    c                       e Zd ZdZdS )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d	S )	XPathExpr *Fpathelement	conditionstar_prefixreturnNc                 0    || _         || _        || _        d S N)r-   r.   r/   )selfr-   r.   r/   r0   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/   )r4   r-   s     r   __str__zXPathExpr.__str__C   s>    49~~DL 1 11> 	,FT^++Dr!   c                 &    | j         j        d| dS )N[])	__class__r$   r4   s    r   __repr__zXPathExpr.__repr__I   s    >222DDD99r!   and
conjuctionc                 P    | j         rd| j         d|d|d| _         n|| _         | S )N(z) z ())r/   )r4   r/   rA   s      r   add_conditionzXPathExpr.add_conditionL   s;    > 	' 	'/3~~~zzz999UDNN&DNr!   c                     | j         dk    rd S |                     dt                              | j                   z             d| _         d S )Nr,   zname() = %s)r.   rE   GenericTranslatorxpath_literalr>   s    r   add_name_testzXPathExpr.add_name_testS   sI    <3F=+<+J+J4<+X+XXYYYr!   c                 &    | xj         dz  c_         dS )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                 0   t          |           |z   }|j        dk    r
||j        z  }|| _        |s%|r
|j        |z   n|j        | _        |j        | _        n@|j        | _        |j        r| xj        d|j        z   dz   z  c_        |r| xj        |z  c_        | S )NrK   r;   r<   r7   )r4   rM   rN   rO   rP   r-   s         r   joinzXPathExpr.joina   s     4yy8#:EJD	" 	1?Ob5=+;;;UZUbDL"_DNN =DL <eo 5 ;; 1 00r!   )r+   r,   r+   F)r@   )r1   N)NF)r$   r%   r&   r8   boolr5   r9   r?   rE   rI   rL   r   rR   r(   r!   r   r*   r*   ;   s9       [`# ##'*#=@#TX#	# # # #    :# : : : : s             +/$)   #3-	
 " 
     r!   r*   z('+)z^[a-zA-Z_][a-zA-Z0-9_.-]*$z^[^ \t\r\n\f]+$c                   ~   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'd0e(defd1Z)d2e*defd3Z+de,defd4Z-d5ed6edefd7Z.d5ed6edefd8Z/d5ed6edefd9Z0d5ed6edefd:Z1d5ed6edefd;Z2d5ed6edefd<Z3d5ed6edefd=Z4d5ed6edefd>Z5	 d_ded+e"d@edAedef
dBZ6ded+e"defdCZ7ded+e"defdDZ8ded+e"defdEZ9ded+e"defdFZ:de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Z?dedefdLZ@dedefdMZAdedefdNZBdedefdOZCdedefdPZDdedefdQZEeEZFeEZGeEZHeEZIeEZJeEZKeEZLeEZMeEZNdedRedSeOe         defdTZPdedRedSeOe         defdUZQdedRedSeOe         defdVZRdedRedSeOe         defdWZSdedRedSeOe         defdXZTdedRedSeOe         defdYZUdedRedSeOe         defdZZVdedRedSeOe         defd[ZWd\S )`rG   z
    Translator for "generic" XML documents.

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

    
descendantchilddirect_adjacentindirect_adjacent) >+~existsequalsincludes	dashmatchprefixmatchsuffixmatchsubstringmatch	different)r]   =z~=z|=z^=z$=z*=z!=idzxml:langFdescendant-or-self::cssprefixr1   c                 d     d                      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   H   K   | ]}                     |d           V  dS )T)translate_pseudo_elementsN)selector_to_xpath).0selectorri   r4   s     r   	<genexpr>z1GenericTranslator.css_to_xpath.<locals>.<genexpr>   sL       
 
 ""8Vt"TT
 
 
 
 
 
r!   )rR   r   )r4   rh   ri   s   ` `r   css_to_xpathzGenericTranslator.css_to_xpath   sM    & zz 
 
 
 
 
!#JJ
 
 
 
 
 	
r!   ro   rl   c                    t          |dd          }|st          d|          |                     |          }t          || j                  sJ |r"|j        r|                     ||j                  }|p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 r+   )r   	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr8   )r4   ro   ri   rl   treeru   s         r   rm   z#GenericTranslator.selector_to_xpath   s    4 x55 	P)HHNOOO

4  %!344444$ 	N)@ 	N--eX5LMME"E

**r!   ru   rx   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#   )r4   ru   rx   s      r   ry   z&GenericTranslator.xpath_pseudo_element  s     BCCCr!   sc                     t          |           } d| vrd| z  } n9d| vrd| z  } n/dd                    d t          |           D                       z  } | S )N''%s'""%s"z
concat(%s),c                 (    g | ]}|d |v rdpd|z  S )r~   r   r   r(   )rn   parts     r   
<listcomp>z3GenericTranslator.xpath_literal.<locals>.<listcomp>  sA       Tk-v74?  r!   )r8   rR   split_at_single_quotes)r|   s    r   rH   zGenericTranslator.xpath_literal  sz    FFa<<
AA\\
AAsxx  6q 9 9      A r!   parsed_selectorc                     t          |          j        }t          | d|                                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*   )r4   r   	type_namemethods       r   ru   zGenericTranslator.xpath   sg    ))2	zIOO,=,==tDD>!"89"DEEE{9ff_&=&=>>>r!   combinedc           	          | j         |j                 }t          | d|z            }t          j        t
           ||                     |j                  |                     |j                                      S )zTranslate a combined selector.zxpath_%s_combinator)	combinator_mapping
combinatorr   r   r   r*   ru   ro   subselector)r4   r   r   r   s       r   xpath_combinedselectorz(GenericTranslator.xpath_combinedselector*  sj    ,X-@A
4zABB{vvdjj):;;TZZH\=]=]^^
 
 	
r!   negationc                    |                      |j                  }|                      |j                  }|                                 |j        r|                    d|j        z            S |                    d          S )Nznot(%s)0)ru   ro   r   rI   r/   rE   )r4   r   ru   	sub_xpaths       r   xpath_negationz GenericTranslator.xpath_negation2  sw    

8,--JJx344	!!! 	,&&y93F'FGGG&&s+++r!   relationc           	      D   |                      |j                  }|j        }|j        }|                      |j                  }t          | d| j        t          j        t          |j
                           z            }t          j        t           |||                    S )Nzxpath_relation_%s_combinator)ru   ro   r   r   rs   r   r   r   r   r8   valuer*   )r4   r   ru   r   r   rightr   s          r   xpath_relationz GenericTranslator.xpath_relation;  s    

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

;233*%fk#z7G&H&HIJ
 

 {9ffUE&:&:;;;r!   matchingc                                            |j                  } fd|j        D             }|D ]8}|                                 |j        r|                    |j        d           9|S )Nc                 :    g | ]}                     |          S r(   ru   rn   ro   r4   s     r   r   z4GenericTranslator.xpath_matching.<locals>.<listcomp>I  %    MMM(H%%MMMr!   orru   ro   selector_listrI   r/   rE   r4   r   ru   exprses   `    r   xpath_matchingz GenericTranslator.xpath_matchingG  z    

8,--MMMMh6LMMM 	7 	7AOO{ 7##AK666r!   c                                            |j                  } fd|j        D             }|D ]8}|                                 |j        r|                    |j        d           9|S )Nc                 :    g | ]}                     |          S r(   r   r   s     r   r   zAGenericTranslator.xpath_specificityadjustment.<locals>.<listcomp>R  r   r!   r   r   r   s   `    r   xpath_specificityadjustmentz-GenericTranslator.xpath_specificityadjustmentP  r   r!   functionc                 
   d|j                             dd          z  }t          | |d          }|st          d|j         z            t	          j        t           ||                     |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*   ru   ro   )r4   r   method_namer   s       r   xpath_functionz GenericTranslator.xpath_functionY  s{    )HM,A,A#s,K,KK{D11 	W!"E"UVVV{9ffTZZ8I-J-JH&U&UVVVr!   pseudoc                    d|j                             dd          z  }t          | |d          }|st          d|j         z            t	          j        t           ||                     |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*   ru   ro   )r4   r   r   r   s       r   xpath_pseudozGenericTranslator.xpath_pseudoa  sx    '&,*>*>sC*H*HH{D11 	T!"Cfl"RSSS{9ffTZZ-H-H&I&IJJJr!   c                 n   | j         |j                 }t          | d|z            }| j        r|j                                        }n|j        }t          |          }|j        r"|j        d|}|ot          |j                  }|rd|z   }nd|                     |          z  }|j	        d}nJ| j
        r7t          j        t          |j	        j	                                                  }n|j	        j	        }t          j        t           ||                     |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	namespacerH   r   lower_case_attribute_valuesr   r   r8   r*   ru   ro   )r4   ro   r   r   r   safer   r   s           r   xpath_attribzGenericTranslator.xpath_attribj  s4   283DE08;<<* 	#?((**DD?DD!! 	=&000$$7D<L);<<D 	L4ZFF043E3Ed3K3KKF>!EE- 	)KX^%9::@@BBEEN(E{9ffTZZ8I-J-JFTY&Z&Z[[[r!   class_selectorc                 n    |                      |j                  }|                     |d|j                  S )zTranslate a class selector.z@class)ru   ro   xpath_attrib_includes
class_name)r4   r   ru   s      r   xpath_classzGenericTranslator.xpath_class  s3     

>233))%>;TUUUr!   id_selectorc                 n    |                      |j                  }|                     |d|j                  S )zTranslate an ID selector.z@id)ru   ro   xpath_attrib_equalsrf   )r4   r   ru   s      r   
xpath_hashzGenericTranslator.xpath_hash  s0    

;/00''uknEEEr!   c                 T   |j         }|sd}d}n7t          t          |                    }| j        r|                                }|j        r/|j        d|}|o t          t          |j                            }|                     |          }|s|                                 |S )z'Translate a type or universal selector.r,   Tr   )r.   )r.   rS   r   lower_case_element_namesr   r   rw   rI   )r4   ro   r.   r   ru   s        r   xpath_elementzGenericTranslator.xpath_element  s    " 	*GDDW--..D, *!--// 	C "*!3!3!3WW=GBDh.@!A!ABBD""7"33 	"!!!r!   leftr   c                 .    |                     d|          S )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/rR   r4   r   r   s      r   xpath_descendant_combinatorz-GenericTranslator.xpath_descendant_combinator  s    yy2E:::r!   c                 .    |                     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                     |                     d|          }|                                 |                    d          S )z)right is a sibling immediately after left/following-sibling::zposition() = 1)rR   rI   rE   r4   r   r   ru   s       r    xpath_direct_adjacent_combinatorz2GenericTranslator.xpath_direct_adjacent_combinator  s=    		0%88""#3444r!   c                 .    |                     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77r!   c                 4    |                     d|dd          S )zHright is a child, grand-child or further descendant of left; select leftz[descendant::r<   T)rO   rP   r   r   s      r   $xpath_relation_descendant_combinatorz6GenericTranslator.xpath_relation_descendant_combinator  s    yy%#[_y```r!   c                 2    |                     d|d          S )z0right is an immediate child of left; select leftz[./r<   rO   r   r   s      r   xpath_relation_child_combinatorz1GenericTranslator.xpath_relation_child_combinator  s    yyy<<<r!   c                 `    |                     d                    |j                            }|S )z6right is a sibling immediately after left; select leftz:following-sibling::*[(name() = '{}') and (position() = 1)])rE   formatr.   r   s       r   )xpath_relation_direct_adjacent_combinatorz;GenericTranslator.xpath_relation_direct_adjacent_combinator  s5     ""HOOPUP]^^
 
 r!   c                 2    |                     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MMr!   TlastrI   c                 0   	 t          |j                  \  }}n%# t          $ r t          d|j        z            w xY w|dz
  }|dk    r|dk    r|S |dk     r|dk     r|                    d          S |rd}n
d|j        z  }|sd|z  }	nd|z  }	|dk    r|                    |	d	|          S g }
|dk    r!|dk    r|
                    |	d
|           n|
                    |	d|           t          |          dk    rD|	}| t          |          z  }|dk    rd|z  }d|d|d}|
                    |d|d           t          |
          dk    rdnd|                    d	                    fd|
D                                  |S )NzInvalid series: '%r'   r   r   r,   z%szcount(preceding-sibling::%s)zcount(following-sibling::%s) = z >= z <= z+%srC   rY   rD   z mod z = 0z(%s)z and c              3   "   K   | ]	}|z  V  
d S r3   r(   )rn   
expressiontemplates     r   rp   z=GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>P  s(      (](]:J)>(](](](](](]r!   )
r   	arguments
ValueErrorr#   rE   r.   appendabslenrR   )r4   ru   r   r   rI   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33DAqq 	O 	O 	O!"88;M"MNNN	OX a% 66gllL
 q55Wq[[&&s+++
  	,HHem+H  	G;hFNN;hFN 66&&NNNGG'LMMMq55 {{""#IJJJ
 ^^^WWEFFF q66Q;;!D
 XQ'Ezz$u}$(DD,,,7$$$:;;;{aHHHGLL(](](](]Q\(](](]]]^^^s    "=c                 2    |                      ||d          S )NT)r   )r   r4   ru   r   s      r   xpath_nth_last_child_functionz/GenericTranslator.xpath_nth_last_child_functionS  s    ,,UH4,HHHr!   c                 f    |j         dk    rt          d          |                     ||d          S )Nr,   "*:nth-of-type() is not implementedF)rI   r.   r#   r   r  s      r   xpath_nth_of_type_functionz,GenericTranslator.xpath_nth_of_type_functionV  s9    =C!"FGGG,,UHE,RRRr!   c                 h    |j         dk    rt          d          |                     ||dd          S )Nr,   r  TF)r   rI   r  r  s      r   xpath_nth_last_of_type_functionz1GenericTranslator.xpath_nth_last_of_type_function[  s<    =C!"FGGG,,UH4W\,]]]r!   c                    |                                 dgdgfvrt          d|j        z            t          j        t
          |j        d         j                  }|                    d|                     |          z            S )NSTRINGIDENTz9Expected a single string or ident for :contains(), got %rr   zcontains(., %s)	argument_typesr#   r   r   r   r8   r   rE   rH   r4   ru   r   r   s       r   xpath_contains_functionz)GenericTranslator.xpath_contains_function`  s     ""$$hZ',CCC!KhN``   C!3A!6!<==""#4t7I7I%7P7P#PQQQr!   c                    |                                 dgdgfvrt          d|j        z            t          j        t
          |j        d         j                  }|                    d|                     |          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C!G(J\\   C!3A!6!<=="":1C1CE1J1J#KLLLr!   c                 ,    |                     d          S )Nznot(parent::*)rE   r4   ru   s     r   xpath_root_pseudoz#GenericTranslator.xpath_root_pseudot  s    ""#3444r!   c                 ,    |                     d          S )N1r  r  s     r   xpath_scope_pseudoz$GenericTranslator.xpath_scope_pseudo|  s    ""3'''r!   c                 ,    |                     d          S )Nzcount(preceding-sibling::*) = 0r  r  s     r   xpath_first_child_pseudoz*GenericTranslator.xpath_first_child_pseudo      ""#DEEEr!   c                 ,    |                     d          S )Nzcount(following-sibling::*) = 0r  r  s     r   xpath_last_child_pseudoz)GenericTranslator.xpath_last_child_pseudo  r  r!   c                 p    |j         dk    rt          d          |                    d|j         z            S )Nr,   z"*:first-of-type is not implementedz count(preceding-sibling::%s) = 0r.   r#   rE   r  s     r   xpath_first_of_type_pseudoz,GenericTranslator.xpath_first_of_type_pseudo  s:    =C!"FGGG""#E#UVVVr!   c                 p    |j         dk    rt          d          |                    d|j         z            S )Nr,   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  s:    =C!"EFFF""#E#UVVVr!   c                 ,    |                     d          S )Nzcount(parent::*/child::*) = 1r  r  s     r   xpath_only_child_pseudoz)GenericTranslator.xpath_only_child_pseudo  s    ""#BCCCr!   c                 p    |j         dk    rt          d          |                    d|j         z            S )Nr,   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  s:    =C!"EFFF""#Cem#STTTr!   c                 ,    |                     d          S )Nznot(*) and not(string-length())r  r  s     r   xpath_empty_pseudoz$GenericTranslator.xpath_empty_pseudo  r  r!   c                 ,    |                     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                 8    |rJ |                     |           |S r3   r  r4   ru   r   r   s       r   xpath_attrib_existsz%GenericTranslator.xpath_attrib_exists  s'    D!!!r!   c                 h    |J |                     |d|                     |                     |S )Nr   rE   rH   r-  s       r   r   z%GenericTranslator.xpath_attrib_equals  sA       t/A/A%/H/H/HIJJJr!   c           
          |J |r2|                     d|d|d|                     |                     n-|                     |d|                     |                     |S )Nznot(z) or z != r0  r-  s       r   xpath_attrib_differentz(GenericTranslator.xpath_attrib_different  s         	PtttTEWEWX]E^E^E^ _````dddD4F4Fu4M4M4M NOOOr!   c           
          |rGt          |          r8|                    |d|d|                     d|z   dz             d           n|                    d           |S )Nz* and contains(concat(' ', normalize-space(z	), ' '), rY   rD   r   )is_non_whitespacerE   rH   r-  s       r   r   z'GenericTranslator.xpath_attrib_includes  s      	%&u-- 	%44t11#+2CDDDDF   
 $$$r!   c                     |J |                     |d|d|                     |          d|d|                     |dz             d
           |S )Nz and (r   z or starts-with(, r   z))r0  r-  s       r   xpath_attrib_dashmatchz(GenericTranslator.xpath_attrib_dashmatch  sy        ttTTT4--e4444dddD<N<NuWZ{<[<[<[<[]	
 	
 	
 r!   c           	          |r2|                     |d|d|                     |          d           n|                     d           |S )Nz and starts-with(r6  rD   r   r0  r-  s       r   xpath_attrib_prefixmatchz*GenericTranslator.xpath_attrib_prefixmatch  sj      	%04dddD<N<Nu<U<U<U<UV    $$$r!   c                     |rG|                     |d|d|dt          |          dz
  d|                     |          	           n|                     d           |S )Nz and substring(z, string-length(z)-r   z) = r   )rE   r   rH   r-  s       r   xpath_attrib_suffixmatchz*GenericTranslator.xpath_attrib_suffixmatch  s      	%44tttSZZ!^^^T5G5G5N5N5NP   
 $$$r!   c           	          |r2|                     |d|d|                     |          d           n|                     d           |S )Nz and contains(r6  rD   r   r0  r-  s       r   xpath_attrib_substringmatchz-GenericTranslator.xpath_attrib_substringmatch  sj      	%-1TT4449K9KE9R9R9R9RS    $$$r!   N)rg   )rg   F)FT)Xr$   r%   r&   r'   r   r   id_attributelang_attributer   r   r   r*   rw   r8   rq   r   rS   rm   r   ry   staticmethodrH   r	   ru   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   r2  r   r7  r9  r;  r=  r(   r!   r   rG   rG      s-	        *  	  	" 	" L  N   %!&"' M
 
 
S 
c 
 
 
 
6 -*/	!+ !+!+ !+ $(	!+
 
!+ !+ !+ !+FD) D] DW` D D D D      \ ?T ?i ? ? ? ?
/? 
I 
 
 
 
,x ,I , , , ,
<x 
<I 
< 
< 
< 
<x I    4I i    Wx WI W W W WK6 Ki K K K K\V \	 \ \ \ \0V% VI V V V VFd Fy F F F F
g )    ,;	 ;) ;PY ; ; ; ;%9 %Y %9 % % % %5Y 5y 5U^ 5 5 5 58y 8 8W` 8 8 8 8a a9 aYb a a a a=I =i =T] = = = =&/	   NN&/N	N N N N _cC CC*2C:>CW[C	C C C CJI9 I IU^ I I I IS	 SX SR[ S S S S
^Y ^( ^W` ^ ^ ^ ^
RY R( Ry R R R RM Mh M9 M M M M5y 5Y 5 5 5 5(	 (i ( ( ( (Fi FI F F F FFY F9 F F F FW	 Wi W W W W
Wy WY W W W W
DY D9 D D D DUy UY U U U U
F	 Fi F F F F() (	 ( ( ( ( -/-.-./0/ # hsm Xa    
 # hsm Xa    
		&)	2:3-			 	 	 	

&)
2:3-
	
 
 
 
		&)	2:3-			 	 	 			&)	2:3-			 	 	 	&)2:3-	   

&)
2:3-
	
 
 
 
 
 
r!   rG   c                   |    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dS )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.

    langFxhtmlr1   Nc                 8    || _         |sd| _        d| _        d S d S )NT)rM  r   r   )r4   rM  s     r   r5   zHTMLTranslator.__init__  s1    
 	3,0D).2D+++	3 	3r!   ru   c                 ,    |                     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   rI  z#HTMLTranslator.xpath_checked_pseudo  s    "";
 
 	
r!   r   c           	      "   |                                 dgdgfvrt          d|j        z            |j        d         j        }|sJ |                    d| j        d|                     |                                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   rE   r?  rH   r   r  s       r   r  z"HTMLTranslator.xpath_lang_function  s    ""$$hZ',CCC!G(J\\   "1%+"""
 !///1C1CEKKMMTWDW1X1X1X1X	Z
 
 	
r!   c                 ,    |                     d          S )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')r  r  s     r   rA  z HTMLTranslator.xpath_link_pseudo-  s    ""O
 
 	
r!   c                 ,    |                     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   rH  z$HTMLTranslator.xpath_disabled_pseudo5  s    ""
 
 	
r!   c                 ,    |                     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   rG  z#HTMLTranslator.xpath_enabled_pseudoS  s    ""
 
 	
r!   )F)r$   r%   r&   r'   r?  rS   r5   r*   rI  r   r  rA  rH  rG  r(   r!   r   rK  rK    s           N3 3d 3t 3 3 3 3
) 
	 
 
 
 

 
h 
9 
 
 
 

y 
Y 
 
 
 

9 
 
 
 
 
< 
)  
	  
  
  
  
  
  
r!   rK  r3   )$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   r4  rG   rK  r(   r!   r   <module>r[     s+    
			                                             * ' ' ' '> > > > >m\ > > >; ; ; ; ; ; ; ;| $F++1 
 rz677= BJ1228 q	 q	 q	 q	 q	 q	 q	 q	hx
 x
 x
 x
 x
& x
 x
 x
 x
 x
r!   