
     h~                     |    d Z dgZddlZddlZddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ  G d dej                        Zy)	z1MarginRule implements DOM Level 2 CSS MarginRule.
MarginRule    N)ChoicePreDefProd
ProdParserSequence   )cssrule)CSSStyleDeclarationc                        e Zd ZdZg dZ	 	 	 	 	 d fd	Zd Z ed ed      ZeZ	d Z
d	 Zd
 Z fdZ eeed      Zd Z ed ed      Z ed d      Z ed       Z xZS )r   a  
    A margin at-rule consists of an ATKEYWORD that identifies the margin box
    (e.g. '@top-left') and a block of declarations (said to be in the margin
    context).

    Format::

        margin :
               margin_sym S* '{' declaration [ ';' S* declaration? ]* '}' S*
               ;

        margin_sym :
               TOPLEFTCORNER_SYM |
               TOPLEFT_SYM |
               TOPCENTER_SYM |
               TOPRIGHT_SYM |
               TOPRIGHTCORNER_SYM |
               BOTTOMLEFTCORNER_SYM |
               BOTTOMLEFT_SYM |
               BOTTOMCENTER_SYM |
               BOTTOMRIGHT_SYM |
               BOTTOMRIGHTCORNER_SYM |
               LEFTTOP_SYM |
               LEFTMIDDLE_SYM |
               LEFTBOTTOM_SYM |
               RIGHTTOP_SYM |
               RIGHTMIDDLE_SYM |
               RIGHTBOTTOM_SYM
               ;

    e.g.::

        @top-left {
            content: "123";
            }
    )z@top-left-cornerz	@top-leftz@top-centerz
@top-rightz@top-right-cornerz@bottom-left-cornerz@bottom-leftz@bottom-centerz@bottom-rightz@bottom-right-cornerz	@left-topz@left-middlez@left-bottomz
@right-topz@right-middlez@right-bottomc                     t         |   ||       dx| _        | _        |r|| _        |r|| _        || _        yt        |       | _        || _        y)z
        :param atkeyword:
            The margin area, e.g. '@top-left' for this rule
        :param style:
            CSSStyleDeclaration for this MarginRule
        )
parentRuleparentStyleSheetNr   )super__init__
_atkeyword_keywordmarginstyler   	_readonly)selfr   r   r   r   readonly	__class__s         W/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/cssutils/css/marginrule.pyr   zMarginRule.__init__G   sX     	JAQR*..$- DKDJ " -=DJ!    c                     | j                  |      }|t        j                  vrF| j                  j	                  d| j
                   d|t        j                  j                         y|| _	        || _
        y)z2Check if new keyword fits the rule it is used for.z!Invalid margin @keyword for this z rule: errorN)
_normalizer   margins_logr   r   xmldomInvalidModificationErrr   r   )r   r   ns      r   
_setMarginzMarginRule._setMarginc   sd    OOF#J&&&IIOO3DKK=zRgg44    DO"DMr   c                     | j                   S N)r   r   s    r   <lambda>zMarginRule.<lambda>r   s    T__r   zfMargin area of parent CSSPageRule. `margin` and `atkeyword` are both normalized @keyword of the @rule.)docc                 ~    d| j                   j                   d| j                  d| j                  j                  dS )Nzcssutils.css.z(margin=z, style=))r   __name__r   r   cssTextr*   s    r   __repr__zMarginRule.__repr__{   s;    t~~667xhW[WaWaWiWiVllmnnr   c                     d| j                   j                  | j                  | j                  j                  t        |       fz  S )Nz3<cssutils.css.%s object margin=%r style=%r at 0x%x>)r   r/   r   r   r0   idr*   s    r   __str__zMarginRule.__str__~   s=    GNN##KKJJtH	K
 
 	
r   c                 @    t         j                  j                  |       S )z#Return serialized property cssText.)cssutilsserdo_MarginRuler*   s    r   _getCssTextzMarginRule._getCssText   s    ||))$//r   c                     t            |       t        dd dd      }t        t        d fdd      t	        j
                  d	d
      t        t        t	        j                  d      |      d       t	        j
                  ddd            }t               j                  |d|      \  }}}}|r j                  |       d|v r|d   j                   _        nB j                  j                  d j                  z  t        j                   j"                         t%                _        d|v r|d    j&                  _        yyy)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.
        styletokensc                     |dk7  S )N} )tvs     r   r+   z(MarginRule._setCssText.<locals>.<lambda>   s    qCxr   T)namematchtoStore
storeTokenz@ marginc                 T    | dk(  xr! j                  |      t        j                  v S )N	ATKEYWORD)r    r   r!   )r?   r@   r   s     r   r+   z(MarginRule._setCssText.<locals>.<lambda>   s+    1#3 $=OOA&**<*<<$=r   r   )rA   rB   rC   OPEN{@)rC   c                       y)N)r   Nr>   r>   r   r   r+   z(MarginRule._setCssText.<locals>.<lambda>   s    yr   )minmaxCLOSEr=   )stopAndKeepr   z#No margin @keyword for this %s ruler   r   N)r   _setCssTextr   r   r   charr   unknownruler   parse_setSeqvaluer   r"   r   r#   r$   r%   r   r   r0   )	r   r0   r;   prodsokseqstoreunusedr   s	   `       r   rN   zMarginRule._setCssText   s3    	G$ '!
 = 	 KK$v))#6D( KK$7
" ",!3!3G\5!QCLL5 #Ho33		9DKKG''88    -=DJ%%*=%9

" &! r   z*(DOM) The parsable textual representation.)fgetfsetr,   c                     | j                          t        |t              rt        ||       | _        y| |_        || _        y)zt
        :param style: A string or CSSStyleDeclaration which replaces the
            current style object.
        )r0   r   N)_checkReadonly
isinstancestrr   _style_parentRule)r   r   s     r   	_setStylezMarginRule._setStyle   s7    
 	eS!-eMDK $EDKr   c                     | j                   S r)   )r_   r*   s    r   r+   zMarginRule.<lambda>   s    T[[r   z-(DOM) The declaration-block of this rule set.c                     | j                   S r)   )MARGIN_RULEr*   s    r   r+   zMarginRule.<lambda>   s
    T%%r   z=The type of this rule, as defined by a CSSRule type constant.c                 ,    t        | j                        S r)   )bool	atkeywordr*   s    r   r+   zMarginRule.<lambda>   s    tDNN';r   )NNNNF)r/   
__module____qualname____doc__r!   r   r'   propertyr   rg   r1   r4   r9   rN   r0   ra   r   type
wellformed__classcell__)r   s   @r   r   r      s    #JG* "8# $!F Io
0@:D 8G
   ;E %ND
 ;<Jr   )rj   __all__xml.domr#   r6   cssutils.prodparserr   r   r   r   r    r
   cssstyledeclarationr   CSSRuler   r>   r   r   <module>ru      s3    7.   J J  4[= [=r   