
    mc5                     ~    d dl mZmZmZmZ d dlmZ ddZd ZddZ	ddZ
d Zd Zdd	Zdd
ZddZddZd Zd Zy)   )AtRuleDeclaration
ParseErrorQualifiedRule)parse_component_value_listc                 P    t        | t              rt        | |      } t        |       S )aq  Iterate component values out of string or component values iterable.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments: If the input is a string, ignore all CSS comments.
    :returns: An iterator yielding :term:`component values`.

    )
isinstancestrr   iter)inputskip_commentss     1/usr/lib/python3/dist-packages/tinycss2/parser.py_to_token_iteratorr      s$     %*5-@;    c                 6    | D ]  }|j                   dvs|c S  y)zReturn the next significant (neither whitespace or comment) token.

    :type tokens: :term:`iterator`
    :param tokens: An iterator yielding :term:`component values`.
    :returns: A :term:`component value`, or :obj:`None`.

    
whitespacecommentN)type)tokenstokens     r   _next_significantr      s%      ::66Lr   c                     t        | |      }t        |      }t        |      }|t        dddd      S |"t        |j                  |j                  dd      S |S )a  Parse a single :diagram:`component value`.

    This is used e.g. for an attribute value
    referred to by ``attr(foo length)``.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments: If the input is a string, ignore all CSS comments.
    :returns:
        A :term:`component value` (that is neither whitespace or comment),
        or a :class:`~tinycss2.ast.ParseError`.

    r   emptyInput is emptyextra-inputzGot more than one token)r   r   r   source_linesource_column)r   r   r   firstseconds        r   parse_one_component_valuer!   "   sk      }5Ff%Ev&F}!Q)9:: 4 4m%' 	' r   c                 h    t        | |      }t        |      }|t        dddd      S t        ||      S )a?  Parse a single :diagram:`declaration`.

    This is used e.g. for a declaration in an `@supports
    <https://drafts.csswg.org/css-conditional/#at-supports>`_ test.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments: If the input is a string, ignore all CSS comments.
    :returns:
        A :class:`~tinycss2.ast.Declaration`
        or :class:`~tinycss2.ast.ParseError`.

    Any whitespace or comment before the ``:`` colon is dropped.

    r   r   r   )r   r   r   _parse_declaration)r   r   r   first_tokens       r   parse_one_declarationr%   >   s?    "  }5F#F+K!Q)9::k622r   c           	         | }|j                   dk7  r/t        |j                  |j                  dd|j                   z        S t	        |      }|"t        |j                  |j                  dd      S |dk7  r/t        |j                  |j                  dd|j                   z        S g }d}t        |      D ][  \  }}|dk(  r
|d	k(  rd
}|}n6|d
k(  r!|j                   dk(  r|j                  dk(  rd}n|j                   dvrd}|j                  |       ] |dk(  r|d= t        |j                  |j                  |j                  |j                  ||dk(        S )a  Parse a declaration.

    Consume :obj:`tokens` until the end of the declaration or the first error.

    :type first_token: :term:`component value`
    :param first_token: The first component value of the rule.
    :type tokens: :term:`iterator`
    :param tokens: An iterator yielding :term:`component values`.
    :returns:
        A :class:`~tinycss2.ast.Declaration`
        or :class:`~tinycss2.ast.ParseError`.

    identinvalidz.Expected <ident> for declaration name, got %s.Nz,Expected ':' after declaration name, got EOF:z,Expected ':' after declaration name, got %s.value!bang	importantr   )
r   r   r   r   r   	enumeratelower_valueappendr   r*   )	r$   r   namecolonr*   stateir   bang_positions	            r   r#   r#   V   sw    DyyG$**D,>,>	J II&' 	' f%E}$**D,>,>	HJ 	J	#%++U-@-@)H!JJ'( 	( EEf% 	5GEMf_w!6%%4EZZ88EU	 -.!t''););TZZ''0DF Fr   c                 n    g }|D ]  }|dk(  r n|j                  |        t        | t        |            S )z=Like :func:`_parse_declaration`, but stop at the first ``;``.;)r0   r#   r   )r$   r   other_declaration_tokensr   s       r   _consume_declaration_in_listr9      sD    ! /C< ''./ k40H+IJJr   c                 X   t        | |      }g }|D ]  }|j                  dk(  r|r|j                  |       '|j                  dk(  r|r9|j                  |       K|j                  dk(  r|j                  t        ||             v|dk7  s||j                  t	        ||              |S )uM  Parse a :diagram:`declaration list` (which may also contain at-rules).

    This is used e.g. for the :attr:`~tinycss2.ast.QualifiedRule.content`
    of a style rule or ``@page`` rule,
    or for the ``style`` attribute of an HTML element.

    In contexts that don’t expect any at-rule,
    all :class:`~tinycss2.ast.AtRule` objects
    should simply be rejected as invalid.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments:
        Ignore CSS comments at the top-level of the list.
        If the input is a string, ignore all comments.
    :type skip_whitespace: :obj:`bool`
    :param skip_whitespace:
        Ignore whitespace at the top-level of the list.
        Whitespace is still preserved
        in the :attr:`~tinycss2.ast.Declaration.value` of declarations
        and the :attr:`~tinycss2.ast.AtRule.prelude`
        and :attr:`~tinycss2.ast.AtRule.content` of at-rules.
    :returns:
        A list of
        :class:`~tinycss2.ast.Declaration`,
        :class:`~tinycss2.ast.AtRule`,
        :class:`~tinycss2.ast.Comment` (if ``skip_comments`` is false),
        :class:`~tinycss2.ast.WhitespaceToken`
        (if ``skip_whitespace`` is false),
        and :class:`~tinycss2.ast.ParseError` objects

    r   r   
at-keywordr7   )r   r   r0   _consume_at_ruler9   r   r   skip_whitespacer   resultr   s         r   parse_declaration_listr@      s    D  }5FF 
G::%"e$ZZ9$ e$ZZ<'MM*5&9:c\MM6ufEF
G Mr   c                     t        | |      }t        |      }|t        dddd      S t        ||      }t        |      }|/t        |j                  |j
                  dd|j                  z        S |S )a  Parse a single :diagram:`qualified rule` or :diagram:`at-rule`.

    This would be used e.g. by `insertRule()
    <https://drafts.csswg.org/cssom/#dom-cssstylesheet-insertrule>`_
    in an implementation of CSSOM.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments:
        If the input is a string, ignore all CSS comments.
    :returns:
        A :class:`~tinycss2.ast.QualifiedRule`,
        :class:`~tinycss2.ast.AtRule`,
        or :class:`~tinycss2.ast.ParseError` objects.

    Any whitespace or comment before or after the rule is dropped.

    r   r   r   r   z4Expected a single rule, got %s after the first rule.)r   r   r   _consume_ruler   r   r   )r   r   r   r   rulenexts         r   parse_one_rulerE      s    (  }5Ff%E}!Q)9::'DV$Dd00-BTYYNP 	P Kr   c                     t        | |      }g }|D ]e  }|j                  dk(  r|r|j                  |       '|j                  dk(  r|r9|j                  |       K|j                  t        ||             g |S )a  Parse a non-top-level :diagram:`rule list`.

    This is used for parsing the :attr:`~tinycss2.ast.AtRule.content`
    of nested rules like ``@media``.
    This differs from :func:`parse_stylesheet` in that
    top-level ``<!--`` and ``-->`` tokens are not ignored.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments:
        Ignore CSS comments at the top-level of the list.
        If the input is a string, ignore all comments.
    :type skip_whitespace: :obj:`bool`
    :param skip_whitespace:
        Ignore whitespace at the top-level of the list.
        Whitespace is still preserved
        in the :attr:`~tinycss2.ast.QualifiedRule.prelude`
        and the :attr:`~tinycss2.ast.QualifiedRule.content` of rules.
    :returns:
        A list of
        :class:`~tinycss2.ast.QualifiedRule`,
        :class:`~tinycss2.ast.AtRule`,
        :class:`~tinycss2.ast.Comment` (if ``skip_comments`` is false),
        :class:`~tinycss2.ast.WhitespaceToken`
        (if ``skip_whitespace`` is false),
        and :class:`~tinycss2.ast.ParseError` objects.

    r   r   r   r   r0   rB   r=   s         r   parse_rule_listrH      st    <  }5FF 8::%"e$ZZ9$ e$MM-v678 Mr   c                     t        | |      }g }|D ]j  }|j                  dk(  r|r|j                  |       '|j                  dk(  r|r9|j                  |       K|dvsP|j                  t        ||             l |S )a  Parse :diagram:`stylesheet` from text.

    This is used e.g. for a ``<style>`` HTML element.

    This differs from :func:`parse_rule_list` in that
    top-level ``<!--`` and ``-->`` tokens are ignored.
    This is a legacy quirk for the ``<style>`` HTML element.

    :type input: :obj:`str` or :term:`iterable`
    :param input: A string or an iterable of :term:`component values`.
    :type skip_comments: :obj:`bool`
    :param skip_comments:
        Ignore CSS comments at the top-level of the stylesheet.
        If the input is a string, ignore all comments.
    :type skip_whitespace: :obj:`bool`
    :param skip_whitespace:
        Ignore whitespace at the top-level of the stylesheet.
        Whitespace is still preserved
        in the :attr:`~tinycss2.ast.QualifiedRule.prelude`
        and the :attr:`~tinycss2.ast.QualifiedRule.content` of rules.
    :returns:
        A list of
        :class:`~tinycss2.ast.QualifiedRule`,
        :class:`~tinycss2.ast.AtRule`,
        :class:`~tinycss2.ast.Comment` (if ``skip_comments`` is false),
        :class:`~tinycss2.ast.WhitespaceToken`
        (if ``skip_whitespace`` is false),
        and :class:`~tinycss2.ast.ParseError` objects.

    r   r   )z<!--z-->rG   r=   s         r   parse_stylesheetrJ     s|    >  }5FF 8::%"e$ZZ9$ e$/)MM-v678 Mr   c                 d   | j                   dk(  rt        | |      S | j                   dk(  rg }| }nV| g}|D ]&  }|j                   dk(  r|} n;|j                  |       ( t        |d   j                  |d   j
                  dd      S t        | j                  | j
                  ||j                        S )a  Parse a qualified rule or at-rule.

    Consume just enough of :obj:`tokens` for this rule.

    :type first_token: :term:`component value`
    :param first_token: The first component value of the rule.
    :type tokens: :term:`iterator`
    :param tokens: An iterator yielding :term:`component values`.
    :returns:
        A :class:`~tinycss2.ast.QualifiedRule`,
        :class:`~tinycss2.ast.AtRule`,
        or :class:`~tinycss2.ast.ParseError`.

    r;   {} blockr(   z1EOF reached before {} block for a qualified rule.)r   r<   r0   r   r   r   r   content)r$   r   preludeblockr   s        r   rB   rB   >  s     <'V44:%- 	EEzzZ'NN5!		E '')B)BICE E 00+2K2K %--1 1r   c                     g }d}|D ]7  }|j                   dk(  r|j                  } n|dk(  r n|j                  |       9 t        | j                  | j
                  | j                  | j                  ||      S )a  Parse an at-rule.

    Consume just enough of :obj:`tokens` for this rule.

    :type at_keyword: :class:`AtKeywordToken`
    :param at_keyword: The at-rule keyword token starting this rule.
    :type tokens: :term:`iterator`
    :param tokens: An iterator yielding :term:`component values`.
    :returns:
        A :class:`~tinycss2.ast.QualifiedRule`,
        or :class:`~tinycss2.ast.ParseError`.

    NrL   r7   )r   rN   r0   r   r   r   r*   r/   )
at_keywordr   rO   rN   r   s        r   r<   r<   a  s     GG ::#mmGc\u *((**B*B""J$:$:GWN Nr   N)F)FF)astr   r   r   r   	tokenizerr   r   r   r!   r%   r#   r9   r@   rE   rH   rJ   rB   r<    r   r   <module>rV      sS    ? ? 1 
830.FbK/dD)X*Z 1FNr   