3
$™O“  ã               @   sT   d Z ddlmZ dd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ ZG dd„ de	ƒZ
dS )z°
    tinycss.parsing
    ---------------

    Utilities for parsing lists of tokens.

    :copyright: (c) 2012 by Simon Sapin.
    :license: BSD, see LICENSE for more details.
é    )Úunicode_literalsc             C   sR   g }g }x:| D ]2}|j dkr6|jdkr6|j|ƒ g }q|j|ƒ qW |j|ƒ |S )ab  Split a list of tokens on commas, ie ``,`` DELIM tokens.

    Only "top-level" comma tokens are splitting points, not commas inside a
    function or other :class:`ContainerToken`.

    :param tokens:
        An iterable of :class:`~.token_data.Token` or
        :class:`~.token_data.ContainerToken`.
    :returns:
        A list of lists of tokens

    ÚDELIMú,)ÚtypeÚvalueÚappend)ÚtokensÚpartsZ	this_partÚtoken© r   úO/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/tinycss/parsing.pyÚsplit_on_comma   s    


r   c             C   sV   x$t | ƒD ]\}}|jdkr
P q
W g S | |d… } x| rP| d jdkrP| jƒ  q4W | S )a3  Remove whitespace at the beggining and end of a token list.

    Whitespace tokens in-between other tokens in the list are preserved.

    :param tokens:
        A list of :class:`~.token_data.Token` or
        :class:`~.token_data.ContainerToken`.
    :return:
        A new sub-sequence of the list.

    ÚSNé   éÿÿÿÿ)Ú	enumerater   Úpop)r   Úir
   r   r   r   Ústrip_whitespace*   s    
r   c             C   s   dd„ | D ƒS )a>  Remove any top-level whitespace in a token list.

    Whitespace tokens inside recursive :class:`~.token_data.ContainerToken`
    are preserved.

    :param tokens:
        A list of :class:`~.token_data.Token` or
        :class:`~.token_data.ContainerToken`.
    :return:
        A new sub-sequence of the list.

    c             S   s   g | ]}|j d kr|‘qS )r   )r   )Ú.0r
   r   r   r   ú
<listcomp>N   s    z%remove_whitespace.<locals>.<listcomp>r   )r   r   r   r   Úremove_whitespaceA   s    r   c             C   s8   x2| D ]*}|j }|dkr&t|jdƒ qt|dƒ qW dS )zÑValidate a property value.

    :param tokens:
        an iterable of tokens
    :raises:
        :class:`ParseError` if there is any invalid token for the 'value'
        production of the core grammar.

    Ú{zproperty valueN)r   Úvalidate_blockÚcontentÚvalidate_any)r   r
   Útype_r   r   r   Úvalidate_valueQ   s
    

r   c             C   s@   x:| D ]2}|j }|dkr&t|j|ƒ q|dkrt||ƒ qW dS )zï
    :raises:
        :class:`ParseError` if there is any invalid token for the 'block'
        production of the core grammar.
    :param tokens: an iterable of tokens
    :param context: a string for the 'unexpected in ...' message

    r   ú;Ú	ATKEYWORDN)r   r   )r   r   r   r   )r   Úcontextr
   r   r   r   r   r   b   s    	
r   c             C   s\   | j }|dkr*xH| jD ]} t| |ƒ qW n.|dkrX|dkr@d}nd}t| dj|||ƒƒ‚dS )zã
    :raises:
        :class:`ParseError` if this is an invalid token for the
        'any' production of the core grammar.
    :param token: a single token
    :param context: a string for the 'unexpected in ...' message

    ÚFUNCTIONú(ú[r   ÚIDENTÚ	DIMENSIONÚ
PERCENTAGEÚNUMBERÚINTEGERÚURIr   ÚSTRINGÚHASHú:úUNICODE-RANGEÚ}ú)ú]Z	unmatchedZ
unexpectedz{0} {1} token in {2}N)r!   r"   r#   )r   r$   r%   r&   r'   r(   r)   r   r*   r+   r,   r-   )r.   r/   r0   )r   r   r   Ú
ParseErrorÚformat)r
   r    r   Z	adjectiver   r   r   r   s   s    	 r   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )r1   aÝ  Details about a CSS syntax error. Usually indicates that something
    (a rule or a declaration) was ignored and will not appear as a parsed
    object.

    This exception is typically logged in a list rather than being propagated
    to the user API.

    .. attribute:: line

        Source line where the error occured.

    .. attribute:: column

        Column in the source line where the error occured.

    .. attribute:: reason

        What happend (a string).

    c                s0   |j | _ |j| _|| _tt| ƒjdj| ƒƒ d S )Nz.Parse error at {0.line}:{0.column}, {0.reason})ÚlineÚcolumnÚreasonÚsuperr1   Ú__init__r2   )ÚselfZsubjectr5   )Ú	__class__r   r   r7       s
    
zParseError.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   Ú__classcell__r   r   )r9   r   r1   ‹   s   r1   N)r=   Ú
__future__r   r   r   r   r   r   r   Ú
ValueErrorr1   r   r   r   r   Ú<module>
   s   