o
    /h+                     @   s<   d Z dgZddlZddlZddlmZ G dd dejZdS )zMCSSNamespaceRule currently implements http://dev.w3.org/csswg/css3-namespace/CSSNamespaceRule    N   )cssrulec                       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dd Zd ddZe	dd eddZe	dd ddZe	dd Z  ZS )!r   a  
    Represents an @namespace rule within a CSS style sheet.

    The @namespace at-rule declares a namespace prefix and associates
    it with a given namespace (a string). This namespace prefix can then be
    used in namespace-qualified names such as those described in the
    Selectors Module [SELECT] or the Values and Units module [CSS3VAL].

    Dealing with these rules directly is not needed anymore, easier is
    the use of :attr:`cssutils.css.CSSStyleSheet.namespaces`.

    Format::

        namespace
          : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
          ;
        namespace_prefix
          : IDENT
          ;
    NFc                    s   t  j||d d| _d| _d| _|r1|| _|| _|  }|| jd || jd | 	| n|dur8|| _
|r=|| _|| _dS )a  
        :Parameters:
            namespaceURI
                The namespace URI (a simple string!) which is bound to the
                given prefix. If no prefix is set
                (``CSSNamespaceRule.prefix==''``) the namespace defined by
                namespaceURI is set as the default namespace
            prefix
                The prefix used in the stylesheet for the given
                ``CSSNamespaceRule.uri``.
            cssText
                if no namespaceURI is given cssText must be given to set
                a namespaceURI as this is readonly later on
            parentStyleSheet
                sheet where this rule belongs to

        Do not use as positional but as keyword parameters only!

        If readonly allows setting of properties in constructor only

        format namespace::

            namespace
              : NAMESPACE_SYM S* [namespace_prefix S*]? [STRING|URI] S* ';' S*
              ;
            namespace_prefix
              : IDENT
              ;
        )
parentRuleparentStyleSheetz
@namespace NprefixnamespaceURI)super__init__
_atkeyword_prefix_namespaceURIr	   r   _tempSeqappend_setSeqcssText_parentStyleSheet	_readonly)selfr	   r   r   r   r   readonlytempseq	__class__ Q/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssnamespacerule.pyr   "   s    &
zCSSNamespaceRule.__init__c                 C   s    d| j j d| jd| jdS )Nzcssutils.css.z(namespaceURI=z	, prefix=))r   __name__r	   r   r   r   r   r   __repr__]   s    zCSSNamespaceRule.__repr__c              	   C   s,   d| j j d| jd| jdt| dd	S )Nz<cssutils.css.z object namespaceURI=z prefix=z at 0xx>)r   r   r	   r   idr   r   r   r   __str__`   s   ,zCSSNamespaceRule.__str__c                 C   s   t j| S )z"Return serialized property cssText)cssutilsserdo_CSSNamespaceRuler   r   r   r   _getCssTextc   s   zCSSNamespaceRule._getCssTextc              	      s\  t  | |}|d}|jjkr+jjd	| t
jjd dS |dddd d fdd	}d fd	d
	}d fdd	}d fdd	} }jd||||||d d\}	}
|	oo d }	 d du rd}	jd	|  |
dkrd}	jd	|  |	r d _ d _ d _| dS dS )a  
        :param cssText: initial value for this rules cssText which is parsed
        :exceptions:
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
        Nz/CSSNamespaceRule: No CSSNamespaceRule found: %serrorr   T)keywordr   uri
wellformedc                    sD   d| kr | d< | d d dS d d< jd| | S )Nprefix or urir   r+   Fr,   z#CSSNamespaceRule: Unexpected ident.)_tokenvaluer   _logr)   expectedseqtoken	tokenizernewr   r   r   _ident   s   z,CSSNamespaceRule._setCssText.<locals>._identc                    sF   |  dr| d< | d d dS d d< jd| | S )Nr+   r	   ;Fr,   z$CSSNamespaceRule: Unexpected string.)endswith_stringtokenvaluer   r/   r)   r0   r5   r   r   _string   s   
z-CSSNamespaceRule._setCssText.<locals>._stringc                    sJ   |  dr|}| d< | d d dS d d< jd| | S )Nr+   r	   r8   Fr,   z!CSSNamespaceRule: Unexpected URI.)r9   _uritokenvaluer   r/   r)   )r1   r2   r3   r4   r+   r5   r   r   _uri   s   

z*CSSNamespaceRule._setCssText.<locals>._uric                    s8    |}d| krd|krdS d d< jd| | S )Nr8   EOFFr,   z"CSSNamespaceRule: Unexpected char.)r.   r/   r)   )r1   r2   r3   r4   valr5   r   r   _char   s   
z+CSSNamespaceRule._setCssText.<locals>._charr-   )IDENTSTRINGURICHAR)r1   r2   r4   productionsr6   r,   r+   Fz,CSSNamespaceRule: No namespace URI found: %sr>   z"CSSNamespaceRule: No ";" found: %sr*   r   N)r
   _setCssText
_tokenize2
_nexttoken_type_prodsNAMESPACE_SYMr/   r)   	_valuestrxmldomInvalidModificationErrr.   r   _parse	atkeywordr   r	   r   )r   r   r4   attokenr7   r;   r=   r@   newseqr,   r1   r   r5   r   rG   g   sd   





zCSSNamespaceRule._setCssTextz7(DOM) The parsable textual representation of this rule.)fgetfsetdocc                 C   s\   |    | js|| _|  }||d | | dS | j|kr,| jjdtjj	d dS dS )a  
        :param namespaceURI: the initial value for this rules namespaceURI
        :exceptions:
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              (CSSRule) Raised if this rule is readonly or a namespaceURI is
              already set in this rule.
        r	   z+CSSNamespaceRule: namespaceURI is readonly.r(   N)
_checkReadonlyr   r   r   r   r/   r)   rN   rO   NoModificationAllowedErr)r   r	   r   r   r   r   _setNamespaceURI   s   

z!CSSNamespaceRule._setNamespaceURIc                 C      | j S rF   )r   r   r   r   r   <lambda>       zCSSNamespaceRule.<lambda>z8URI (handled as simple string) of the defined namespace.)rW   c                 C   sN   || _ t| jD ]\}}d|jkr$d| j_| j||d d| j_ dS qdS )zuUsed during parse of new sheet only!

        :param namespaceURI: the new value for this rules namespaceURI
        r	   FTN)r   	enumerate_seqtyper   replace)r   r	   ir    r   r   r   _replaceNamespaceURI   s   
z%CSSNamespaceRule._replaceNamespaceURIc                 C   s   |    |s	d}n,| |}| |d}|r| || jjkr0| jjd| | t	j
jd dS | |}t| jD ]\}}|| jkrN|dddf| j|<  n
q:|dddf| jd< || _dS )a?  
        :param prefix: the new prefix
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this rule is readonly.
        r   Nz'CSSNamespaceRule: No valid prefix "%s".r(   r   r   )rX   rH   rI   rJ   rK   rA   r/   r)   rM   rN   rO   	SyntaxErrr.   r^   r_   r   )r   r   r4   prefixtokenrb   r    r   r   r   
_setPrefix  s&   




zCSSNamespaceRule._setPrefixc                 C   r[   rF   )r   r   r   r   r   r\   0  r]   z&Prefix used for the defined namespace.c                 C   r[   rF   )NAMESPACE_RULEr   r   r   r   r\   6  r]   z=The type of this rule, as defined by a CSSRule type constant.c                 C   s
   | j d uS rF   )r	   r   r   r   r   r\   :  s   
 )NNNNNFrF   )r   
__module____qualname____doc__r   r   r#   r'   rG   propertyr   rZ   r	   rc   rf   r   r`   r,   __classcell__r   r   r   r   r      sH    ;v
$)	rj   __all__xml.domrN   r$   r   r   CSSRuler   r   r   r   r   <module>   s    