o
    /h                     @   sH   d Z dgZddlZddlZddlmZ ddlmZ G dd dej	Z
dS )z~CSSVariables implements (and only partly) experimental
`CSS Variables <http://disruptive-innovations.com/zoo/cssvariables/>`_
CSSVariablesRule    N   )cssrule)CSSVariablesDeclarationc                       s   e Zd ZdZ					d fdd	Zdd Zdd	 Zd
d Z fddZe	eeddZ
e	ddZdd Ze	dd eddZe	dd ddZe	dd ddZe	dd Z  ZS )r   aW  
    The CSSVariablesRule interface represents a @variables rule within a CSS
    style sheet. The @variables rule is used to specify variables.

    cssutils uses a :class:`~cssutils.css.CSSVariablesDeclaration`  to
    represent the variables.

    Format::

        variables
            VARIABLES_SYM S* medium [ COMMA S* medium ]* LBRACE S*
            variableset* '}' S*
            ;

    for variableset see :class:`cssutils.css.CSSVariablesDeclaration`

    **Media are not implemented. Reason is that cssutils is using CSS
    variables in a kind of preprocessing and therefor no media information
    is available at this stage. For now do not use media!**

    Example::

        @variables {
          CorporateLogoBGColor: #fe8d12;
        }

        div.logoContainer {
          background-color: var(CorporateLogoBGColor);
        }
    NFc                    sJ   t  j||d d| _tjj||d| _|r|| _nt| d| _|| _	dS )zO
        If readonly allows setting of properties in constructor only.
        )
parentRuleparentStyleSheetz
@variables)readonlyr   N)
super__init__
_atkeywordcssutilsstylesheets	MediaList_media	variablesr   	_readonly)self	mediaTextr   r   r   r   	__class__ Q/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssvariablesrule.pyr   /   s   
zCSSVariablesRule.__init__c                 C   s$   d| j j d| jjd| jjdS )Nzcssutils.css.z(mediaText=z, variables=))r   __name__r   r   r   cssTextr   r   r   r   __repr__G   s   $zCSSVariablesRule.__repr__c                 C   s$   d| j j| jj| jj| jt| f S )NzC<cssutils.css.%s object mediaText=%r variables=%r valid=%r at 0x%x>)r   r   r   r   r   r   valididr   r   r   r   __str__J   s   zCSSVariablesRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)r   serdo_CSSVariablesRuler   r   r   r   _getCssTextW   s   zCSSVariablesRule._getCssTextc                    s  t  | | |}| |d}| || jjkr+| jjd| 	| t
jjd dS t| d}d}| j|ddd\}}| |dkrQd}| jd	| 	| | d
di}|  }	| jd|	| |i d\}
}|on|
on|d
 }| j|ddd\}}| || |}}|dkr|dkrd}| jd| 	|  | |}|rd}| jjd|d d|kr|| ||_|r| |	 || _dS dS )ar  
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.

        Format::

            variables
            : VARIABLES_SYM S* medium [ COMMA S* medium ]* LBRACE S*
              variableset* '}' S*
            ;

            variableset
            : LBRACE S* vardeclaration [ ';' S* vardeclaration ]* '}' S*
            ;
        Nz/CSSVariablesRule: No CSSVariablesRule found: %s)errorr	   T)blockstartonlyseparateEnd{Fz>CSSVariablesRule: No start { of variable declaration found: %r
wellformed:)expectedseq	tokenizerproductions)blockendonlyr&   }EOFz>CSSVariablesRule: No "}" after variables declaration found: %rz)CSSVariablesRule: Trailing content found.)token)r
   _setCssText
_tokenize2
_nexttoken_type_prodsVARIABLES_SYM_logr$   	_valuestrxmldomInvalidModificationErrr   _tokensupto2_tokenvalue_tempSeq_parseappendr   _setSeqr   )r   r   r,   attokennewVariablesokbeforetokensbracenewnewseqbeforewellformedr*   variablestokensbraceorEOFtokenvaltype_	nonetokenr   r   r   r2   [   sp   









zCSSVariablesRule._setCssTextz7(DOM) The parsable textual representation of this rule.)docz]NOT IMPLEMENTED! As cssutils resolves variables during serializing media information is lost.c                 C   s4   |    t|trt|| d| _dS | |_|| _dS )zS
        :param variables:
            a CSSVariablesDeclaration or string
        )r   r   N)_checkReadonly
isinstancestrr   
_variables_parentRule)r   r   r   r   r   _setVariables   s   

zCSSVariablesRule._setVariablesc                 C      | j S N)rT   r   r   r   r   <lambda>       zCSSVariablesRule.<lambda>zV(DOM) The variables of this rule set, a :class:`cssutils.css.CSSVariablesDeclaration`.c                 C   rW   rX   )VARIABLES_RULEr   r   r   r   rY      rZ   z=The type of this rule, as defined by a CSSRule type constant.c                 C      dS NTr   r   r   r   r   rY          zNOT IMPLEMTED REALLY (TODO)c                 C   r\   r]   r   r   r   r   r   rY      r^   )NNNNF)r   
__module____qualname____doc__r   r   r    r#   r2   propertyr   mediarV   r   typer   r(   __classcell__r   r   r   r   r      s@    !])ra   __all__xml.domr:   r    r   cssvariablesdeclarationr   CSSRuler   r   r   r   r   <module>   s    