o
    e                     @   sH   d Z dgZddlmZ ddlmZ ddlZddl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   )CSSVariablesDeclaration)cssrule    Nc                       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__Z
_atkeywordcssutilsZstylesheetsZ	MediaList_media	variablesr   Z	_readonly)self	mediaTextr   r   r   r   	__class__ MD:\Projects\ConvertPro\env\Lib\site-packages\cssutils/css/cssvariablesrule.pyr   ,   s   
zCSSVariablesRule.__init__c                 C   s   d | jj| jj| jjS )Nz/cssutils.css.{}(mediaText={!r}, variables={!r}))formatr   __name__r   r   r   cssTextr   r   r   r   __repr__D   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__K   s   zCSSVariablesRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)r   ZserZdo_CSSVariablesRuler   r   r   r   _getCssTextX   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)ZblockstartonlyseparateEnd{Fz>CSSVariablesRule: No start { of variable declaration found: %r
wellformed:)expectedseq	tokenizerZproductions)Zblockendonlyr   }ZEOFz>CSSVariablesRule: No "}" after variables declaration found: %rz)CSSVariablesRule: Trailing content found.)token)r
   _setCssTextZ
_tokenize2Z
_nexttoken_typeZ_prodsZVARIABLES_SYM_logr   Z	_valuestrxmldomZInvalidModificationErrr   Z_tokensupto2Z_tokenvalueZ_tempSeq_parseappendr   Z_setSeqr   )r   r   r%   ZattokenZnewVariablesokZbeforetokensbracenewZnewseqZbeforewellformedr#   ZvariablestokensZbraceorEOFtokenvaltype_Z	nonetokenr   r   r   r(   \   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)Z_checkReadonly
isinstancestrr   
_variablesZ_parentRule)r   r   r   r   r   _setVariables   s   

zCSSVariablesRule._setVariablesc                 C      | j S N)r7   r   r   r   r   <lambda>       zCSSVariablesRule.<lambda>zV(DOM) The variables of this rule set, a :class:`cssutils.css.CSSVariablesDeclaration`.c                 C   r9   r:   )ZVARIABLES_RULEr   r   r   r   r;      r<   z=The type of this rule, as defined by a CSSRule type constant.c                 C      dS NTr   r   r   r   r   r;          zNOT IMPLEMTED REALLY (TODO)c                 C   r=   r>   r   r   r   r   r   r;      r?   )NNNNF)r   
__module____qualname____doc__r   r   r   r   r(   propertyr   Zmediar8   r   typer   r!   __classcell__r   r   r   r   r      s@    !])rB   __all__Zcssvariablesdeclarationr    r   r   Zxml.domr+   ZCSSRuler   r   r   r   r   <module>   s    