
    &th4                       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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 )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dS )ExpressionErrorz3Unknown or unsupported selector (eg. pseudo-class).N)__name__
__module____qualname____doc__     c/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/cssselect/xpath.pyr   r   -   s        ====r!   r   c                  X    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	dS )$	XPathExpr *Fpathstrelement	conditionstar_prefixboolreturnNonec                0    || _         || _        || _        d S N)r'   r)   r*   )selfr'   r)   r*   r+   s        r"   __init__zXPathExpr.__init__5   s     	"r!   c                    t          | j                  t          | j                  z   }| j        r|d| j         dz  }|S N[]r(   r'   r)   r*   )r1   r'   s     r"   __str__zXPathExpr.__str__@   sE    49~~DL 1 11> 	*)))))Dr!   c                &    | j         j         d|  dS r4   )	__class__r   r1   s    r"   __repr__zXPathExpr.__repr__F   s    .)33D3333r!   and
conjuctionr   c                P    | j         rd| j          d| d| d| _         n|| _         | S )N(z) z ())r*   )r1   r*   r>   s      r"   add_conditionzXPathExpr.add_conditionI   s>    > 	'MMM:MMMMMDNN&DNr!   c                    | j         dk    rd S |                     dt                              | j                               d| _         d S )Nr&   z	name() = )r)   rB   GenericTranslatorxpath_literalr;   s    r"   add_name_testzXPathExpr.add_name_testP   sM    <3FV'8'F'Ft|'T'TVVWWW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_prefixW   s    
 			T				r!   Ncombinerotherclosing_combiner
str | None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 )NrH   r5   r6   r7   )r1   rJ   rK   rL   rN   r'   s         r"   joinzXPathExpr.join^   s     4yy8#:EJD	" 
	14DW 000%- L #_DNN =DL <eo 5 ;; 1 00r!   )r%   r&   r%   F)
r'   r(   r)   r(   r*   r(   r+   r,   r-   r.   )r-   r(   )r=   )r*   r(   r>   r(   r-   r   )r-   r.   )NF)
rJ   r(   rK   r$   rL   rM   rN   r,   r-   r   )
r   r   r   r2   r8   r<   rB   rF   rI   rP   r    r!   r"   r$   r$   4   s         !	# 	# 	# 	# 	#   4 4 4 4           (,$)      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dodpdZ	 	 dqdrdZdsd"Zedtd$            Zdud'Zdvd*Zdwd-Zdxd0Zdyd3Zdzd5Zd{d8Zd|d;Zd}d=Zd~d@ZddCZddEZddHZddIZddJZ ddKZ!ddLZ"ddMZ#ddNZ$ddOZ%	 	 dddSZ&ddTZ'ddUZ(ddVZ)ddWZ*ddXZ+ddYZ,ddZZ-dd[Z.dd\Z/dd]Z0dd^Z1dd_Z2dd`Z3ddaZ4ddbZ5e5Z6e5Z7e5Z8e5Z9e5Z:e5Z;e5Z<e5Z=e5Z>ddfZ?ddgZ@ddhZAddiZBddjZCddkZDddlZEddmZFdnS )rD   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:langFdescendant-or-self::cssr(   prefixr-   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selectorrf   r1   s     r"   	<genexpr>z1GenericTranslator.css_to_xpath.<locals>.<genexpr>   sL       
 
 ""8Vt"TT
 
 
 
 
 
r!   )rP   r   )r1   re   rf   s   ` `r"   css_to_xpathzGenericTranslator.css_to_xpath   sM    & zz 
 
 
 
 
!#JJ
 
 
 
 
 	
r!   rl   r   ri   r,   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%   )getattr	TypeErrorxpath
isinstancexpathexpr_clspseudo_elementxpath_pseudo_elementr(   )r1   rl   rf   ri   treers   s         r"   rj   z#GenericTranslator.selector_to_xpath   s    4 x55 	MKxKKLLL

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

**r!   rs   r$   rv   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   )r1   rs   rv   s      r"   rw   z&GenericTranslator.xpath_pseudo_element  s     BCCCr!   sc                    t          |           } d| vrd|  d} nLd| vrd|  d} nAd t          |           D             }d                    d                    |                    } | S )N'"c                2    g | ]}|d |v rd| dnd | d S )r|   r}   r    )rk   parts     r"   
<listcomp>z3GenericTranslator.xpath_literal.<locals>.<listcomp>  sJ       "d{{DD  r!   z
concat({}),)r(   split_at_single_quotesformatrP   )rz   parts_quoteds     r"   rE   zGenericTranslator.xpath_literal  s    FFa<<AAA\\AAA 2155  L
 ##CHH\$:$:;;Ar!   parsed_selectorr   c           	        t          |          j        }t          t          t          t
          gt          f                  t          | d|                                 d                    }|t          | d           ||          S )z%Translate any parsed selector object.xpath_Nz is not supported.)
typer   r   r   r   r   r$   rq   lowerr   )r1   r   	type_namemethods       r"   rs   zGenericTranslator.xpath   s    ))2	Xtfi/01D69??#4#466==
 
 >!Y"B"B"BCCCvo&&&r!   combinedr
   c           	        | j         |j                 }t          t          t          t          gt          f         t          | d| d                    } ||                     |j                  |                     |j                            S )zTranslate a combined selector.r   _combinator)	combinator_mapping
combinatorr   r   r$   rq   rs   rl   subselector)r1   r   r   r   s       r"   xpath_combinedselectorz(GenericTranslator.xpath_combinedselector-  s~    ,X-@A
i+Y67D:::::;;
 
 vdjj!233TZZ@T5U5UVVVr!   negationr   c                   |                      |j                  }|                      |j                  }|                                 |j        r|                    d|j         d          S |                    d          S )Nnot(rA   0)rs   rl   r   rF   r*   rB   )r1   r   rs   	sub_xpaths       r"   xpath_negationz GenericTranslator.xpath_negation6  s    

8,--JJx344	!!! 	F&&'Di.A'D'D'DEEE""3'''r!   relationr   c                d   |                      |j                  }|j        }|j        }|                      |j                  }t          t          t          t          gt          f         t          | d| j	        t          t          |j                            d                    } |||          S )Nxpath_relation_r   )rs   rl   r   r   rp   r   r   r$   rq   r   r(   value)r1   r   rs   r   r   rightr   s          r"   xpath_relationz GenericTranslator.xpath_relation>  s    

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

;233i+Y67c$"9$sJDT:U:U"Vccc 
 
 veU###r!   matchingr   c                                           |j                  } fd|j        D             }|D ]8}|                                 |j        r|                    |j        d           9|S )Nc                :    g | ]}                     |          S r    rs   rk   rl   r1   s     r"   r   z4GenericTranslator.xpath_matching.<locals>.<listcomp>N  %    MMM(H%%MMMr!   orrs   rl   selector_listrF   r*   rB   r1   r   rs   exprses   `    r"   xpath_matchingz GenericTranslator.xpath_matchingL  z    

8,--MMMMh6LMMM 	7 	7AOO{ 7##AK666r!   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>W  r   r!   r   r   r   s   `    r"   xpath_specificityadjustmentz-GenericTranslator.xpath_specificityadjustmentU  r   r!   functionr   c                j   d                     |j                            dd                    }t          t          t
          t          t          gt          f                  t          | |d                    }|st          d|j         d           || 
                    |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   rq   r   rs   rl   )r1   r   method_namer   s       r"   xpath_functionz GenericTranslator.xpath_function^  s    )001F1FsC1P1PQQXy(3Y>?@D+t,,
 
  	U!"Sx}"S"S"STTTvdjj!233X>>>r!   pseudor   c                \   d                     |j                            dd                    }t          t          t
          t          gt          f                  t          | |d                    }|st          d|j         d           || 	                    |j
                            S )zTranslate a pseudo-class.zxpath_{}_pseudor   r   Nr   z is unknown)r   identr   r   r   r   r$   rq   r   rs   rl   )r1   r   r   r   s       r"   xpath_pseudozGenericTranslator.xpath_pseudoi  s    '..v|/C/CC/M/MNNXyk9456kSW8X8X
 
  	R!"Pv|"P"P"PQQQvdjj11222r!   r   c                   | j         |j                 }t          t          t          t
          t          t
                   gt          f         t          | d|                     }| j        r|j	        
                                }n|j	        }t          |          }|j        r"|j         d| }|ot          |j                  }|rd|z   }nd|                     |           d}|j        d}nE| j        r2t          t
          |j        j                  
                                }n|j        j        } ||                     |j                  ||          S )z Translate an attribute selector.xpath_attrib_:@zattribute::*[name() = r6   N)attribute_operator_mappingoperatorr   r   r$   r(   r   rq   lower_case_attribute_namesattribr   is_safe_name	namespacerE   r   lower_case_attribute_valuesrs   rl   )r1   rl   r   r   r   safer   r   s           r"   xpath_attribzGenericTranslator.xpath_attribt  sV   283DEihsm4i?@D4(4455
 
 * 	#?((**DD?DD!! 	=(11411D<L);<<D 	J4ZFFId.@.@.F.FIIIF>!EE- 	)hn23399;;EEN(Evdjj!233VUCCCr!   class_selectorr	   c                n    |                      |j                  }|                     |d|j                  S )zTranslate a class selector.z@class)rs   rl   xpath_attrib_includes
class_name)r1   r   rs   s      r"   xpath_classzGenericTranslator.xpath_class  s3     

>233))%>;TUUUr!   id_selectorr   c                n    |                      |j                  }|                     |d|j                  S )zTranslate an ID selector.z@id)rs   rl   xpath_attrib_equalsrc   )r1   r   rs   s      r"   
xpath_hashzGenericTranslator.xpath_hash  s0    

;/00''uknEEEr!   r   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)   r,   r   lower_case_element_namesr   r   ru   rF   )r1   rl   r)   r   rs   s        r"   xpath_elementzGenericTranslator.xpath_element  s    " 	*GDDW--..D, *!--// 	C "+77g77G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::*/rP   r1   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)rP   rF   rB   )r1   r   r   rs   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::r6   T)rL   rN   r   r   s      r"   $xpath_relation_descendant_combinatorz6GenericTranslator.xpath_relation_descendant_combinator  s(     yyUSd  
 
 	
r!   c                2    |                     d|d          S )z0right is an immediate child of left; select leftz[./r6   rL   r   r   s      r"   xpath_relation_child_combinatorz1GenericTranslator.xpath_relation_child_combinator  s     yyy<<<r!   c                >    |                     d|j         d          S )z6right is a sibling immediately after left; select leftz following-sibling::*[(name() = 'z') and (position() = 1)])rB   r)   r   s      r"   )xpath_relation_direct_adjacent_combinatorz;GenericTranslator.xpath_relation_direct_adjacent_combinator  s,     !!Vu}VVV
 
 	
r!   c                2    |                     d|d          S )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r6   r   r   r   s      r"   +xpath_relation_indirect_adjacent_combinatorz=GenericTranslator.xpath_relation_indirect_adjacent_combinator  s     yy/yMMMr!   TlastrF   c                .   	 t          |j                  \  }}n+# t          $ r}t          d|j        d          |d }~ww xY w|dz
  }|dk    r|dk    r|S |dk     r|dk     r|                    d          S |rdn|j         }	|sd|	 d}
nd	|	 d}
|dk    r|                    |
 d
|           S g }|dk    r!|dk    r|                    |
 d|            n|                    |
 d|            t          |          dk    r?|
}| t          |          z  }|dk    r	d| d| d}|                    | d| d           t          |          dk    rdnd|                    d	                    fd|D                                  |S )NzInvalid series: 'r|      r   r   r&   count(preceding-sibling::rA   count(following-sibling:: = z >= z <= r@   z +z mod z = 0z(%s)z%sz and c              3  "   K   | ]	}|z  V  
d S r0   r    )rk   
expressiontemplates     r"   rm   z=GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>f  s(      MM:J.MMMMMMr!   )
r   	arguments
ValueErrorr   rB   r)   appendabslenrP   )r1   rs   r   r   rF   abexb_min_1nodetestsiblings_countexpressionsr   b_negr   s                 @r"   xpath_nth_child_functionz*GenericTranslator.xpath_nth_child_function  sJ   	W 233DAqq 	W 	W 	W!"Mh6H"M"M"MNNTVV	WX a% 66gllL
 q55Wq[[&&s+++
 (?33-?  	EDDDDNNDDDDN 66&&.'F'FW'F'FGGGq55 {{""n#C#C'#C#CDDD
 .??g??@@@ q66Q;;!D
 XQ'Ezz+4++5+++$44Q444555 --1166tLLMMMMMMMMM	
 	
 	
 s    
A>Ac                2    |                      ||d          S )NT)r   )r  r1   rs   r   s      r"   xpath_nth_last_child_functionz/GenericTranslator.xpath_nth_last_child_functionj  s     ,,UH4,HHHr!   c                f    |j         dk    rt          d          |                     ||d          S )Nr&   "*:nth-of-type() is not implementedF)rF   r)   r   r  r  s      r"   xpath_nth_of_type_functionz,GenericTranslator.xpath_nth_of_type_functiono  s;     =C!"FGGG,,UHE,RRRr!   c                h    |j         dk    rt          d          |                     ||dd          S )Nr&   r  TF)r   rF   r  r  s      r"   xpath_nth_last_of_type_functionz1GenericTranslator.xpath_nth_last_of_type_functionv  sF     =C!"FGGG,,8$e - 
 
 	
r!   c                   |                                 dgdgfvrt          d|j                  t          t          |j        d         j                  }|                    d|                     |           d          S )NSTRINGIDENTz7Expected a single string or ident for :contains(), got r   zcontains(., rA   argument_typesr   r   r   r(   r   rB   rE   r1   rs   r   r   s       r"   xpath_contains_functionz)GenericTranslator.xpath_contains_function  s    
 ""$$hZ',CCC!`(J\``   S(,Q/566""#N$2D2DU2K2K#N#N#NOOOr!   c                   |                                 dgdgfvrt          d|j                  t          t          |j        d         j                  }|                    d|                     |           d          S )Nr  r  3Expected a single string or ident for :lang(), got r   zlang(rA   r  r  s       r"   xpath_lang_functionz%GenericTranslator.xpath_lang_function  s    ""$$hZ',CCC!\hFX\\   S(,Q/566""#G4+=+=e+D+D#G#G#GHHHr!   c                ,    |                     d          S )Nznot(parent::*)rB   r1   rs   s     r"   xpath_root_pseudoz#GenericTranslator.xpath_root_pseudo  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                r    |j         dk    rt          d          |                    d|j          d          S )Nr&   z"*:first-of-type is not implementedr   ) = 0r)   r   rB   r  s     r"   xpath_first_of_type_pseudoz,GenericTranslator.xpath_first_of_type_pseudo  s@    =C!"FGGG""#Su}#S#S#STTTr!   c                r    |j         dk    rt          d          |                    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  s@    =C!"EFFF""#Su}#S#S#STTTr!   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                r    |j         dk    rt          d          |                    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  s@    =C!"EFFF""#QU]#Q#Q#QRRRr!   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   rM   c                8    |rJ |                     |           |S r0   r  r1   rs   r   r   s       r"   xpath_attrib_existsz%GenericTranslator.xpath_attrib_exists  s(     yD!!!r!   c                h    |J |                     | d|                     |                      |S )Nr   rB   rE   r1  s       r"   r   z%GenericTranslator.xpath_attrib_equals  sE        tCC(:(:5(A(ACCDDDr!   c           
         |J |r2|                     d| d| d|                     |                      n-|                     | d|                     |                      |S )Nr   z) or z != r4  r1  s       r"   xpath_attrib_differentz(GenericTranslator.xpath_attrib_different  s         	J Wt W W$ W WD<N<Nu<U<U W WXXXX4 H HT-?-?-F-F H HIIIr!   c                    |rIt          |          r:|                     d|z   dz             }|                    | d| d| d           n|                    d           |S )NrV   z* and contains(concat(' ', normalize-space(z	), ' '), rA   r   )is_non_whitespacerE   rB   )r1   rs   r   r   args        r"   r   z'GenericTranslator.xpath_attrib_includes  s      	%&u-- 	%$$S5[3%677CXX4XXRUXXX    $$$r!   c                    |J |                      |          }|                      |dz             }|                    | d| d| d| d| d
           |S )Nr   z and (r   z or starts-with(, z)))rE   rB   )r1   rs   r   r   r9  arg_dashs         r"   xpath_attrib_dashmatchz(GenericTranslator.xpath_attrib_dashmatch  s          ''%%eck22MM4MMCMMMMMMM	
 	
 	
 r!   c           	         |r2|                     | d| d|                     |           d           n|                     d           |S )Nz and starts-with(r;  rA   r   r4  r1  s       r"   xpath_attrib_prefixmatchz*GenericTranslator.xpath_attrib_prefixmatch  sn      	%NN$NN$2D2DU2K2KNNN    $$$r!   c                    |rG|                     | d| d| dt          |          dz
   d|                     |           	           n|                     d           |S )Nz and substring(z, string-length(z)-r   z) = r   )rB   r   rE   r1  s       r"   xpath_attrib_suffixmatchz*GenericTranslator.xpath_attrib_suffixmatch  s      	%uuuuduuc%jjSTnuuZ^ZlZlmrZsZsuu    $$$r!   c           	         |r2|                     | d| d|                     |           d           n|                     d           |S )Nz and contains(r;  rA   r   r4  r1  s       r"   xpath_attrib_substringmatchz-GenericTranslator.xpath_attrib_substringmatch  sn      	%KKtKKt/A/A%/H/HKKK    $$$r!   N)rd   )re   r(   rf   r(   r-   r(   )rd   F)rl   r   rf   r(   ri   r,   r-   r(   )rs   r$   rv   r   r-   r$   )rz   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$   )rl   r   r-   r$   )r   r	   r-   r$   )r   r   r-   r$   )rl   r   r-   r$   )r   r$   r   r$   r-   r$   )FT)
rs   r$   r   r   r   r,   rF   r,   r-   r$   rs   r$   r   r   r-   r$   rs   r$   r-   r$   )rs   r$   r   r(   r   rM   r-   r$   )Gr   r   r   r   r   r   id_attributelang_attributer   r   r   r$   ru   rn   rj   rw   staticmethodrE   rs   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_pseudor2  r   r6  r   r=  r?  rA  rC  r    r!   r"   rD   rD      s        *  	  	" 	" L  N   %!&"' M
 
 
 
 
6 -*/	!+ !+ !+ !+ !+F	D 	D 	D 	D    \	' 	' 	' 	'W W W W( ( ( ($ $ $ $      	? 	? 	? 	?	3 	3 	3 	3D D D D6V V V VF F F F
   ,; ; ; ;% % % %5 5 5 58 8 8 8
 
 
 
= = = =
 
 
 
N N N N "B B B B BHI I I I
S S S S
 
 
 

P 
P 
P 
PI I I I5 5 5 5( ( ( (F F F FF F F FU U U U
U U U U
D D D DS S S S
F F F F( ( ( ( -/-.-./0/      	 	 	 	
 
 
 

 
 
 
	 	 	 	
 
 
 

 
 
 
 
 
r!   rD   c                  H    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
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xhtmlr,   r-   r.   c                8    || _         |sd| _        d| _        d S d S )NT)rU  r   r   )r1   rU  s     r"   r2   zHTMLTranslator.__init__3  s1    
 	3,0D).2D+++	3 	3r!   rs   r$   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"   rQ  z#HTMLTranslator.xpath_checked_pseudo:  s    "";
 
 	
r!   r   r   c                &   |                                 dgdgfvrt          d|j                  |j        d         j        }|sJ |                     |                                dz             }|                    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   rE   r   rB   rG  )r1   rs   r   r   r9  s        r"   r  z"HTMLTranslator.xpath_lang_functionC  s    ""$$hZ',CCC!\hFX\\   "1%+u  !455""-  	  
 
 	
r!   c                ,    |                     d          S )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')r  r  s     r"   rI  z HTMLTranslator.xpath_link_pseudoS  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"   rP  z$HTMLTranslator.xpath_disabled_pseudo[  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"   rO  z#HTMLTranslator.xpath_enabled_pseudoy  s    ""
 
 	
r!   N)F)rU  r,   r-   r.   rE  rD  )r   r   r   r   rG  r2   rQ  r  rI  rP  rO  r    r!   r"   rS  rS     s           N3 3 3 3 3
 
 
 

 
 
 
 
 
 
 

 
 
 
< 
  
  
  
  
  
r!   rS  ))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   r8  rD   rS  r    r!   r"   <module>rf     sI    # " " " " " 				 $ $ $ $ $ $ 0 0 0 0 0 0 0 0 0 0                                     (  '&&&&&&> > > > >m\ > > >A A A A A A A AH $F++1 
 rz677= BJ1228 W
 W
 W
 W
 W
 W
 W
 W
ty
 y
 y
 y
 y
& y
 y
 y
 y
 y
r!   