B
    h                 @   s   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dZG dd de
eZG d	d
 d
ZedjZedjZ edjZ!G dd dZ"G d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             C   s   t jdtd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default r   LC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\cssselect\xpath.py_unicode_safe_getattr)   s
    r   c               @   s   e Zd ZdZdS )ExpressionErrorz3Unknown or unsupported selector (eg. pseudo-class).N)__name__
__module____qualname____doc__r   r   r   r   r    4   s   r    c               @   s   e Zd ZdeeeeddddZedd	d
ZedddZdeed dddZddddZ	ddddZ
ded ee ed dddZdS )	XPathExpr *FN)pathelement	conditionstar_prefixreturnc             C   s   || _ || _|| _d S )N)r(   r)   r*   )selfr(   r)   r*   r+   r   r   r   __init__<   s    zXPathExpr.__init__)r,   c             C   s,   t | jt | j }| jr(|d| j 7 }|S )Nz[%s])strr(   r)   r*   )r-   r(   r   r   r   __str__C   s    zXPathExpr.__str__c             C   s   d| j j| f S )Nz%s[%s])	__class__r!   )r-   r   r   r   __repr__I   s    zXPathExpr.__repr__and)r*   
conjuctionr,   c             C   s$   | j rd| j ||f | _ n|| _ | S )Nz(%s) %s (%s))r*   )r-   r*   r4   r   r   r   add_conditionL   s    zXPathExpr.add_conditionc             C   s.   | j dkrd S | dt| j   d| _ d S )Nr'   zname() = %s)r)   r5   GenericTranslatorxpath_literal)r-   r   r   r   add_name_testS   s    
zXPathExpr.add_name_testc             C   s   |  j d7  _ dS )ze
        Append '*/' to the path to keep the context constrained
        to a single parent.
        z*/N)r(   )r-   r   r   r   add_star_prefixZ   s    zXPathExpr.add_star_prefix)combinerotherclosing_combinerhas_inner_conditionr,   c             C   s   t | | }|jdkr ||j7 }|| _|sJ|r8|j| n|j| _|j| _n8|j| _|jrp|  jd|j d 7  _|r|  j|7  _| S )Nz*/[])r/   r(   r)   r*   )r-   r:   r;   r<   r=   r(   r   r   r   joina   s    


zXPathExpr.join)r&   r'   r&   F)r3   )NF)r!   r"   r#   r/   boolr.   r0   r2   r5   r8   r9   r   r@   r   r   r   r   r%   ;   s   
 r%   z('+)z^[a-zA-Z_][a-zA-Z0-9_.-]*$z^[^ \t\r\n\f]+$c            	   @   s  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deeedddZdeeeedddZeeedddZeeedddZeed d!d"Zeed#d$d%Zeed&d'd(Zeed)d*d+Zeed,d-d.Ze ed,d/d0Z!e"ed1d2d3Z#e$ed4d5d6Z%e&ed7d8d9Z'e(ed:d;d<Z)e*ed=d>d?Z+e,ed7d@dAZ-eeedBdCdDZ.eeedBdEdFZ/eeedBdGdHZ0eeedBdIdJZ1eeedBdKdLZ2eeedBdMdNZ3eeedBdOdPZ4eeedBdQdRZ5dee"eeedTdUdVZ6ee"edWdXdYZ7ee"edWdZd[Z8ee"edWd\d]Z9ee"edWd^d_Z:ee"edWd`daZ;eedbdcddZ<eedbdedfZ=eedbdgdhZ>eedbdidjZ?eedbdkdlZ@eedbdmdnZAeedbdodpZBeedbdqdrZCeedbdsdtZDeedbdudvZEeEZFeEZGeEZHeEZIeEZJeEZKeEZLeEZMeEZNeeeOe edwdxdyZPeeeOe edwdzd{ZQeeeOe edwd|d}ZReeeOe edwd~dZSeeeOe edwddZTeeeOe edwddZUeeeOe edwddZVeeeOe edwddZWdS )r6   z
    Translator for "generic" XML documents.

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

    Z
descendantchildZdirect_adjacentZindirect_adjacent) >+~existsequalsincludesZ	dashmatchZprefixmatchZsuffixmatchZsubstringmatchZ	different)rG   =z~=z|=z^=z$=z*=z!=idzxml:langFdescendant-or-self::)cssprefixr,   c                s   d  fd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   s   | ]}j | d dV  qdS )T)translate_pseudo_elementsN)selector_to_xpath).0selector)rN   r-   r   r   	<genexpr>   s   z1GenericTranslator.css_to_xpath.<locals>.<genexpr>)r@   r   )r-   rM   rN   r   )rN   r-   r   css_to_xpath   s    zGenericTranslator.css_to_xpath)rR   rN   rO   r,   c             C   s`   t |dd}|std|f | |}t|| js8t|rP|jrP| ||j}|pVdt| 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 %rr&   )	r   	TypeErrorxpath
isinstancexpathexpr_clsAssertionErrorpseudo_elementxpath_pseudo_elementr/   )r-   rR   rN   rO   treerW   r   r   r   rP      s    

z#GenericTranslator.selector_to_xpath)rW   r[   r,   c             C   s   t ddS )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.N)r    )r-   rW   r[   r   r   r   r\     s    z&GenericTranslator.xpath_pseudo_element)sr,   c             C   sL   t | } d| krd|  } n.d| kr,d|  } ndddd t| D  } | S )	N'z'%s'"z"%s"z
concat(%s),c             S   s$   g | ]}|rd |krdpd| qS )r_   z"%s"z'%s'r   )rQ   partr   r   r   
<listcomp>  s   z3GenericTranslator.xpath_literal.<locals>.<listcomp>)r/   r@   split_at_single_quotes)r^   r   r   r   r7     s    

zGenericTranslator.xpath_literal)parsed_selectorr,   c             C   sB   t |j}t| d|  d}|dkr2td| tt||S )z%Translate any parsed selector object.zxpath_%sNz%s is not supported.)typer!   r   lowerr    typingcastr%   )r-   re   	type_namemethodr   r   r   rW      s
    
zGenericTranslator.xpath)combinedr,   c             C   s<   | j |j }t| d| }tt|| |j| |jS )zTranslate a combined selector.zxpath_%s_combinator)	combinator_mapping
combinatorr   rh   ri   r%   rW   rR   subselector)r-   rl   rn   rk   r   r   r   xpath_combinedselector*  s    z(GenericTranslator.xpath_combinedselector)negationr,   c             C   sD   |  |j}|  |j}|  |jr6|d|j S |dS d S )Nznot(%s)0)rW   rR   ro   r8   r*   r5   )r-   rq   rW   Z	sub_xpathr   r   r   xpath_negation2  s    z GenericTranslator.xpath_negation)relationr,   c             C   sT   |  |j}|j}|j}|  |j}t| d| jtt	|j
  }tt|||S )Nzxpath_relation_%s_combinator)rW   rR   rn   ro   rU   r   rm   rh   ri   r/   valuer%   )r-   rt   rW   rn   ro   rightrk   r   r   r   xpath_relation;  s    z GenericTranslator.xpath_relation)matchingr,   c                sN     |j} fdd|jD }x(|D ] }|  |jr&||jd q&W |S )Nc                s   g | ]}  |qS r   )rW   )rQ   rR   )r-   r   r   rc   I  s    z4GenericTranslator.xpath_matching.<locals>.<listcomp>or)rW   rR   selector_listr8   r*   r5   )r-   rx   rW   exprser   )r-   r   xpath_matchingG  s    
z GenericTranslator.xpath_matchingc                sN     |j} fdd|jD }x(|D ] }|  |jr&||jd q&W |S )Nc                s   g | ]}  |qS r   )rW   )rQ   rR   )r-   r   r   rc   R  s    zAGenericTranslator.xpath_specificityadjustment.<locals>.<listcomp>ry   )rW   rR   rz   r8   r*   r5   )r-   rx   rW   r{   r|   r   )r-   r   xpath_specificityadjustmentP  s    
z-GenericTranslator.xpath_specificityadjustment)functionr,   c             C   sJ   d|j dd }t| |d}|s0td|j  tt|| |j|S )z$Translate a functional pseudo-class.zxpath_%s_function-_Nz!The pseudo-class :%s() is unknown)	r   replacer   r    rh   ri   r%   rW   rR   )r-   r   method_namerk   r   r   r   xpath_functionY  s
    z GenericTranslator.xpath_function)pseudor,   c             C   sH   d|j dd }t| |d}|s0td|j  tt|| |jS )zTranslate a pseudo-class.zxpath_%s_pseudor   r   NzThe pseudo-class :%s is unknown)	identr   r   r    rh   ri   r%   rW   rR   )r-   r   r   rk   r   r   r   xpath_pseudoa  s
    zGenericTranslator.xpath_pseudo)rR   r,   c             C   s   | j |j }t| d| }| jr,|j }n|j}t|}|jr\d|j|f }|oZt|j}|rjd| }nd| | }|j	dkrd}n$| j
rtt|j	j	 }n|j	j	}tt|| |j||S )z Translate an attribute selector.zxpath_attrib_%sz%s:%s@zattribute::*[name() = %s]N)attribute_operator_mappingoperatorr   lower_case_attribute_namesattribrg   is_safe_name	namespacer7   ru   lower_case_attribute_valuesrh   ri   r/   r%   rW   rR   )r-   rR   r   rk   r   safer   ru   r   r   r   xpath_attribj  s$    

zGenericTranslator.xpath_attrib)class_selectorr,   c             C   s   |  |j}| |d|jS )zTranslate a class selector.z@class)rW   rR   xpath_attrib_includes
class_name)r-   r   rW   r   r   r   xpath_class  s    zGenericTranslator.xpath_class)id_selectorr,   c             C   s   |  |j}| |d|jS )zTranslate an ID selector.z@id)rW   rR   xpath_attrib_equalsrK   )r-   r   rW   r   r   r   
xpath_hash  s    zGenericTranslator.xpath_hashc             C   sp   |j }|sd}d}ntt|}| jr.| }|jrTd|j|f }|oRtt|j}| j|d}|sl|  |S )z'Translate a type or universal selector.r'   Tz%s:%s)r)   )r)   rA   r   lower_case_element_namesrg   r   rY   r8   )r-   rR   r)   r   rW   r   r   r   xpath_element  s    zGenericTranslator.xpath_element)leftrv   r,   c             C   s   | d|S )z;right is a child, grand-child or further descendant of leftz/descendant-or-self::*/)r@   )r-   r   rv   r   r   r   xpath_descendant_combinator  s    z-GenericTranslator.xpath_descendant_combinatorc             C   s   | d|S )z#right is an immediate child of left/)r@   )r-   r   rv   r   r   r   xpath_child_combinator  s    z(GenericTranslator.xpath_child_combinatorc             C   s   | d|}|  |dS )z)right is a sibling immediately after leftz/following-sibling::zposition() = 1)r@   r8   r5   )r-   r   rv   rW   r   r   r    xpath_direct_adjacent_combinator  s    z2GenericTranslator.xpath_direct_adjacent_combinatorc             C   s   | d|S )z1right is a sibling after left, immediately or notz/following-sibling::)r@   )r-   r   rv   r   r   r   "xpath_indirect_adjacent_combinator  s    z4GenericTranslator.xpath_indirect_adjacent_combinatorc             C   s   |j d|dddS )zHright is a child, grand-child or further descendant of left; select leftz[descendant::r?   T)r<   r=   )r@   )r-   r   rv   r   r   r   $xpath_relation_descendant_combinator  s    z6GenericTranslator.xpath_relation_descendant_combinatorc             C   s   |j d|ddS )z0right is an immediate child of left; select leftz[./r?   )r<   )r@   )r-   r   rv   r   r   r   xpath_relation_child_combinator  s    z1GenericTranslator.xpath_relation_child_combinatorc             C   s   | d|j}|S )z6right is a sibling immediately after left; select leftz:following-sibling::*[(name() = '{}') and (position() = 1)])r5   formatr)   )r-   r   rv   rW   r   r   r   )xpath_relation_direct_adjacent_combinator  s    z;GenericTranslator.xpath_relation_direct_adjacent_combinatorc             C   s   |j d|ddS )z>right is a sibling after left, immediately or not; select leftz[following-sibling::r?   )r<   )r@   )r-   r   rv   r   r   r   +xpath_relation_indirect_adjacent_combinator  s    z=GenericTranslator.xpath_relation_indirect_adjacent_combinatorT)rW   r   lastr8   r,   c                st  yt |j\}}W n" tk
r4   td|j Y nX |d }|dkrR|dkrR|S |dk rl|dk rl|dS |rvd}n
d|j }|sd| }	nd| }	|dkr|d	|	|f S g }
|dkr|dkr|
d
|	|f  n|
d|	|f  t|dkr:|	}| t| }|dkr(d| }d||f }|
d||f  t|
dkrNd nd |d	 fdd|
D  |S )NzInvalid series: '%r'   r   rr   r'   z%szcount(preceding-sibling::%s)zcount(following-sibling::%s)z%s = %sz%s >= %sz%s <= %sz+%sz(%s %s)z%s mod %s = 0z(%s)z and c             3   s   | ]} | V  qd S )Nr   )rQ   
expression)templater   r   rS   P  s    z=GenericTranslator.xpath_nth_child_function.<locals>.<genexpr>)
r   	arguments
ValueErrorr    r5   r)   appendabslenr@   )r-   rW   r   r   r8   abZb_min_1ZnodetestZsiblings_countZexpressionsr   Zb_negZb_neg_as_strr   )r   r   xpath_nth_child_function  sD    +



z*GenericTranslator.xpath_nth_child_function)rW   r   r,   c             C   s   | j ||ddS )NT)r   )r   )r-   rW   r   r   r   r   xpath_nth_last_child_functionS  s    z/GenericTranslator.xpath_nth_last_child_functionc             C   s"   |j dkrtd| j||ddS )Nr'   z"*:nth-of-type() is not implementedF)r8   )r)   r    r   )r-   rW   r   r   r   r   xpath_nth_of_type_functionV  s    
z,GenericTranslator.xpath_nth_of_type_functionc             C   s$   |j dkrtd| j||dddS )Nr'   z"*:nth-of-type() is not implementedTF)r   r8   )r)   r    r   )r-   rW   r   r   r   r   xpath_nth_last_of_type_function[  s    
z1GenericTranslator.xpath_nth_last_of_type_functionc             C   sJ   |  dgdgfkr"td|j tt|jd j}|d| | S )NSTRINGIDENTz9Expected a single string or ident for :contains(), got %rr   zcontains(., %s))	argument_typesr    r   rh   ri   r/   ru   r5   r7   )r-   rW   r   ru   r   r   r   xpath_contains_function`  s
    z)GenericTranslator.xpath_contains_functionc             C   sJ   |  dgdgfkr"td|j tt|jd j}|d| | S )Nr   r   z5Expected a single string or ident for :lang(), got %rr   zlang(%s))	r   r    r   rh   ri   r/   ru   r5   r7   )r-   rW   r   ru   r   r   r   xpath_lang_functionj  s
    z%GenericTranslator.xpath_lang_function)rW   r,   c             C   s
   | dS )Nznot(parent::*))r5   )r-   rW   r   r   r   xpath_root_pseudot  s    z#GenericTranslator.xpath_root_pseudoc             C   s
   | dS )N1)r5   )r-   rW   r   r   r   xpath_scope_pseudo|  s    z$GenericTranslator.xpath_scope_pseudoc             C   s
   | dS )Nzcount(preceding-sibling::*) = 0)r5   )r-   rW   r   r   r   xpath_first_child_pseudo  s    z*GenericTranslator.xpath_first_child_pseudoc             C   s
   | dS )Nzcount(following-sibling::*) = 0)r5   )r-   rW   r   r   r   xpath_last_child_pseudo  s    z)GenericTranslator.xpath_last_child_pseudoc             C   s"   |j dkrtd|d|j  S )Nr'   z"*:first-of-type is not implementedz count(preceding-sibling::%s) = 0)r)   r    r5   )r-   rW   r   r   r   xpath_first_of_type_pseudo  s    
z,GenericTranslator.xpath_first_of_type_pseudoc             C   s"   |j dkrtd|d|j  S )Nr'   z!*:last-of-type is not implementedz count(following-sibling::%s) = 0)r)   r    r5   )r-   rW   r   r   r   xpath_last_of_type_pseudo  s    
z+GenericTranslator.xpath_last_of_type_pseudoc             C   s
   | dS )Nzcount(parent::*/child::*) = 1)r5   )r-   rW   r   r   r   xpath_only_child_pseudo  s    z)GenericTranslator.xpath_only_child_pseudoc             C   s"   |j dkrtd|d|j  S )Nr'   z!*:only-of-type is not implementedzcount(parent::*/child::%s) = 1)r)   r    r5   )r-   rW   r   r   r   xpath_only_of_type_pseudo  s    
z+GenericTranslator.xpath_only_of_type_pseudoc             C   s
   | dS )Nznot(*) and not(string-length()))r5   )r-   rW   r   r   r   xpath_empty_pseudo  s    z$GenericTranslator.xpath_empty_pseudoc             C   s
   | dS )z:Common implementation for pseudo-classes that never match.rr   )r5   )r-   rW   r   r   r   pseudo_never_matches  s    z&GenericTranslator.pseudo_never_matches)rW   r   ru   r,   c             C   s   |rt || |S )N)rZ   r5   )r-   rW   r   ru   r   r   r   xpath_attrib_exists  s    
z%GenericTranslator.xpath_attrib_existsc             C   s(   |d k	st |d|| |f  |S )Nz%s = %s)rZ   r5   r7   )r-   rW   r   ru   r   r   r   r     s    z%GenericTranslator.xpath_attrib_equalsc             C   sH   |d k	st |r,|d||| |f  n|d|| |f  |S )Nznot(%s) or %s != %sz%s != %s)rZ   r5   r7   )r-   rW   r   ru   r   r   r   xpath_attrib_different  s
    z(GenericTranslator.xpath_attrib_differentc          	   C   s>   |r0t |r0|d||| d| d f  n
|d |S )Nz:%s and contains(concat(' ', normalize-space(%s), ' '), %s)rC   rr   )is_non_whitespacer5   r7   )r-   rW   r   ru   r   r   r   r     s    
z'GenericTranslator.xpath_attrib_includesc             C   s8   |d k	st |d||| ||| |d f  |S )Nz'%s and (%s = %s or starts-with(%s, %s))r   )rZ   r5   r7   )r-   rW   r   ru   r   r   r   xpath_attrib_dashmatch  s
    "z(GenericTranslator.xpath_attrib_dashmatchc             C   s.   |r | d||| |f  n
| d |S )Nz%s and starts-with(%s, %s)rr   )r5   r7   )r-   rW   r   ru   r   r   r   xpath_attrib_prefixmatch  s
    
z*GenericTranslator.xpath_attrib_prefixmatchc          
   C   s:   |r,| d|||t|d | |f  n
| d |S )Nz/%s and substring(%s, string-length(%s)-%s) = %sr   rr   )r5   r   r7   )r-   rW   r   ru   r   r   r   xpath_attrib_suffixmatch  s    "
z*GenericTranslator.xpath_attrib_suffixmatchc             C   s.   |r | d||| |f  n
| d |S )Nz%s and contains(%s, %s)rr   )r5   r7   )r-   rW   r   ru   r   r   r   xpath_attrib_substringmatch  s
    
z-GenericTranslator.xpath_attrib_substringmatchN)rL   )rL   F)FT)Xr!   r"   r#   r$   rm   r   Zid_attributelang_attributer   r   r   r%   rY   r/   rT   r   rA   rP   r   r\   staticmethodr7   r   rW   r   rp   r   rs   r   rw   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_pseudoZxpath_visited_pseudoZxpath_hover_pseudoZxpath_active_pseudoZxpath_focus_pseudoZxpath_target_pseudoxpath_enabled_pseudoxpath_disabled_pseudoxpath_checked_pseudor   r   r   r   r   r   r   r   r   r   r   r   r   r6      s    	
				
 










r6   c               @   sx   e Zd ZdZdZdeddddZeedd	d
Zee	edddZ
eedddZeedddZeed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.

    langFN)xhtmlr,   c             C   s   || _ |sd| _d| _d S )NT)r   r   r   )r-   r   r   r   r   r.     s    zHTMLTranslator.__init__)rW   r,   c             C   s
   | dS )Nz(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio')))r5   )r-   rW   r   r   r   r     s    z#HTMLTranslator.xpath_checked_pseudo)rW   r   r,   c             C   sX   |  dgdgfkr"td|j |jd j}|s6t|d| j| | d f S )Nr   r   z5Expected a single string or ident for :lang(), got %rr   zancestor-or-self::*[@lang][1][starts-with(concat(translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), %s)]r   )	r   r    r   ru   rZ   r5   r   r7   rg   )r-   rW   r   ru   r   r   r   r     s    z"HTMLTranslator.xpath_lang_functionc             C   s
   | dS )NzA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area'))r5   )r-   rW   r   r   r   r   -  s    z HTMLTranslator.xpath_link_pseudoc             C   s
   | 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]
        )
        )r5   )r-   rW   r   r   r   r   5  s    z$HTMLTranslator.xpath_disabled_pseudoc             C   s
   | 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]
            )
        )
        )r5   )r-   rW   r   r   r   r   S  s    z#HTMLTranslator.xpath_enabled_pseudo)F)r!   r"   r#   r$   r   rA   r.   r%   r   r   r   r   r   r   r   r   r   r   r     s   	r   )N)$r$   rerh   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splitrd   matchr   r   r6   r   r   r   r   r   <module>   s$   L
>    x