o
    »ÙøiJ  ã                   @   sÔ   d dl mZ ddlmZmZmZmZ ddlmZ d*dd„Z	dd	„ Z
d*d
d„Zd*dd„Zdd„ Zd+dd„Zdd„ Zdd„ Zd,dd„Zd,dd„Zd*dd„Zd,dd„Zd,dd „Zd!d"„ Zd#d$„ Zd%d&„ Z		'd-d(d)„Zd'S ).é    )Úchainé   )ÚAtRuleÚDeclarationÚ
ParseErrorÚQualifiedRule)Úparse_component_value_listFc                 C   s   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_comments© r   ú\/home/develop/edictos_py/central_edictos/env/lib/python3.10/site-packages/tinycss2/parser.pyÚ_to_token_iterator   s   


r   c                 C   s    | D ]}|j dvr|  S qdS )zçReturn 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Útokenr   r   r   Ú_next_significant   s
   
ÿÿr   c                 C   sN   t | |ƒ}t|ƒ}t|ƒ}|du rtddddƒS |dur%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`.

    Nr   ÚemptyúInput is emptyúextra-inputzGot more than one token)r   r   r   Úsource_lineÚsource_column)r   r   r   ÚfirstÚsecondr   r   r   Úparse_one_component_value#   s   

þr   c                 C   s2   t | |ƒ}t|ƒ}|du r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.

    Nr   r   r   )r   r   r   Ú_parse_declaration)r   r   r   Úfirst_tokenr   r   r   Úparse_one_declaration?   s
   

r"   c                 C   s.   | D ]}|dkr d S |r|dkr d S qd S )Nú;Ú}r   )r   Únestedr   r   r   r   Ú_consume_remnantsW   s   €ür&   Tc                 C   sb  | }|j dkrt||ƒ t|j|jdd|j › d�ƒS t|ƒ}|du r0t||ƒ t|j|jddƒS |dkrBt||ƒ t|j|jddƒS g }d	}d
}d
}t|ƒD ]=\}	}
|d	kr_|
dkr_d}|	}n'|dkrp|
j dkrp|
jdkrpd}n|
j dvr†d	}|
j dkr„|r�d}nd}nd}| |
¡ qN|dkr•||d…= |r¢|r¢t|j|jddƒS 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`.
    :type nested: :obj:`bool`
    :param nested: Whether the declaration is nested or top-level.
    :returns:
        A :class:`~tinycss2.ast.Declaration`
        or :class:`~tinycss2.ast.ParseError`.

    ÚidentÚinvalidz+Expected <ident> for declaration name, got Ú.Nz,Expected ':' after declaration name, got EOFú:z6Expected ':' after declaration name, got {colon.type}.ÚvalueFú!ÚbangÚ	importantr   ú{} blockTzDeclaration contains {} block)r   r&   r   r   r   r   Ú	enumerateÚlower_valueÚappendr   r+   )r!   r   r%   ÚnameÚcolonr+   ÚstateÚcontains_non_whitespaceÚcontains_simple_blockÚir   Úbang_positionr   r   r   r    _   sd   


þ

þ

þ




þþr    c                 C   sŽ   g }g }| dkr)| j dkr)|D ]}|dkr| |¡  n| |¡ |j dkr( nqt| t|ƒdd�}|j dkr9|S t|||ƒ}t| |ddd�S )z#Consume declaration or nested rule.r#   r/   T)r%   Údeclaration)Ú
stop_tokenr%   )r   r2   r    r   r   Ú_consume_qualified_rule)r!   r   Údeclaration_tokensÚsemicolon_tokenr   r:   r   r   r   Ú_consume_blocks_content©   s$   


ÿ
ÿ
r?   c                 C   s2   g }|D ]}|dkr n|  |¡ qt| t|ƒƒS )z�Like :func:`_parse_declaration`, but stop at the first ``;``.

    Deprecated, use :func:`_consume_blocks_content` instead.

    r#   )r2   r    r   )r!   r   Úother_declaration_tokensr   r   r   r   Ú_consume_declaration_in_list¾   s   rA   c                 C   ó„   t | |ƒ}g }|D ]6}|jdkr|s| |¡ q	|jdkr%|s$| |¡ q	|jdkr3| t||ƒ¡ q	|dkr?| t||ƒ¡ q	|S )u–  Parse a blockâ€™s contents.

    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 and/or qualified rule,
    all :class:`~tinycss2.ast.AtRule` and/or
    :class:`~tinycss2.ast.QualifiedRule` 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.QualifiedRule`,
        :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-keywordr#   )r   r   r2   Ú_consume_at_ruler?   ©r   r   Úskip_whitespacer   Úresultr   r   r   r   Úparse_blocks_contentsÌ   ó"   
$

€

€
€rH   c                 C   rB   )u­  Parse a :diagram:`declaration list` (which may also contain at-rules).

    Deprecated and removed from CSS Syntax Level 3. Use
    :func:`parse_blocks_contents` instead.

    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   rC   r#   )r   r   r2   rD   rA   rE   r   r   r   Úparse_declaration_list   rI   rJ   c                 C   s^   t | |ƒ}t|ƒ}|du rtddddƒS t||ƒ}t|ƒ}|dur-t|j|jdd|j ƒ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.

    Nr   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Únextr   r   r   Úparse_one_rule4  s   


þrN   c                 C   s`   t | |ƒ}g }|D ]$}|jdkr|s| |¡ q	|jdkr%|s$| |¡ q	| t||ƒ¡ q	|S )a  Parse a non-top-level :diagram:`rule list`.

    Deprecated and removed from CSS Syntax. Use :func:`parse_blocks_contents`
    instead.

    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   r2   rK   rE   r   r   r   Úparse_rule_listV  s   
!

€

€rP   c                 C   sh   t | |ƒ}g }|D ](}|jdkr|s| |¡ q	|jdkr%|s$| |¡ q	|dvr1| t||ƒ¡ q	|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-->rO   rE   r   r   r   Úparse_stylesheet…  s   


€

€€rQ   c                 C   s   | j dkr
t| |ƒS t| |ƒ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`.

    rC   )r   rD   r<   )r!   r   r   r   r   rK   ²  s   


rK   c                 C   sV   g }d}|D ]}|j dkr|j} n|dkr n| |¡ q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`.
    :type nested: :obj:`bool`
    :param nested: Whether the at-rule is nested or top-level.
    :returns:
        A :class:`~tinycss2.ast.QualifiedRule`,
        or :class:`~tinycss2.ast.ParseError`.

    Nr/   r#   )r   Úcontentr2   r   r   r   r+   r1   )Ú
at_keywordr   ÚpreluderR   r   r   r   r   rD   Æ  s   
þrD   c                 C   s   t | j| jd|› d�ƒS )z6Create rule parse error raised because of given token.r(   z. reached before {} block for a qualified rule.)r   r   r   )r   r3   r   r   r   Ú_rule_erroræ  s   
þrU   Nc                 C   sŠ   | |kr	t | dƒS | jdkrg }| }n(| g}|D ]}||kr%t |dƒ  S |jdkr.|} n| |¡ qt |d dƒS t| j| j||jƒS )aø  Consume a qualified 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`.
    :type nested: :obj:`bool`
    :param nested: Whether the rule is nested or top-level.
    :type stop_token: :class:`~tinycss2.ast.Node`
    :param stop_token: A token that ends rule parsing when met.

    z
Stop tokenr/   éÿÿÿÿÚEOF)rU   r   r2   r   r   r   rR   )r!   r   r%   r;   rT   Úblockr   r   r   r   r<   í  s"   


ÿr<   )F)T)FF)FN)Ú	itertoolsr   Úastr   r   r   r   Ú	tokenizerr   r   r   r   r"   r&   r    r?   rA   rH   rJ   rN   rP   rQ   rK   rD   rU   r<   r   r   r   r   Ú<module>   s,    



J

4
4
"
/- ÿ