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 )zCSSFontFaceRule implements DOM Level 2 CSS CSSFontFaceRule.

From cssutils 0.9.6 additions from CSS Fonts Module Level 3 are
added http://www.w3.org/TR/css3-fonts/.
CSSFontFaceRule    N   )cssrule)CSSStyleDeclarationc                       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
dd Ze	dd eddZe	dd ddZdd Ze	eddZe	dd Z  ZS )r   a7  
    The CSSFontFaceRule interface represents a @font-face rule in a CSS
    style sheet. The @font-face rule is used to hold a set of font
    descriptions.

    Format::

        font_face
          : FONT_FACE_SYM S*
            '{' S* declaration [ ';' S* declaration ]* '}' S*
          ;

    cssutils uses a :class:`~cssutils.css.CSSStyleDeclaration`  to
    represent the font descriptions. For validation a specific profile
    is used though were some properties have other valid values than
    when used in e.g. a :class:`~cssutils.css.CSSStyleRule`.
    NFc                    s4   t  j||d d| _|r|| _nt | _|| _dS )z
        If readonly allows setting of properties in constructor only.

        :param style:
            CSSStyleDeclaration used to hold any font descriptions
            for this CSSFontFaceRule
        )
parentRuleparentStyleSheetz
@font-faceN)super__init__
_atkeywordstyler   	_readonly)selfr   r   r   readonly	__class__ P/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssfontfacerule.pyr	   $   s   

zCSSFontFaceRule.__init__c                 C   s   d| j j d| jjdS )Nzcssutils.css.z(style=))r   __name__r   cssTextr   r   r   r   __repr__8   s   zCSSFontFaceRule.__repr__c              	   C   s.   d| j j d| jjd| jdt| dd	S )Nz<cssutils.css.z object style=z valid=z at 0xx>)r   r   r   r   valididr   r   r   r   __str__;   s   .zCSSFontFaceRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)cssutilsserdo_CSSFontFaceRuler   r   r   r   _getCssText>   s   zCSSFontFaceRule._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 )ad  
        :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.
        Nz-CSSFontFaceRule: No CSSFontFaceRule found: %s)error)r   T)blockstartonlyseparateEnd{Fz:CSSFontFaceRule: No start { of style declaration found: %r
wellformed:)expectedseq	tokenizerproductions)blockendonlyr#   }EOFz9CSSFontFaceRule: No "}" after style declaration found: %rz(CSSFontFaceRule: Trailing content found.)token)r   _setCssText
_tokenize2
_nexttoken_type_prodsFONT_FACE_SYM_logr!   	_valuestrxmldomInvalidModificationErrr   _tokensupto2_tokenvalue_tempSeq_parseappendr   _setSeqr   )r   r   r)   attokennewStyleokbeforetokensbracenewnewseqbeforewellformedr'   styletokensbraceorEOFtokenvaltype_	nonetokenr   r   r   r/   B   sp   









zCSSFontFaceRule._setCssTextz7(DOM) The parsable textual representation of this rule.)docc                 C   s4   |    t|trt|| d| _dS | |_|| _dS )zK
        :param style:
            a CSSStyleDeclaration or string
        )r   r   N)_checkReadonly
isinstancestrr   _style_parentRule)r   r   r   r   r   	_setStyle   s
   

zCSSFontFaceRule._setStylec                 C      | j S N)rQ   r   r   r   r   <lambda>       zCSSFontFaceRule.<lambda>z[(DOM) The declaration-block of this rule set, a :class:`~cssutils.css.CSSStyleDeclaration`.c                 C   rT   rU   )FONT_FACE_RULEr   r   r   r   rV      rW   z=The type of this rule, as defined by a CSSRule type constant.c              	   C   sT   ddg}| j jddD ]}|js dS z||j W q ty$   Y qw t| S )Nzfont-familysrcT)allF)r   getPropertiesr   removename
ValueErrorbool)r   neededpr   r   r   	_getValid   s   
zCSSFontFaceRule._getValidz`CSSFontFace is valid if properties `font-family` and `src` are set and all properties are valid.c                 C   s   dS )NTr   r   r   r   r   rV      s    )NNNF)r   
__module____qualname____doc__r	   r   r   r    r/   propertyr   rS   r   typerb   r   r%   __classcell__r   r   r   r   r      s:    S)re   __all__xml.domr7   r    r   cssstyledeclarationr   CSSRuler   r   r   r   r   <module>   s    