o
    /h^                     @   s   d Z g dZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZ G dd dej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G dd deZG dd deZG dd deZdS )zCSSValue related classes

- CSSValue implements DOM Level 2 CSS CSSValue
- CSSPrimitiveValue implements DOM Level 2 CSS CSSPrimitiveValue
- CSSValueList implements DOM Level 2 CSS CSSValueList

)CSSValueCSSPrimitiveValueCSSValueListRGBColorCSSVariable    N)ChoicePreDefProd
ProdParserSequencec                       s   e Zd ZdZdZdZdZdZdZddd	d
ddZ	d fdd	Z
dd Z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  ZS ) r   zThe CSSValue interface represents a simple or a complex value.
    A CSSValue object only occurs in a context of a CSS property.
    r               CSS_INHERITCSS_PRIMITIVE_VALUECSS_VALUE_LIST
CSS_CUSTOMCSS_VARIABLE)r   r   r   r   r   NFc                    sZ   t    d| _d| _|| _|dur(t|trt|}n	t|tr%d| }|| _	|| _
dS )z
        :param cssText:
            the parsable cssText of the value
        :param readonly:
            defaults to False
        NFz%f)super__init___cssValueType
wellformedparent
isinstanceintstrfloatcssText	_readonlyselfr   r   readonly	__class__ I/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssvalue.pyr   ,   s   




zCSSValue.__init__c                 C      d| j j d| jdS Nzcssutils.css.()r$   __name__r   r!   r%   r%   r&   __repr__B      zCSSValue.__repr__c                 C   s   d| j j| j| jt| f S )NzA<cssutils.css.%s object cssValueTypeString=%r cssText=%r at 0x%x>)r$   r,   cssValueTypeStringr   idr-   r%   r%   r&   __str__E   s   zCSSValue.__str__c                    s      d}ttt ttj|dtj|dtj|dtj|dtj	|dtj
|dtj|dtj|dtd fdd| fdddtj| fddd	tj| fd
dd	tj| fddd	
}tt tjdddd dtjdddd ddd}t|t|tjddddd|dd d}t j|d|dd\}}}}	|rd\}
}  }dt|}}||k rY|| }|j jjkrn|j|jfdkr|| |
d8 }
|r|d  jjkr|d d f}nk|jdkr|| n`|jd!ks|jd"kr1|d7 }z|| }W n ty   d#}Y nGw |j|j }|||j|j|j |s,||jf}|
d7 }
n |jt j!j"krL|| |sG|j|jf}|
d7 }
n|| |d7 }||k s|si j#$d$ %|  d.S  &| | _'t( d%ry `)|
dkrt*|d t+rd&t j,-|d krt. _/t.j0 _1d.S d'|d krt2 _/| _)|d j3 _3d.S t4 _/| _)d.S |
dkr~t5 _/  }g }d(} fd)d*}d+d, }t6 j7D ]\}}t8t|jt.r j9|j_9|j jj: jj; jj< jj jj= jj> jj? jj@ jjAd'f
v rA|r||| n(||| t(|jd-r/||j|jj/|j|j n|t4||t4|j|j d(}qd|jkr_|sV|| j7|d   |d d}q|rk||jjB q|| q|||  &| d.S t. _/t.jC _1d.S d.S )/a  
        Format::

            unary_operator
              : '-' | '+'
              ;
            operator
              : '/' S* | ',' S* | /* empty */
              ;
            expr
              : term [ operator term ]*
              ;
            term
              : unary_operator?
                [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* |
                  ANGLE S* | TIME S* | FREQ S* ]
              | STRING S* | IDENT S* | URI S* | hexcolor | function
              | UNICODE-RANGE S*
              ;
            function
              : FUNCTION S* expr ')' S*
              ;
            /*
             * There is a constraint on the color that it must
             * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
             * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
             */
            hexcolor
              : HASH S*
              ;

        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error
              (according to the attached property) or is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              TODO: Raised if the specified CSS string value represents a
              different type of values than the values allowed by the CSS
              property.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this value is readonly.
        z,/)nextSor
expressionc                    s&   |  j jkotj|dv p|dS )N)zexpression(zalpha(zblur(zchroma(zdropshadow(zfliph(zflipv(zglow(zgray(zinvert(zmask(zshadow(zwave(zxray(z"progid:DXImageTransform.Microsoft.)_prodsFUNCTIONcssutilshelper	normalize
startswithtvr-   r%   r&   <lambda>   s
    

z&CSSValue._setCssText.<locals>.<lambda>c                       t jt tj| | dfS Nr   ExpressionValue_functionNamer7   r8   	pushtokenr<   tokensr-   r%   r&   r>         )namematchr3   toSeqc                       dt tj| | dfS )Nr   rA   )r   r7   r8   rE   rF   r-   r%   r&   r>         )r3   rK   c                    r?   r@   )	CalcValuerD   r7   r8   rE   rF   r-   r%   r&   r>      rH   c                    rL   )Nr6   rA   CSSFunctionr7   r8   rE   rF   r-   r%   r&   r>      rM   comma,c                 S      d| d fS Noperatorr   r%   rF   r%   r%   r&   r>          rK   slash/c                 S   rS   rT   r%   rF   r%   r%   r&   r>      rV   T)optionalEND;)stopAndKeeprZ   c                   S      dS N)r   Nr%   r%   r%   r%   r&   r>          minmaxr   keepS)r   r%   r   )rR   rU   r   STRING-+r%   z)CSSValue: Unknown syntax or no value: %r._valueinheritr   Fc                    s^    j j| jkrtj| jS  j j| jkrtj| jS  j j	| jks(d| jkr,| jj
S | jS )zReserialized simple item.valuer   )r5   re   typer7   r8   stringvalueURIurir6   r   )itemr-   r%   r&   	itemValueA  s   
z'CSSValue._setCssText.<locals>.itemValuec                 S   s@   | r| dtd| dt|d j|d j | dd= dS dS )z
                        saves items in commalist to seq and items
                        if anything in there
                         )r   N)replacer   joinlinecol)	commalistnewseqr%   r%   r&   saveifcommalistO  s   z-CSSValue._setCssText.<locals>.saveifcommalistr   N)D_checkReadonlyr   r   r   unarynumber
percentage	dimensionrk   identrn   hexcolorunicode_ranger	   variablecalcfunctionScharr
   parse_tempSeqlenrj   r5   rl   
appendItemIDENT
IndexErrorappendru   rv   r7   css
CSSComment_logerror	_valuestr_setSeqr   hasattrrh   r   r   r8   r9   r   r$   r   r   r   _namer   r   	enumerate_seq
issubclassr   	DIMENSIONr6   HASHNUMBER
PERCENTAGEre   rm   UNICODE_RANGEr   r   )r!   r   r3   termrU   
valueprodsr   seqstorenotusedcount
firstvaluerx   iendro   nextnewvalrw   nexttocommalistrp   ry   r%   r-   r&   _setCssTextL   sN  +












T







-








 zCSSValue._setCssTextc                 C      t j| S N)r7   serdo_css_CSSValuer-   r%   r%   r&   r>     rV   zCSSValue.<lambda>-A string representation of the current value.docc                 C      | j S r   )r   r-   r%   r%   r&   r>         z1A (readonly) code defining the type of the value.c                 C   s   t j| jd S r   )r   _typestringsgetcssValueTyper-   r%   r%   r&   r>         z (readonly) Name of cssValueType.NNF)r,   
__module____qualname____doc__r   r   r   r   r   r   r   r.   r2   r   propertyr   r   r0   __classcell__r%   r%   r#   r&   r      s@      Sr   c                       sr  e Zd ZdZejZejj	Z
dZdZdZdZdZdZdZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&eeeeeeeeeeeeeeeeeefZ'e!e eefZ(e"fZ)e#fZ*e$e%fZ+eeeeeeeeef	Z,i eefdd eefd d eefd!d eefd"d eefd#d eefd$d eefd%d eefd&d eefd'd eefd(d eefd)d eefd*d eefd+d eefd,d eefd-d eefd.d eefd/d eefd0d eefd1d eefd2d eefd3d eefd4d eefd5d eefd6d eefd7d eefd8d i	Z-dl fd;d<	Z.d=d> Z/g d?Z0e12d@e1j3e1j4B e1j5B Z6dAdB Z7dCdD Z8e
j9dEe
j:dFe
j;dGe
j<dHe
j=dIe
j>dJe
j?dKe
j@e7e
jAe8i	ZBdLdM ZCdNdO ZDeEeDdPdQZFdRdS ZGeEeGdTdQZHdUdV ZIdmdWdXZJdmdYdZZKd[d\ ZLd]d^ ZMd_d` ZNdadb ZOdcdd ZPdedf ZQdgdh ZR fdidjZSeEeReSdkdQZT  ZUS )nr   aS  Represents a single CSS Value.  May be used to determine the value of a
    specific style property currently set in a block or to set a specific
    style property explicitly within the block. Might be obtained from the
    getPropertyCSSValue method of CSSStyleDeclaration.

    Conversions are allowed between absolute values (from millimeters to
    centimeters, from degrees to radians, and so on) but not between
    relative values. (For example, a pixel value cannot be converted to a
    centimeter value.) Percentage values can't be converted since they are
    relative to the parent value (or another property value). There is one
    exception for color percentage values: since a color percentage value
    is relative to the range 0-255, a color percentage value can be
    converted to a number; (see also the RGBColor interface).
    r   r   r   r   r               	   
                                                      c                 C      | d S Nr   r%   xr%   r%   r&   r>         zCSSPrimitiveValue.<lambda>c                 C      | d S r   r%   r   r%   r%   r&   r>     r   c                 C   r   Nr   r%   r   r%   r%   r&   r>     r   c                 C   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   NRQ@r%   r   r%   r%   r&   r>     r   c                 C   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   Nffffff9@r%   r   r%   r%   r&   r>     r   c                 C   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   NH   r%   r   r%   r%   r&   r>     r   c                 C   r   r   r%   r   r%   r%   r&   r>     r   c                 C      | d d S )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C      | d d S )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C   r   )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C   r   )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C   r   )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C   r   )Nr   r   r%   r   r%   r%   r&   r>     rV   c                 C      | d d d S )Nr   r   r   r%   r   r%   r%   r&   r>     r   c                 C      | d d d S )Nr   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   )Nr   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   )Nr   r   r   r%   r   r%   r%   r&   r>     r   c                 C   r   Ni  r%   r   r%   r%   r&   r>      r   c                 C   r   r   r%   r   r%   r%   r&   r>   !  r   c                 C   r   r   r%   r   r%   r%   r&   r>   #  r   c                 C   r   r   r%   r   r%   r%   r&   r>   $  r   c                 C   
   t | S r   )mathdegreesr   r%   r%   r&   r>   %     
 c                 C   r   r   )r   radiansr   r%   r%   r&   r>   &  r   NFc                    s   t  j|||d dS )z See CSSPrimitiveValue.__init__()r   r   r"   N)r   r   r    r#   r%   r&   r   .  s   zCSSPrimitiveValue.__init__c              	   C   s,   d| j j d| j d| jdt| dd	S )N<cssutils.css.z object primitiveType=	 cssText= at 0xr   >)r$   r,   primitiveTypeStringr   r1   r-   r%   r%   r&   r2   2     ,zCSSPrimitiveValue.__str__)CSS_UNKNOWN
CSS_NUMBERCSS_PERCENTAGECSS_EMSCSS_EXSCSS_PXCSS_CMCSS_MMCSS_INCSS_PTCSS_PCCSS_DEGCSS_RADCSS_GRADCSS_MSCSS_SCSS_HZCSS_KHZCSS_DIMENSION
CSS_STRINGCSS_URI	CSS_IDENTCSS_ATTRCSS_COUNTERCSS_RECTCSS_RGBCOLORCSS_RGBACOLORCSS_UNICODE_RANGEz([+-]?\d*\.\d+|[+-]?\d+)(.*)$c                 C   sL   ddddddddd	d
dddddd}t jtj| d \}}||dS )zCheck val for dimension name.r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  )emexpxcmmminptpcdegradgradmsshzkhzr   r  )r   	_reNumDimfindallr7   r8   r9   r   )rl   unitsvaldimr%   r%   r&   _unitDIMENSIONV  s,   
z CSSPrimitiveValue._unitDIMENSIONc                 C   s6   dddddd}| tdtj| jtjd d	S )
zCheck val for function name.r	  r
  r  r  r  )zattr(zcounter(zrect(rgb(rgba(z^(.*?\()r   r   )r   rer  r7   r8   r9   r   U)rl   r   r%   r%   r&   _unitFUNCTIONn  s   zCSSPrimitiveValue._unitFUNCTIONr   r   r  r  r  r  r  c                 C   s8   | j \}}| j|d}t|r||}t| || _dS )z5primitiveType is readonly but is set lazy if accessedr   N)rh   _CSSPrimitiveValue__unitbytyper   callablegetattr_primitiveType)r!   r!  type_r  r%   r%   r&   __set_primitiveType  s
   
z%CSSPrimitiveValue.__set_primitiveTypec                 C   s   t | ds	|   | jS )N_primitivetype)r   %_CSSPrimitiveValue__set_primitiveTyper,  r-   r%   r%   r&   _getPrimitiveType  s   
z#CSSPrimitiveValue._getPrimitiveTypezK(readonly) The type of the value as defined by the constants in this class.r   c                 C   s   | j | j S r   )
_unitnamesprimitiveTyper-   r%   r%   r&   _getPrimitiveTypeString     z)CSSPrimitiveValue._getPrimitiveTypeStringz%Name of primitive type of this value.c              	   C   s,   z| j | W S  ttfy   d|  Y S w )zBget TypeString by given type which may be unknown, used by settersz%r (UNKNOWN TYPE))r2  r   	TypeError)r!   rj   r%   r%   r&   _getCSSPrimitiveTypeString  s
   z,CSSPrimitiveValue._getCSSPrimitiveTypeStringc              
   C   s   |du rt j| jd }ztj|d \}}W n ty'   |d}}Y nw zt|}|t	|kr<t	|}W ||fS W ||fS  t
yX } ztjd| jd  |d}~ww )z2Split self._value in numerical and dimension part.Nr   rr   z$CSSPrimitiveValue: No float value %r)r7   r8   r9   rh   r   r  r  r   r   r   
ValueErrorxmldomInvalidAccessErr)r!   rl   r!  r"  errr%   r%   r&   
_getNumDim  s,   
zCSSPrimitiveValue._getNumDimc              
   C   s   |dur|| j vrtjd|  \}}|durF| j|krFz| j| j|f |}W n tyE } ztjd| j| 	|f |d}~ww |t
|krPt
|}|S )aG  (DOM) This method is used to get a float value in a
        specified unit. If this CSS value doesn't contain a float value
        or can't be converted into the specified unit, a DOMException
        is raised.

        :param unitType:
            to get the float value. The unit code can only be a float unit type
            (i.e. CSS_NUMBER, CSS_PERCENTAGE, CSS_EMS, CSS_EXS, CSS_PX, CSS_CM,
            CSS_MM, CSS_IN, CSS_PT, CSS_PC, CSS_DEG, CSS_RAD, CSS_GRAD, CSS_MS,
            CSS_S, CSS_HZ, CSS_KHZ, CSS_DIMENSION) or None in which case
            the current dimension is used.

        :returns:
            not necessarily a float but some cases just an integer
            e.g. if the value is ``1px`` it return ``1`` and **not** ``1.0``

            Conversions might return strange values like 1.000000000001
        Nz&unitType Parameter is not a float type7CSSPrimitiveValue: Cannot coerce primitiveType %r to %r)_floattypesr9  r:  r;  r=  r3  
_converterKeyErrorr   r7  r   )r!   unitTyper!  r"  r<  r%   r%   r&   getFloatValue  s*   	zCSSPrimitiveValue.getFloatValuec              
   C   s   |    || jvrtjd| | zt|}W n ty/ } z	tjd| |d}~ww |  \}}| j	|krcz| j
|| j	f |}W n tyb } ztjd| j| |f |d}~ww |t|krmt|}| | | _dS )aZ  (DOM) A method to set the float value with a specified unit.
        If the property attached with this value can not accept the
        specified unit or the float value, the value will be unchanged and
        a DOMException will be raised.

        :param unitType:
            a unit code as defined above. The unit code can only be a float
            unit type
        :param floatValue:
            the new float value which does not have to be a float value but
            may simple be an int e.g. if setting::

                setFloatValue(CSS_PX, 1)

        :exceptions:
            - :exc:`~xml.dom.InvalidAccessErr`:
              Raised if the attached property doesn't
              support the float value or the unit type.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this property is readonly.
        z2CSSPrimitiveValue: unitType %r is not a float typez/CSSPrimitiveValue: floatValue %r is not a floatNr>  )rz   r?  r9  r:  r;  r7  r   r8  r=  r3  r@  rA  r   r   r   )r!   rB  
floatValuer!  r<  oldvalr"  r%   r%   r&   setFloatValue  sH   

	zCSSPrimitiveValue.setFloatValuec                 C   sH   | j | jvrtjd| j tj| j kr| jd j	dd S | jd S )a  (DOM) This method is used to get the string value. If the
        CSS value doesn't contain a string value, a DOMException is raised.

        Some properties (like 'font-family' or 'voice-family')
        convert a whitespace separated list of idents to a string.

        Only the actual value is returned so e.g. all the following return the
        actual value ``a``: url(a), attr(a), "a", 'a'
        )CSSPrimitiveValue %r is not a string typer   r   rq   )
r3  _stringtypesr9  r:  r;  r   r   r	  rh   r   r-   r%   r%   r&   getStringValue   s   

z CSSPrimitiveValue.getStringValuec                 C   s   |    | j| jvrtjd| j || jvr#tjd| | | j|kr6tjd| j| |f t	j
| jkrDtj|| _nt	j| jkrRtj|| _nt	j| jkr^d| | _n|| _|| _dS )aP  (DOM) A method to set the string value with the specified
        unit. If the property attached to this value can't accept the
        specified unit or the string value, the value will be unchanged and
        a DOMException will be raised.

        :param stringType:
            a string code as defined above. The string code can only be a
            string unit type (i.e. CSS_STRING, CSS_URI, CSS_IDENT, and
            CSS_ATTR).
        :param stringValue:
            the new string value
            Only the actual value is expected so for (CSS_URI, "a") the
            new value will be ``url(a)``. For (CSS_STRING, "'a'")
            the new value will be ``"\'a\'"`` as the surrounding ``'`` are
            not part of the string value

        :exceptions:
            - :exc:`~xml.dom.InvalidAccessErr`:
              Raised if the CSS value doesn't contain a
              string value or if the string value can't be converted into
              the specified unit.

            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this property is readonly.
        rG  z5CSSPrimitiveValue: stringType %s is not a string typer>  zattr(%s)N)rz   r3  rH  r9  r:  r;  r   r7  r,  r   r  r7   r8   rk   r   r  rn   r	  )r!   
stringTypestringValuer%   r%   r&   setStringValue4  s6   


z CSSPrimitiveValue.setStringValuec                 C   s   | j | jkstjdt )a  (DOM) This method is used to get the Counter value. If
        this CSS value doesn't contain a counter value, a DOMException
        is raised. Modification to the corresponding style property
        can be achieved using the Counter interface.

        **Not implemented.**
        zValue is not a counter type)r
  r3  r9  r:  r;  NotImplementedErrorr-   r%   r%   r&   getCounterValuen     z!CSSPrimitiveValue.getCounterValuec                 C   s&   | j | jvrtjdt| jd S )z(DOM) This method is used to get the RGB color. If this
        CSS value doesn't contain a RGB color value, a DOMException
        is raised. Modification to the corresponding style property
        can be achieved using the RGBColor interface.
        zValue is not a RGBColor valuer   )r3  	_rbgtypesr9  r:  r;  r   rh   r-   r%   r%   r&   getRGBColorValue{  s   z"CSSPrimitiveValue.getRGBColorValuec                 C   s   | j | jvrtjdt )a  (DOM) This method is used to get the Rect value. If this CSS
        value doesn't contain a rect value, a DOMException is raised.
        Modification to the corresponding style property can be achieved
        using the Rect interface.

        **Not implemented.**
        zvalue is not a Rect value)r3  
_recttypesr9  r:  r;  rM  r-   r%   r%   r&   getRectValue  rO  zCSSPrimitiveValue.getRectValuec                 C   r   )zOverwrites CSSValue.)r7   r   do_css_CSSPrimitiveValuer-   r%   r%   r&   _getCssText     zCSSPrimitiveValue._getCssTextc                       t  |S )zUse CSSValue.r   r   r!   r   r#   r%   r&   r     rV  zCSSPrimitiveValue._setCssTextr   r   r   )Vr,   r   r   r   r   r   r   r7   cssproductionsCSSProductions_CSSPrimitiveValue__typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r	  r
  r  r  r  r  r?  rH  _countertypesrR  rP  _lengthtypesr@  r   r2   r2  r&  compileIr'  Xr  r#  r(  r   r   re   r   rm   r   r   r   r6   r)  r0  r1  r   r3  r4  r   r7  r=  rC  rF  rI  rL  rN  rQ  rS  rU  r   r   r   r%   r%   r#   r&   r     s,   	
'

*6:
r   c                       sX   e Zd ZdZejZd fdd	Zdd Zdd	 Z	d
d Z
dd Zedd ddZ  ZS )r   a}  The CSSValueList interface provides the abstraction of an ordered
    collection of CSS values.

    Some properties allow an empty list into their syntax. In that case,
    these properties take the none identifier. So, an empty list means
    that the property has the value none.

    The items in the CSSValueList are accessible via an integral index,
    starting from 0.
    NFc                    s   t  j|||d g | _dS )zInit a new CSSValueListr   N)r   r   _itemsr    r#   r%   r&   r     s   
zCSSValueList.__init__c                 c   s    |   D ]}|jV  qdS )zCSSValueList is iterable.N)_CSSValueList__itemsrl   )r!   ro   r%   r%   r&   __iter__  s   
zCSSValueList.__iter__c                 C   s    d| j j| j| j| jt| f S )NzE<cssutils.css.%s object cssValueType=%r cssText=%r length=%r at 0x%x>)r$   r,   r0   r   lengthr1   r-   r%   r%   r&   r2     s   zCSSValueList.__str__c                 C   s   dd | j D S )Nc                 S   s   g | ]
}t |jtr|qS r%   )r   rl   r   ).0ro   r%   r%   r&   
<listcomp>  s    z(CSSValueList.__items.<locals>.<listcomp>)r   r-   r%   r%   r&   __items  s   zCSSValueList.__itemsc                 C   s&   z|   | jW S  ty   Y dS w )a	  (DOM) Retrieve a CSSValue by ordinal `index`. The
        order in this collection represents the order of the values in the
        CSS style property. If `index` is greater than or equal to the number
        of values in the list, this returns ``None``.
        N)rc  rl   r   )r!   indexr%   r%   r&   ro     s
   zCSSValueList.itemc                 C   s   t |  S r   )r   rc  r-   r%   r%   r&   r>     rV   zCSSValueList.<lambda>z4(DOM attribute) The number of CSSValues in the list.r   r   )r,   r   r   r   r   r   r   r   rd  r2   rc  ro   r   re  r   r%   r%   r#   r&   r     s    r   c                       sV   e Zd ZdZd ZejZd fdd	Zdd Z	dd	 Z
ed
d e
Zedd Z  ZS )rP   z%A CSS function value like rect() etc.NFc                    s8   t  j|d d| _d| _d| _|dur|| _|| _dS )z
        Init a new CSSFunction

        :param cssText:
            the parsable cssText of the value
        :param readonly:
            defaults to False
        rA   NF)r   r   	_funcTypevalidr   r   r   r    r#   r%   r&   r     s   	
zCSSFunction.__init__c              
      s   | j  tt td fdddd d}t|tjdd d}ttd fd	dd
d dtt|tt |dd dtjddtjdd}|S )z#Return definition used for parsing.PrimitiveValuec                    s    |  j  j j j j jfv S r   )r   r   r   r   r   re   r;   typesr%   r&   r>     s    z3CSSFunction._productiondefinition.<locals>.<lambda>c                 S   s   | d t | d fS Nr   r   r   rF   r%   r%   r&   r>      s    rI   rJ   rK   c                 S   s   dt tj| |fS )Nr6   rO   rF   r%   r%   r&   r>     s   rW   FUNCc                    
   |  j kS r   r6   r;   rm  r%   r&   r>     r   c                 S   s   | d t j| d fS ro  )r7   r8   r9   rF   r%   r%   r&   r>     s    c                   S   r^   r_   r%   r%   r%   r%   r&   r>     r`   ra   Tstop)	r5   r   r   r{   r	   r   r   rQ   funcEnd)r!   rl   valueOrFunc	funcProdsr%   rm  r&   _productiondefinition  s>   
	



z!CSSFunction._productiondefinitionc                 C   s$  |    t j|| j|  dd\}}}}|r|  }dt|}}||k r|| }	|	j| jj	kr2nF|	j
dks<|	j
dkrs|d7 }|| }
|
j
}t|trh||jt|	j
t|   |||
j|	j|	j n||	 ||
 n||	 |d7 }||k s&d| _| | |d j
| _d S d S )NTrc   r   rg   rf   r   )rz   r
   r   rD   rz  r   r   rj   r5   r   rl   r   r   rF  r3  r   r   rC  r   ru   rv   r   r   r   rj  )r!   r   r   r   r   unusedtokensrx   r   r   ro   r   r   r%   r%   r&   r   !  s<   



zCSSFunction._setCssTextc                 C   r   r   )r7   r   do_css_FunctionValuer-   r%   r%   r&   r>   G  rV   zCSSFunction.<lambda>c                 C   r   r   )rj  r-   r%   r%   r&   r>   J  r   r   )r,   r   r   r   rD   r   r   r3  r   rz  r   r   r   funcTyper   r%   r%   r#   r&   rP     s    2%rP   c                       sX   e Zd ZdZdZd fdd	Zdd Zd	d
 Zdd Ze	dd eZ
e	dd Z  ZS )r   zBA CSS color like RGB, RGBA or a simple value like `#000` or `red`.zFunction rgb()NFc                    sZ   t t| j|d d| _d| _d| _|dur(z|j}W n	 ty$   Y nw || _|| _dS )z
        Init a new RGBColor

        :param cssText:
            the parsable cssText of the value
        :param readonly:
            defaults to False
        rA   NF)	r   rP   r   
_colorTyperk  r   r   AttributeErrorr   r    r#   r%   r&   r   R  s   	

zRGBColor.__init__c                 C   r'   r(   r+   r-   r%   r%   r&   r.   i  r/   zRGBColor.__repr__c              	   C   ,   d| j j d| jd| jdt| dd	S )Nr   z object colorType=r   r   r   r   )r$   r,   	colorTyper   r1   r-   r%   r%   r&   r2   l  r   zRGBColor.__str__c           	   
      s  |    | j td fdddd dd}ttd fddd	d d
dt |tt t |dd dt }t|t	d
td fddd
d}t
 j|d|ddg id\}}}}|rd| _|d
 j| jjkrnd| _n|d
 j| jjkr{d| _n
|d
 jd d | _| | d S d S )Nrl   c                    s   |  j  jfv S r   )r   r   r;   rm  r%   r&   r>   t  r   z&RGBColor._setCssText.<locals>.<lambda>c                 S   s   t t |fS r   rp  r;   r%   r%   r&   r>   u  rV   parts)rI   rJ   rK   toStorerr  c                    s   |  j kotj|dv S )N)r$  r%  zhsl(zhsla()r6   r7   r8   r9   r;   rm  r%   r&   r>   |  s   
 c                 S   s   | |fS r   r%   r;   r%   r%   r&   r>   ~  r   r  c                   S   r^   )N)r   r   r%   r%   r%   r%   r&   r>     r`   ra   znamed colorc                    rs  r   )r   r;   rm  r%   r&   r>     r   )rI   rJ   r  r   T)rd   r   HEXzNamed Colorrq   )rz   r5   r	   r   r   r{   rQ   rw  r   r   r
   r   r   rj   r   r~  r   rl   r   )	r!   r   	valueProd	funccolor
colorprodsr   r   r   r{  r%   rm  r&   r   o  sR   



zRGBColor._setCssTextc                 C   r   r   )r7   r   do_css_RGBColorr-   r%   r%   r&   r>     rV   zRGBColor.<lambda>c                 C   r   r   )r~  r-   r%   r%   r&   r>     r   r   )r,   r   r   r   rD   r   r.   r2   r   r   r   r  r   r%   r%   r#   r&   r   M  s    3r   c                       B   e Zd ZdZdZdd Zdd Z fddZeeed	d
Z	  Z
S )rN   zCalc FunctionzFunction calc()c              
      r    j dd }ttdfdd|dtttd fddd	d dtd
dd dd ddd dtjdd}|S )"Return defintion used for parsing.c                 S      | d | d fS zDo not normalize function name!r   r   r%   rF   r%   r%   r&   rK        z.CalcValue._productiondefinition.<locals>.toSeqr   c                    rs  r   rt  r;   rm  r%   r&   r>     r   z1CalcValue._productiondefinition.<locals>.<lambda>rq  nested functionc                       |  j jkS r   r5   r6   r;   r-   r%   r&   r>     rV   c                 S      t jt tj| |fS r   )rP   rD   r7   r8   rE   rF   r%   r%   r&   r>        partc                 S      |dkS Nr*   r%   r;   r%   r%   r&   r>     r   c                 S   r  ro  r%   rF   r%   r%   r&   r>     r   c                   S   r^   r_   r%   r%   r%   r%   r&   r>     r`   ra   Tru  r5   r   r	   r   r   rw  r!   rK   ry  r%   r!   rn  r&   rz    s,   

zCalcValue._productiondefinitionc                 C   r   r   )r7   r   do_css_CalcValuer-   r%   r%   r&   rU    r5  zCalcValue._getCssTextc                    rW  r   rX  rY  r#   r%   r&   r     r5  zCalcValue._setCssTextr   r   r,   r   r   r   rD   rz  rU  r   r   r   r   r%   r%   r#   r&   rN     s     rN   c                       r  )rC   zxSpecial IE only CSSFunction which may contain *anything*.
    Used for expressions and ``alpha(opacity=100)`` currently.zExpression (IE only)c              
      r  )r  c                 S   r  r  r%   rF   r%   r%   r&   rK     r  z4ExpressionValue._productiondefinition.<locals>.toSeqr4   c                    rs  r   rt  r;   rm  r%   r&   r>     r   z7ExpressionValue._productiondefinition.<locals>.<lambda>rq  r  c                    r  r   r  r;   r-   r%   r&   r>     rV   c                 S   r  r   rB   rF   r%   r%   r&   r>     r  r  c                 S   r  r  r%   r;   r%   r%   r&   r>     r   c                 S   r  ro  r%   rF   r%   r%   r&   r>     r   c                   S   r^   r_   r%   r%   r%   r%   r&   r>     r`   ra   Tru  r  r  r%   r  r&   rz    s0   

z%ExpressionValue._productiondefinitionc                 C   r   r   )r7   r   do_css_ExpressionValuer-   r%   r%   r&   rU    r5  zExpressionValue._getCssTextc                    rW  r   rX  rY  r#   r%   r&   r     rV  zExpressionValue._setCssTextr   r   r  r%   r%   r#   r&   rC     s    "rC   c                       sn   e Zd ZdZd fdd	Zdd Zdd	 Zd
d Zedd eddZ	e
jZedd Zdd ZeeZ  ZS )r   z2The CSSVariable represents a call to CSS Variable.NFc                    s   d| _ t j|||d dS )zInit a new CSSVariable.

        :param cssText:
            the parsable cssText of the value, e.g. ``var(x)``
        :param readonly:
            defaults to False
        Nr   )r   r   r   r    r#   r%   r&   r     s   zCSSVariable.__init__c                 C   r'   r(   r+   r-   r%   r%   r&   r.     r/   zCSSVariable.__repr__c              	   C   r  )Nr   z object name=z value=r   r   r   )r$   r,   rI   rl   r1   r-   r%   r%   r&   r2     r   zCSSVariable.__str__c                    s   |    | j ttd fdddtjddtjdd}dd i}t j|d	|dd
\}}}}|rA|d j	| _
| | d| _d S d S )Nvarc                    rs  r   rt  r;   rm  r%   r&   r>   %  r   z)CSSVariable._setCssText.<locals>.<lambda>)rI   rJ   r   )r  Tru  r   rc   )rz   r5   r   r	   r   r   rw  r
   r   rl   r   r   r   )r!   r   ry  r   r   r   r{  r%   rm  r&   r     s    



zCSSVariable._setCssTextc                 C   r   r   )r7   r   do_css_CSSVariabler-   r%   r%   r&   r>   5  rV   zCSSVariable.<lambda>z0A string representation of the current variable.r   c                 C   r   r   )r   r-   r%   r%   r&   r>   =  r   c                 C   sJ   z	| j j jjj}W n
 ty   Y dS w z|| j W S  ty$   Y dS w )z)Find contained sheet and @variables thereN)r   
parentRuleparentStyleSheet	variablesr  rI   rA  )r!   r  r%   r%   r&   	_getValue?  s   zCSSVariable._getValuer   )r,   r   r   r   r   r.   r2   r   r   r   r   r   r   rI   r  rl   r   r%   r%   r#   r&   r     s    r   )r   __all__r   r&  xml.domr9  r7   cssutils.helpercssutils.prodparserr   r   r	   r
   r   util_NewBaser   r   r   rP   r   rN   rC   r   r%   r%   r%   r&   <module>   s,          t9uZ04