3
3P2                 @   sZ  d Z ddlmZ ddlZddlZddlZddlZddlZdjddjddZ	d	Z
i Zg Zi Zg Zye W n ek
r   eZeZY nX d
d Ze  eeejfddZejejed ejjeZejejded  jdZejejded  ejjejddZejed j Z!G dd de"Z#G dd de"Z$G dd de$Z%G dd de&Z'dS )z
    tinycss.token_data
    ------------------

    Shared data for both implementations (Cython and Python) of the tokenizer.

    :copyright: (c) 2012 by Simon Sapin.
    :license: BSD, see LICENSE for more details.
    )unicode_literalsNa  
    nl	\n|\r\n|\r|\f
    w	[ \t\r\n\f]*
    nonascii	[^\0-\237]
    unicode	\\([0-9a-f]{{1,6}})(\r\n|[ \n\r\t\f])?
    simple_escape	[^\n\r\f0-9a-f]
    escape	{unicode}|\\{simple_escape}
    nmstart	[_a-z]|{nonascii}|{escape}
    nmchar	[_a-z0-9-]|{nonascii}|{escape}
    name	{nmchar}+
    ident	[-]?{nmstart}{nmchar}*
    num	[-+]?(?:[0-9]*\.[0-9]+|[0-9]+)
    string1	\"([^\n\r\f\\"]|\\{nl}|{escape})*\"
    string2	\'([^\n\r\f\\']|\\{nl}|{escape})*\'
    string	{string1}|{string2}
    badstring1	\"([^\n\r\f\\"]|\\{nl}|{escape})*\\?
    badstring2	\'([^\n\r\f\\']|\\{nl}|{escape})*\\?
    badstring	{badstring1}|{badstring2}
    badcomment1	\/\*[^*]*\*+([^/*][^*]*\*+)*
    badcomment2	\/\*[^*]*(\*+[^/*][^*]*)*
    badcomment	{badcomment1}|{badcomment2}
    baduri1	url\({w}([!#$%&*-~]|{nonascii}|{escape})*{w}
    baduri2	url\({w}{string}{w}
    baduri3	url\({w}{badstring}
    baduri	{baduri1}|{baduri2}|{baduri3}
z\0 z\237   a  
    S	[ \t\r\n\f]+

    URI	url\({w}({string}|([!#$%&*-\[\]-~]|{nonascii}|{escape})*){w}\)
    BAD_URI	{baduri}
    FUNCTION	{ident}\(
    UNICODE-RANGE	u\+[0-9a-f?]{{1,6}}(-[0-9a-f]{{1,6}})?
    IDENT	{ident}

    ATKEYWORD	@{ident}
    HASH	#{name}

    DIMENSION	({num})({ident})
    PERCENTAGE	{num}%
    NUMBER	{num}

    STRING	{string}
    BAD_STRING	{badstring}

    COMMENT	\/\*[^*]*\*+([^/*][^*]*\*+)*\/
    BAD_COMMENT	{badcomment}

    :	:
    ;	;
    {	\{{
    }	\}}
    (	\(
    )	\)
    [	\[
    ]	\]
    CDO	<!--
    CDC	-->
c        	      C   s~  t j  x>tj D ]2} | j r| jd\}}d|jf t  t |j < qW dd tj D tdd< t	j  x t
tD ]\}\}}|t	|< qtW dd tdD }xd	d
gfddddgftjd td ddgftjd dddgfddgfddgfdddgfddd gfd!d"gfd#d$gfg
D ],\}}x |D ]}|t| j| q$W qW xd%D ]}|g|t|< qLW d&d |D tdd< dS )'zImport-time initialization.	z(?:%s)c             s   sL   | ]D}|j  r|jd gD ]*\}}|j  tj|jf ttjjfV  qqdS )r   N)stripsplitrecompileformatCOMPILED_MACROSImatch).0linenamevalue r   R/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/tinycss/token_data.py	<genexpr>   s   	z_init.<locals>.<genexpr>Nc             S   s   g | ]}g qS r   r   )r   ir   r   r   
<listcomp>   s    z_init.<locals>.<listcomp>   z 	
SZuUURIZBAD_URIzUNICODE-RANGEz\_-   ZFUNCTIONZIDENTz.+-Z	DIMENSIONZ
PERCENTAGENUMBER@Z	ATKEYWORD#HASHz'"STRINGZ
BAD_STRING/COMMENTZBAD_COMMENT<ZCDO-ZCDCz:;{}()[]c             s   s   | ]}d d |D V  qdS )c             S   s*   g | ]"}t | gD ]}|ft|  qqS r   )COMPILED_TOKEN_INDEXESCOMPILED_TOKEN_REGEXPS)r   r   indexr   r   r   r      s   z#_init.<locals>.<genexpr>.<listcomp>Nr   )r   namesr   r   r   r      s   )r   clearMACROS
splitlinesr   r   r
   TOKENSr%   r$   	enumeraterangestringascii_lettersunichrdigitsordextendTOKEN_DISPATCH)	r   r   r   r   Zregexpdispatchcharsr'   charr   r   r   _init   s:    	



r8   c             C   s(   || j dd}||kr ||S dS d S )N      u   �)group)r   intr0   
maxunicodeZ	codepointr   r   r   _unicode_replace   s    r>   unicodez()\\nl z\\(%s)Zsimple_escaper;   r9   c               @   s0   e Zd ZdZdZdZd	d
 Zdd Zdd ZdS )Tokenu;  A single atomic token.

    .. attribute:: is_container

        Always ``False``.
        Helps to tell :class:`Token` apart from :class:`ContainerToken`.

    .. attribute:: type

        The type of token as a string:

        ``S``
            A sequence of white space

        ``IDENT``
            An identifier: a name that does not start with a digit.
            A name is a sequence of letters, digits, ``_``, ``-``, escaped
            characters and non-ASCII characters. Eg: ``margin-left``

        ``HASH``
            ``#`` followed immediately by a name. Eg: ``#ff8800``

        ``ATKEYWORD``
            ``@`` followed immediately by an identifier. Eg: ``@page``

        ``URI``
            Eg: ``url(foo)`` The content may or may not be quoted.

        ``UNICODE-RANGE``
            ``U+`` followed by one or two hexadecimal
            Unicode codepoints. Eg: ``U+20-00FF``

        ``INTEGER``
            An integer with an optional ``+`` or ``-`` sign

        ``NUMBER``
            A non-integer number  with an optional ``+`` or ``-`` sign

        ``DIMENSION``
            An integer or number followed immediately by an
            identifier (the unit). Eg: ``12px``

        ``PERCENTAGE``
            An integer or number followed immediately by ``%``

        ``STRING``
            A string, quoted with ``"`` or ``'``

        ``:`` or ``;``
            That character.

        ``DELIM``
            A single character not matched in another token. Eg: ``,``

        See the source of the :mod:`.token_data` module for the precise
        regular expressions that match various tokens.

        Note that other token types exist in the early tokenization steps,
        but these are ignored, are syntax errors, or are later transformed
        into :class:`ContainerToken` or :class:`FunctionToken`.

    .. attribute:: value

        The parsed value:

        * INTEGER, NUMBER, PERCENTAGE or DIMENSION tokens: the numeric value
          as an int or float.
        * STRING tokens: the unescaped string without quotes
        * URI tokens: the unescaped URI without quotes or
          ``url(`` and ``)`` markers.
        * IDENT, ATKEYWORD or HASH tokens: the unescaped token,
          with ``@`` or ``#`` markers left as-is
        * Other tokens: same as :attr:`as_css`

        *Unescaped* refers to the various escaping methods based on the
        backslash ``\`` character in CSS syntax.

    .. attribute:: unit

        * DIMENSION tokens: the normalized (unescaped, lower-case)
          unit name as a string. eg. ``'px'``
        * PERCENTAGE tokens: the string ``'%'``
        * Other tokens: ``None``

    .. attribute:: line

        The line number in the CSS source of the start of this token.

    .. attribute:: column

        The column number (inside a source line) of the start of this token.

    Ftype_as_cssr   unitr   columnc             C   s(   || _ || _|| _|| _|| _|| _d S )N)rC   rD   r   rE   r   rF   )selftype_Z	css_valuer   rE   r   rF   r   r   r   __init__9  s    zToken.__init__c             C   s   | j S )zs
        Return as an Unicode string the CSS representation of the token,
        as parsed in the source.
        )rD   )rG   r   r   r   as_cssA  s    zToken.as_cssc             C   s   dj | | jpdS )Nz6<Token {0.type} at {0.line}:{0.column} {0.value!r}{1}>rA   )r
   rE   )rG   r   r   r   __repr__H  s    zToken.__repr__N)rC   rD   r   rE   r   rF   )	__name__
__module____qualname____doc__is_container	__slots__rI   rJ   rK   r   r   r   r   rB      s   ]rB   c               @   s8   e Zd ZdZdZdZdZd
d Zdd ZdZ	dd Z
dS )ContainerTokenaY  A token that contains other (nested) tokens.

    .. attribute:: is_container

        Always ``True``.
        Helps to tell :class:`ContainerToken` apart from :class:`Token`.

    .. attribute:: type

        The type of token as a string. One of ``{``, ``(``, ``[`` or
        ``FUNCTION``. For ``FUNCTION``, the object is actually a
        :class:`FunctionToken`.

    .. attribute:: unit

        Always ``None``. Included to make :class:`ContainerToken` behave
        more like :class:`Token`.

    .. attribute:: content

        A list of :class:`Token` or nested :class:`ContainerToken`,
        not including the opening or closing token.

    .. attribute:: line

        The line number in the CSS source of the start of this token.

    .. attribute:: column

        The column number (inside a source line) of the start of this token.

    TNrC   
_css_start_css_endcontentr   rF   c             C   s(   || _ || _|| _|| _|| _|| _d S )N)rC   rS   rT   rU   r   rF   )rG   rH   	css_startcss_endrU   r   rF   r   r   r   rI   r  s    zContainerToken.__init__c             C   s4   | j g}|jdd | jD  |j| j dj|S )zs
        Return as an Unicode string the CSS representation of the token,
        as parsed in the source.
        c             s   s   | ]}|j  V  qd S )N)rJ   )r   tokenr   r   r   r     s    z(ContainerToken.as_css.<locals>.<genexpr>rA   )rS   r3   rU   appendrT   join)rG   partsr   r   r   rJ   z  s    zContainerToken.as_cssz0<ContainerToken {0.type} at {0.line}:{0.column}>c             C   s   | j d j| S )Nz {0.content})format_stringr
   )rG   r   r   r   rK     s    zContainerToken.__repr__)rC   rS   rT   rU   r   rF   )rL   rM   rN   rO   rP   rE   rQ   rI   rJ   r\   rK   r   r   r   r   rR   M  s    
rR   c                   s(   e Zd ZdZdZ fddZdZ  ZS )FunctionTokenzA specialized :class:`ContainerToken` for a ``FUNCTION`` group.
    Has an additional attribute:

    .. attribute:: function_name

        The unescaped name of the function, with the ``(`` marker removed.

    function_namec                s,   t t| j|||||| |d d | _d S )Nr9   )superr]   rI   r^   )rG   rH   rV   rW   r^   rU   r   rF   )	__class__r   r   rI     s    
zFunctionToken.__init__z:<FunctionToken {0.function_name}() at {0.line}:{0.column}>)r^   )rL   rM   rN   rO   rQ   rI   r\   __classcell__r   r   )ra   r   r]     s   r]   c               @   s0   e Zd ZdZedd Zedd Zdd ZdS )		TokenLista  
    A mixed list of :class:`~.token_data.Token` and
    :class:`~.token_data.ContainerToken` objects.

    This is a subclass of the builtin :class:`~builtins.list` type.
    It can be iterated, indexed and sliced as usual, but also has some
    additional API:

    c             C   s
   | d j S )z5The line number in the CSS source of the first token.r   )r   )rG   r   r   r   r     s    zTokenList.linec             C   s
   | d j S )z<The column number (inside a source line) of the first token.r   )rF   )rG   r   r   r   rF     s    zTokenList.columnc             C   s   dj dd | D S )zt
        Return as an Unicode string the CSS representation of the tokens,
        as parsed in the source.
        rA   c             s   s   | ]}|j  V  qd S )N)rJ   )r   rX   r   r   r   r     s    z#TokenList.as_css.<locals>.<genexpr>)rZ   )rG   r   r   r   rJ     s    zTokenList.as_cssN)rL   rM   rN   rO   propertyr   rF   rJ   r   r   r   r   rc     s   	rc   )(rO   
__future__r   r   sysoperator	functoolsr.   replacer)   r+   r   r%   r$   r4   r0   	NameErrorchrstrr?   r8   r<   r=   r>   partialr	   r   subZUNICODE_UNESCAPEZNEWLINE_UNESCAPEmethodcallerZSIMPLE_UNESCAPEfinditerZFIND_NEWLINESobjectrB   rR   r]   listrc   r   r   r   r   <module>
   sD   0+
8u=