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 )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   )CSSStyleDeclaration)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
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__Z
_atkeywordstyler   Z	_readonly)selfr
   r   r   readonly	__class__ LD:\Projects\ConvertPro\env\Lib\site-packages\cssutils/css/cssfontfacerule.pyr	   !   s   

zCSSFontFaceRule.__init__c                 C   s   d | jj| jjS )Nzcssutils.css.{}(style={!r}))formatr   __name__r
   cssTextr   r   r   r   __repr__5   s   zCSSFontFaceRule.__repr__c                 C   s   d | jj| jj| jt| S )Nz8<cssutils.css.{} object style={!r} valid={!r} at 0x{:x}>)r   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.)cssutilsZserZdo_CSSFontFaceRuler   r   r   r   _getCssTextC   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)ZblockstartonlyseparateEnd{Fz:CSSFontFaceRule: No start { of style declaration found: %r
wellformed:)expectedseq	tokenizerZproductions)Zblockendonlyr   }ZEOFz9CSSFontFaceRule: No "}" after style declaration found: %rz(CSSFontFaceRule: Trailing content found.)token)r   _setCssTextZ
_tokenize2Z
_nexttoken_typeZ_prodsZFONT_FACE_SYM_logr   Z	_valuestrxmldomZInvalidModificationErrr   Z_tokensupto2Z_tokenvalueZ_tempSeq_parseappendr   Z_setSeqr
   )r   r   r"   ZattokenZnewStyleokZbeforetokensbracenewZnewseqZbeforewellformedr    ZstyletokensZbraceorEOFtokenvaltype_Z	nonetokenr   r   r   r%   G   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)Z_checkReadonly
isinstancestrr   _styleZ_parentRule)r   r
   r   r   r   	_setStyle   s
   

zCSSFontFaceRule._setStylec                 C      | j S N)r4   r   r   r   r   <lambda>       zCSSFontFaceRule.<lambda>z[(DOM) The declaration-block of this rule set, a :class:`~cssutils.css.CSSStyleDeclaration`.c                 C   r6   r7   )ZFONT_FACE_RULEr   r   r   r   r8      r9   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
   Z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   r8      s    )NNNF)r   
__module____qualname____doc__r	   r   r   r   r%   propertyr   r5   r
   typerB   r   r   __classcell__r   r   r   r   r      s:    S)rE   __all__Zcssstyledeclarationr    r   r   Zxml.domr(   ZCSSRuler   r   r   r   r   <module>   s    