o
    Zh0h?                     @   sT  d dl mZ dgZh dZd7ddZd8ddZd	d
 Zdd Zdd Zdd Z	dd Z
d8ddZG dd deZG dd dZG dd dZG dd dZG dd dZG dd  d ZG d!d" d"ZG d#d$ d$ZG d%d& d&ZG d'd( d(ZG d)d* d*ZG d+d, d,ZG d-d. d.ZG d/d0 d0ZG d1d2 d2ZG d3d4 d4ZG d5d6 d6ZdS )9    )parse_component_value_listparse>   target-textfootnote-callgrammar-errorspelling-errorfootnote-markerfile-selector-buttonafterbeforemarkerprefixshadowcontentpostfix	selectionplaceholder
first-linefirst-letterNFc              
   c   s    t | tr
t| } t| }|pi }z	t|||V  W n ty2 } z|r,W Y d}~dS |d}~ww 	 | }|du r>dS |dkrbz	t|||V  W n" tya } z
|sW|W Y d}~nd}~ww |snt|d|j dq4)zYield tinycss2 selectors found in given ``input``.

    :param input:
        A string, or an iterable of tinycss2 component values.

    N   ,unexpected  token.)
isinstancestrr   TokenStreamparse_selectorSelectorErrornexttype)input
namespaces	forgivingrelativetokens	exceptionr    r&   G/var/www/html/rh/venv/lib/python3.10/site-packages/cssselect2/parser.pyr      s:   
c                 C   s   |    |r|  }|dv r|j}|   nd}|    t| |\}}	 |  }|  r6|  p1|}|  s,t||}|rBt||}|d urH|S |  }|d u sT|dkrV|S |dv rb|j}	|   n|rgd}	n|S t| |\}
}t	||	|
}q$)N)>+~ r   r   )
skip_whitespace_and_commentpeekvaluer   parse_compound_selectorskip_whitespaceskip_commentSelectorRelativeSelectorCombinedSelector)r$   r!   r#   r-   initial_combinatorresultpseudo_elementhas_whitespaceselector
combinatorcompoundr&   r&   r'   r   1   s>   



r   c                 C   s   t | |}|d ur|ng }	 t| |\}}|d us|d u rn|| q|s,||fdkr2t||fS |  }|r;|jnd}t|d| )Nr   NNEOFz"expected a compound selector, got )parse_type_selectorparse_simple_selectorappendCompoundSelectorr-   r   r   )r$   r!   type_selectorssimple_selectorssimple_selectorr7   r-   	peek_typer&   r&   r'   r/   S   s   

r/   c                 C   sZ   |    t| |}|d u rd S g }|\}}|d ur |t| |d ur+|t| |S N)r0   parse_qualified_namer@   LocalNameSelectorNamespaceSelector)r$   r!   qualified_namerC   	namespace
local_namer&   r&   r'   r>   e   s   
r>   c                 C   s  |   }|d u r
dS |jdkr|jr|   t|jd fS |dkrA|   |  }|d u s2|jdkr:t|d| t|jd fS |jdkrV|   tt	|j
|}|d fS |dkr|   |  }|dkr|  }|d u ss|jdkr{t|d| |j}|tvrt|d	| d |fS |d ur|jdkr|j}|d
v rd |fS t|d fS |d ur|jdkr|j}|dv rt|||d fS t||jd fS t|d| ddS )Nr<   hash.identzExpected a class name, got z[] block:z$Expected a pseudo-element name, got z)Expected a supported pseudo-element, got )r   r
   r   r   function)iswherenothasr   r   )r-   r   is_identifierr   
IDSelectorr.   r   ClassSelectorparse_attribute_selectorr   r   lower_valueSUPPORTED_PSEUDO_ELEMENTSPseudoClassSelector
lower_nameparse_logical_combinationFunctionalPseudoClassSelector	arguments)r$   r!   r-   r   attrr.   namer&   r&   r'   r?   t   sR   

r?   c                 C   sh   d}d}|dkrt }n|dkrt}n|dkrd}t}n|dkr#d}t}dd t| j|||D }||S )	NTFrR   rS   rT   rU   c                 S   s   g | ]	}|j d u r|qS rF   )r7   .0r9   r&   r&   r'   
<listcomp>   s
    
z-parse_logical_combination.<locals>.<listcomp>)MatchesAnySelectorSpecificityAdjustmentSelectorNegationSelectorRelationalSelectorr   r`   )matches_any_tokenr!   rb   r"   r#   selector_class	selectorsr&   r&   r'   r^      s    r^   c                 C   sL  |    t| |dd}|d u r|  }t|d| |\}}|    |  }|d u r0d }d }n9|dv ra|j}|   |    |  }|d u sL|jdvr]|d u rRdn|j}	t|d|	 |j}nt|d| |    |  }d }
|d ur|jd	kr|j d
krd}
n|jd	kr|j dkrd}
n	t|d|j t|||||
S )NT)is_attributezexpected attribute name, got )=z~=z|=z^=z$=z*=)rO   stringNonezexpected attribute value, got z*expected attribute selector operator, got rO   iFszexpected ], got )	r0   rG   r   r   r-   r.   r   lowerAttributeSelector)r$   r!   rJ   r   rK   rL   r-   operatorr.   	next_typecase_sensitiver&   r&   r'   rY      s>   rY   c                 C   s@  |   }|du r
dS |jdkrE|  }|   }|dkr-|rdn|dd}||j|jffS |   ||j}|du rDt|d|j n7|dkro|  }|   }|dkrh|r`t|d|j |dddfS |   d}n|dkrz|   d}ndS |  }|jdkr||j|jffS |dkr|s|dfS t|d|j )zReturn ``(namespace, local)`` for given tokens.

    Can also return ``None`` for a wildcard.

    The empty string for ``namespace`` means "no namespace".

    NrO   | zundefined namespace prefix: *zexpected local name, got )r-   r   r   getr.   rZ   r   )r$   r!   rm   r-   first_identrK   r   r&   r&   r'   rG      sF   

rG   c                   @   s   e Zd ZdZdS )r   z3A specialized ``ValueError`` for invalid selectors.N)__name__
__module____qualname____doc__r&   r&   r&   r'   r     s    r   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )r   c                 C   s   t || _g | _d S rF   )iterr$   peeked)selfr$   r&   r&   r'   __init__  s   

zTokenStream.__init__c                 C   s   | j r| j  S t| jd S rF   )r   popr   r$   r   r&   r&   r'   r     s   
zTokenStream.nextc                 C   s$   | j s| j t| jd  | j d S )N)r   r@   r   r$   r   r&   r&   r'   r-     s   
zTokenStream.peekc                 C   s4   d}	 |   }|d u s|j|vr	 |S |   d}q)NFr   T)r-   r   r   )r   
skip_typesfoundr-   r&   r&   r'   skip!  s   zTokenStream.skipc                 C      |  dgS )N
whitespacer   r   r&   r&   r'   r0   +     zTokenStream.skip_whitespacec                 C   r   )Ncommentr   r   r&   r&   r'   r1   .  r   zTokenStream.skip_commentc                 C   s   |  ddgS )Nr   r   r   r   r&   r&   r'   r,   1  s   z'TokenStream.skip_whitespace_and_commentN)
r}   r~   r   r   r   r-   r   r0   r1   r,   r&   r&   r&   r'   r     s    
r   c                   @   s   e Zd ZdddZdd ZdS )r2   Nc                 C   s@   || _ || _|d u r|j| _d S |j\}}}|||d f| _d S )Nr   )parsed_treer7   specificity)r   treer7   abcr&   r&   r'   r   6  s   zSelector.__init__c                 C   s$   | j r	d| j  nd}| j| S )Nz::ry   )r7   r   )r   pseudor&   r&   r'   __repr__@  s   zSelector.__repr__rF   )r}   r~   r   r   r   r&   r&   r&   r'   r2   5  s    

r2   c                   @   s4   e Zd Zdd Zedd Zedd Zdd Zd	S )
r3   c                 C      || _ || _d S rF   r:   r9   )r   r:   r9   r&   r&   r'   r   F     
zRelativeSelector.__init__c                 C      | j jS rF   )r9   r   r   r&   r&   r'   r   J     zRelativeSelector.specificityc                 C   r   rF   )r9   r7   r   r&   r&   r'   r7   N  r   zRelativeSelector.pseudo_elementc                 C   s$   | j dkr	| jS | j  d| jS )Nr+   r   r   r&   r&   r'   r   R  s   zRelativeSelector.__repr__N)r}   r~   r   r   propertyr   r7   r   r&   r&   r&   r'   r3   E  s    

r3   c                   @   (   e Zd Zdd Zedd Zdd ZdS )r4   c                 C   s   || _ || _|| _d S rF   leftr:   right)r   r   r:   r   r&   r&   r'   r   Y  s   
zCombinedSelector.__init__c                 C   s2   | j j\}}}| jj\}}}|| || || fS rF   )r   r   r   )r   a1b1c1a2b2c2r&   r&   r'   r   a  s   zCombinedSelector.specificityc                 C   s   | j | j | jS rF   r   r   r&   r&   r'   r   g     zCombinedSelector.__repr__Nr}   r~   r   r   r   r   r   r&   r&   r&   r'   r4   X  s
    
r4   c                   @   r   )rA   c                 C   
   || _ d S rF   )rC   )r   rC   r&   r&   r'   r   l     
zCompoundSelector.__init__c                 C   s(   | j rttttdd | j D  S dS )Nc                 s       | ]}|j V  qd S rF   r   rd   selr&   r&   r'   	<genexpr>u      z/CompoundSelector.specificity.<locals>.<genexpr>r   r   r   )rC   tuplemapsumzipr   r&   r&   r'   r   o  s
   zCompoundSelector.specificityc                 C   s   d tt| jS )Nry   )joinr   reprrC   r   r&   r&   r'   r   y  s   zCompoundSelector.__repr__Nr   r&   r&   r&   r'   rA   k  s
    
	rA   c                   @       e Zd ZdZdd Zdd ZdS )rH   )r   r   r   c                 C   s   |\| _ | _d S rF   )rL   lower_local_name)r   rL   r&   r&   r'   r     s   zLocalNameSelector.__init__c                 C   s   | j S rF   )rL   r   r&   r&   r'   r     s   zLocalNameSelector.__repr__Nr}   r~   r   r   r   r   r&   r&   r&   r'   rH   }      rH   c                   @   r   )rI   r   c                 C   r   rF   rK   )r   rK   r&   r&   r'   r     s   
zNamespaceSelector.__init__c                 C   s   | j dkrdS d| j  dS )Nry   rx   {z}|r   r   r&   r&   r'   r     s   zNamespaceSelector.__repr__Nr   r&   r&   r&   r'   rI     s    rI   c                   @   r   )rW   )r   r   r   c                 C   r   rF   rO   )r   rO   r&   r&   r'   r     r   zIDSelector.__init__c                 C      d| j  S )N#r   r   r&   r&   r'   r     r   zIDSelector.__repr__Nr   r&   r&   r&   r'   rW     r   rW   c                   @   r   )rX   r   r   r   c                 C   r   rF   
class_name)r   r   r&   r&   r'   r     r   zClassSelector.__init__c                 C   r   )NrN   r   r   r&   r&   r'   r     r   zClassSelector.__repr__Nr   r&   r&   r&   r'   rX     r   rX   c                   @   r   )rt   r   c                 C   s(   || _ |\| _| _|| _|| _|| _d S rF   )rK   rb   r]   ru   r.   rw   )r   rK   rb   ru   r.   rw   r&   r&   r'   r     s
   
zAttributeSelector.__init__c                 C   s`   | j d u rdnd| j  d}| jd u rdn	d| jrdnd }d| | j | j | j| d	S )
Nz*|r   }ry   r+   rr   rq   [])rK   rw   rb   ru   r.   )r   rK   rw   r&   r&   r'   r     s   zAttributeSelector.__repr__Nr   r&   r&   r&   r'   rt     s    rt   c                   @   r   )r\   r   c                 C   r   rF   rb   )r   rb   r&   r&   r'   r     r   zPseudoClassSelector.__init__c                 C   s
   d| j  S NrP   r   r   r&   r&   r'   r     r   zPseudoClassSelector.__repr__Nr   r&   r&   r&   r'   r\     r   r\   c                   @   r   )r_   r   c                 C   r   rF   )rb   r`   )r   rb   r`   r&   r&   r'   r     r   z&FunctionalPseudoClassSelector.__init__c                 C   s   d| j  t| jS r   )rb   r   r`   r   r&   r&   r'   r     r   z&FunctionalPseudoClassSelector.__repr__Nr   r&   r&   r&   r'   r_     s    r_   c                   @   r   )rh   c                 C   r   rF   selector_listr   r   r&   r&   r'   r     r   zNegationSelector.__init__c                 C      | j rtdd | j D S dS )Nc                 s   r   rF   r   rc   r&   r&   r'   r     r   z/NegationSelector.specificity.<locals>.<genexpr>r   r   maxr   r&   r&   r'   r        zNegationSelector.specificityc                 C      dd dd | jD  dS )Nz:not(, c                 s       | ]}t |V  qd S rF   r   r   r&   r&   r'   r         z,NegationSelector.__repr__.<locals>.<genexpr>)r   r   r   r&   r&   r'   r        zNegationSelector.__repr__Nr   r&   r&   r&   r'   rh     
    
rh   c                   @   r   )ri   c                 C   r   rF   r   r   r&   r&   r'   r     r   zRelationalSelector.__init__c                 C   r   )Nc                 s   r   rF   r   rc   r&   r&   r'   r     r   z1RelationalSelector.specificity.<locals>.<genexpr>r   r   r   r&   r&   r'   r     r   zRelationalSelector.specificityc                 C   r   )Nz:has(r   c                 s   r   rF   r   r   r&   r&   r'   r     r   z.RelationalSelector.__repr__.<locals>.<genexpr>r   r   r   r&   r&   r'   r     r   zRelationalSelector.__repr__Nr   r&   r&   r&   r'   ri     r   ri   c                   @   r   )rf   c                 C   r   rF   r   r   r&   r&   r'   r     r   zMatchesAnySelector.__init__c                 C   r   )Nc                 s   r   rF   r   rc   r&   r&   r'   r     r   z1MatchesAnySelector.specificity.<locals>.<genexpr>r   r   r   r&   r&   r'   r     r   zMatchesAnySelector.specificityc                 C   r   )Nz:is(r   c                 s   r   rF   r   r   r&   r&   r'   r     r   z.MatchesAnySelector.__repr__.<locals>.<genexpr>r   r   r   r&   r&   r'   r     r   zMatchesAnySelector.__repr__Nr   r&   r&   r&   r'   rf     r   rf   c                   @   r   )rg   c                 C   r   rF   r   r   r&   r&   r'   r     r   z&SpecificityAdjustmentSelector.__init__c                 C   s   dS )Nr   r&   r   r&   r&   r'   r     s   z)SpecificityAdjustmentSelector.specificityc                 C   r   )Nz:where(r   c                 s   r   rF   r   r   r&   r&   r'   r   
  r   z9SpecificityAdjustmentSelector.__repr__.<locals>.<genexpr>r   r   r   r&   r&   r'   r   	  r   z&SpecificityAdjustmentSelector.__repr__Nr   r&   r&   r&   r'   rg     s
    
rg   )NFF)F)tinycss2r   __all__r[   r   r   r/   r>   r?   r^   rY   rG   
ValueErrorr   r   r2   r3   r4   rA   rH   rI   rW   rX   rt   r\   r_   rh   ri   rf   rg   r&   r&   r&   r'   <module>   s8    

 "/
&/$



