o
    j.                     @   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 )z5CSSMediaRule implements DOM Level 2 CSS CSSMediaRule.CSSMediaRule    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
e	dd Zejdd Zdd Zdd Ze	dd eddZd!ddZe	dd ddZe	dd Z  ZS )"r   a  
    Objects implementing the CSSMediaRule interface can be identified by the
    MEDIA_RULE constant. On these objects the type attribute must return the
    value of that constant.

    Format::

      : MEDIA_SYM S* medium [ COMMA S* medium ]*

          STRING? # the name

      LBRACE S* ruleset* '}' S*;

    ``cssRules``
        All Rules in this media rule, a :class:`~cssutils.css.CSSRuleList`.
    allNFc                    s>   t  j||d d| _|r|| _ntj | _|| _|| _dS )constructor
parentRuleparentStyleSheet@mediaN)	super__init__Z
_atkeywordmediacssutilsstylesheets	MediaListnameZ	_readonly)self	mediaTextr   r   r	   readonly	__class__ Z/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/cssutils/css/cssmediarule.pyr      s   	
zCSSMediaRule.__init__c                 C   s   d| j j d| jjdS )Nzcssutils.css.z(mediaText=))r   __name__r   r   r   r   r   r   __repr__3   s   zCSSMediaRule.__repr__c                 C   s&   d| j j d| jjdt| ddS )Nz<cssutils.css.z object mediaText=z at 0xx>)r   r   r   r   idr   r   r   r   __str__6   s   &zCSSMediaRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)r   ZserZdo_CSSMediaRuler   r   r   r   _getCssText9   s   zCSSMediaRule._getCssTextc                    s  t  |  |\}} |} |d} | jjkr2 jj	d 
| tjjd dS  j} j}d} j|ddd\}}	d |	ksT jj |	krgtjj d _| j_|oe jj}nd}d}
  } jj |	kr |	}
 j|ddd	\}}	 d||i \}}|sd} j	d
 
|  d |	kr j	d 
|  dS  j|ddd\}} |d}d |kr|| d} jjd|dd d |kr jj	d|d nL|r jj	d|d nAddi}d fdd	} fdd} fdd} j}tj   _g }t!|} j|||||||||||d||d\}}|o6|}|rD|
 _" #| dS | _| _dS )aP  
        :param cssText:
            a parseable string or a tuple of (cssText, dict-of-namespaces)
        :Exceptions:
            - :exc:`~xml.dom.NamespaceErr`:
              Raised if a specified selector uses an unknown namespace
              prefix.
            - :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'CSSMediaRule: No CSSMediaRule found: %serrorT)ZmediaqueryendonlyseparateEnd{)r   F)Zblockstartonlyr$   zCSSMediaRule: Syntax Error: %szCSSMediaRule: No "{" found: %s)Zmediaendonlyr$   ZEOF)ZCHAR}r   r   z%CSSMediaRule: Incomplete, adding "}".)tokenZ
neverraiser&   zCSSMediaRule: No "}" found.)r'   z%CSSMediaRule: Trailing content found.
wellformedc                    s      tjj|g  jd | S Nr   )
insertRuler   cssZ
CSSCommentr	   )expectedseqr'   	tokenizerr   r   r   COMMENT   s   z)CSSMediaRule._setCssText.<locals>.COMMENTc                    s4   t jj  jd} |||_|jr | | S r)   )r   r+   ZCSSStyleRuler	   _tokensupto2cssTextr(   r*   )r,   r-   r'   r.   ruler   r   r   ruleset   s   
z)CSSMediaRule._setCssText.<locals>.rulesetc                    s     ||} |}tjjttjjd}|dv r+ jjd 	| |t
jjd | S ||v rE||   jd}||_|jrC | | S tjj|  jd}|jrW | | S )N)z@pager
   z
@font-face)z	@charset z@importz
@namespacez
@variableszECSSMediaRule: This rule is not allowed in CSSMediaRule - ignored: %s.)r'   r#   r   )r0   _tokenvaluer   r+   ZCSSPageRuler   ZCSSFontFaceRule_logr#   	_valuestrxmldomHierarchyRequestErrr	   r1   r(   r*   ZCSSUnknownRule)r,   r-   r'   r.   tokensZatvalZ	factoriesr2   r   r   r   atrule   s>   

	
z(CSSMediaRule._setCssText.<locals>.atrule)r/   ZCHARSET_SYMZFONT_FACE_SYMZ
IMPORT_SYMZNAMESPACE_SYMZPAGE_SYM	MEDIA_SYMZ	ATKEYWORD)defaultnewN)$r   _setCssTextZ_splitNamespacesOffZ
_tokenize2Z
_nexttoken_typeZ_prodsr<   r5   r#   r6   r7   r8   ZInvalidModificationErr_mediaZ	_cssRulesr0   r4   STRINGr   r   r   r   r   r(   Z_tempSeqZ_stringtokenvalue_parseappenddebugZcssRulesr+   ZCSSRuleListiterr   Z_setSeq)r   r1   
namespacesr.   ZattokenZoldMediaZoldCssRulesokZmediatokensendr   ZnameseqZ
nametokensr(   r,   ZcssrulestokensZ
braceOrEOFZ	nonetokenr>   r/   r3   r;   r-   r   r   r   r@   =   s   


 




	(



zCSSMediaRule._setCssTextz7(DOM) The parsable textual representation of this rule.)docc                 C      | j S )z%An optional name for this media rule.)_namer   r   r   r   r     s   zCSSMediaRule.namec                 C   s8   t |ts	|d u r|sd }|| _d S | jd|  d S )Nz#CSSImportRule: Not a valid name: %s)
isinstancestrrM   r5   r#   r   r   r   r   r   r   	  s
   
c                 C   s
   || _ d S r?   )r   rP   r   r   r   _setName  s   
zCSSMediaRule._setNamec                 C   s8   |    t|trtjj|| d| _dS | |_|| _dS )z`
        :param media:
            a :class:`~cssutils.stylesheets.MediaList` or string
        )r   r   N)Z_checkReadonlyrN   rO   r   r   r   rB   Z_parentRule)r   r   r   r   r   	_setMedia  s   

zCSSMediaRule._setMediac                 C   rL   r?   )rB   r   r   r   r   <lambda>2      zCSSMediaRule.<lambda>z[(DOM) A list of media types for this rule of type :class:`~cssutils.stylesheets.MediaList`.c                 C   s   |  ||\}}|du s|du rdS t|tjjs.t|tjjs.t|tjjs.t|tjjrA| jj	d| j
j|jf tjjd dS | ||S )zImplements base ``insertRule``.FTNz-%s: This type of rule is not allowed here: %sr"   )Z_prepareInsertRulerN   r   r+   ZCSSCharsetRuleZCSSImportRuleZCSSNamespaceRuleZ
MarginRuler5   r#   r   r   r1   r7   r8   r9   Z_finishInsertRule)r   r2   indexr   r   r   r*   8  s&   zCSSMediaRule.insertRulec                 C   rL   r?   )Z
MEDIA_RULEr   r   r   r   rS   Q  rT   z=The type of this rule, as defined by a CSSRule type constant.c                 C   s   | j jS r?   )r   r(   r   r   r   r   rS   U  s    )r   NNNFr?   )r   
__module____qualname____doc__r   r   r    r!   r@   propertyr1   r   setterrQ   rR   r   r*   typer(   __classcell__r   r   r   r   r      sF     B



)	rX   __all__Zxml.domr7   r    r   ZCSSRuleRulesr   r   r   r   r   <module>   s    