o
    j8                     @   sL   d Z dgZddlZddlZddlZddlZddlm	Z	 G dd de	j
ZdS )zCSSImportRule implements DOM Level 2 CSS CSSImportRule plus the
``name`` property from http://www.w3.org/TR/css3-cascade/#cascading.CSSImportRule    N   )cssrulec                       s   e Zd ZdZ						d( fdd	Zdd Zdd	 Zed
d ddZdd Z	 fddZ
ee	e
ddZdd ZdZedd eddZdd Zedd eddZd)ddZdd  Zeeed!dZed"d d#dZed$d d%dZd&d' ZeeZ  ZS )*r   a  
    Represents an @import rule within a CSS style sheet.  The @import rule
    is used to import style rules from other style sheets.

    Format::

        import
          : IMPORT_SYM S*
          [STRING|URI] S* [ medium [ COMMA S* medium]* ]? S* STRING? S* ';' S*
          ;
    NFc                    s~   t  j||d d| _d| _d| _|  }|dd |dd | | |r,|| _nt	j
jdd| _|| _|| _|| _dS )a`  
        If readonly allows setting of properties in constructor only

        :param href:
            location of the style sheet to be imported.
        :param mediaText:
            A list of media types for which this style sheet may be used
            as a string
        :param name:
            Additional name of imported style sheet
        )
parentRuleparentStyleSheetz@importNhrefnameall	mediaText)super__init__Z
_atkeyword_styleSheethreftype_tempSeqappend_setSeqmediacssutilsstylesheets	MediaListr   r   Z	_readonly)selfr   r   r   r   r   readonlyseq	__class__ [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/cssutils/css/cssimportrule.pyr      s   

zCSSImportRule.__init__c              	   C   s:   | j r| jj}nd }d| jj d| jd|d| jd	S )Nzcssutils.css.z(href=z, mediaText=z, name=))	_usemediar   r   r   __name__r   r   r   r   r   r   r   __repr__K   s   
&zCSSImportRule.__repr__c                 C   sF   | j r| jj}nd }d| jj d| jd|d| jdt| ddS )Nz<cssutils.css.z object href=z mediaText=z name=z at 0xx>)r   r   r   r   r    r   r   idr!   r   r   r   __str__R   s   
2zCSSImportRule.__str__c                 C   s   | j jdvS )N) r	   )r   r   r   r   r   r   <lambda>Z   s    zCSSImportRule.<lambda>z'if self.media is used (or simply empty))docc                 C   s   t j| S )z#Return serialized property cssText.)r   ZserZdo_CSSImportRuler(   r   r   r   _getCssText^   s   zCSSImportRule._getCssTextc              	      s  t   }|d}|jjkr+jjd	 t
jjd dS |ddddddfdd d fdd		}dfd
d	}d fdd	}dfdd	} }jd||||||dd\}	}
|	o{d }d sd}jd	  |
dkrd}jd	  |r͈| d _d _d _d rd _ntjjdd_d _dS dS )ad  
        :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)CSSImportRule: No CSSImportRule found: %s)errorT)keywordr   r   r   r   
wellformedc                    s"    | d< |  d d dS )Nr   ;)_stringtokenvaluer   )r   tokennewr   r   r   Z__doname   s   z+CSSImportRule._setCssText.<locals>.__donamec                    s^   d| kr |d< dd< |d d dS d| v r" ||S dd< jd| | S )	Nr   stringr   media name ;r   Fr.   z!CSSImportRule: Unexpected string.)r0   r   _logr,   )expectedr   r1   	tokenizer)_CSSImportRule__donamer3   r   r   r   _string   s   
z*CSSImportRule._setCssText.<locals>._stringc                    sP   d| kr |}d d< | d< | d d dS d d< jd| | S )Nr   urir   r5   Fr.   zCSSImportRule: Unexpected URI.)Z_uritokenvaluer   r6   r,   )r7   r   r1   r8   r;   r2   r   r   _uri   s   
z'CSSImportRule._setCssText.<locals>._uric           	         s  |  drtj|dd}|d| | }||}}|dkr>|djjfvr>dd< jj	d	
 |d
 tjjd}||_|jrV|d< ||d ndd< jj	d
 |d
 |jjkrr ||S dS dd< j	d| | S )Nr   T)Zimportmediaqueryendonlyr   r/   EOFFr.   CSSImportRule: No ";" found: %s)r1   )r   z$CSSImportRule: Invalid MediaList: %sz CSSImportRule: Unexpected ident.)
startswithZ_tokensupto2insertpop_tokenvalue_type_prodsSTRINGr6   r,   	_valuestrr   r   r   r   r.   r   )	r7   r   r1   r8   ZmediatokenslastZlastvalZlasttypZnewMediar9   cssTextr3   r   r   r   _ident   s>   

z)CSSImportRule._setCssText.<locals>._identc                    s:    |}| drd|krdS d d< jd| | S )Nr/   r=   Fr.   zCSSImportRule: Unexpected char.)rB   endswithr6   r,   )r7   r   r1   r8   valr2   r   r   _char   s   
z(CSSImportRule._setCssText.<locals>._charr   )rE   URIZIDENTZCHAR)r7   r   r8   Zproductionsr3   r.   Fz CSSImportRule: No href found: %sr=   r>   r-   r   r   r   r	   r
   N)r   _setCssTextZ
_tokenize2Z
_nexttokenrC   rD   Z
IMPORT_SYMr6   r,   rF   xmldomZInvalidModificationErrrB   r   _parser   Z	atkeywordr   r   r   r   r   r   r   )r   rI   r8   Zattokenr:   r<   rJ   rM   Znewseqr.   r7   okr   rH   r   rP   b   sj   

	(




zCSSImportRule._setCssTextz7(DOM) The parsable textual representation of this rule.)fgetfsetr*   c              
   C   sl  || _ t| jD ]\}}|j}d|kr |||j|jf| j|<  nqtjj	| j
| | jd}d| _|r| jr| jj}|d u rFtjt d }tj|| j}z>| j|\}}	}
|
d u r`tdd\}}|	dkrk|}nd|	  k rudk ryn n|}||_ || jj |j|
||d	 W n! ttfy } z| jjd
| j|f dd W Y d }~nd }~ww d| _|| _d S )Nr   )r   Z	ownerRuletitleF/zCannot read Stylesheet.)NNr      )encodingOverrideencodingz@CSSImportRule: While processing imported style sheet href=%s: %rT)Z
neverraise)_href	enumerater   typelinecol_seqr   cssZCSSStyleSheetr   r   Z	hrefFoundr   r   helperZpath2urlosgetcwdurllibparseurljoinZ_resolveImportOSErrorZ_setFetcherZ_fetcherZ_setCssTextWithEncodingOverride
ValueErrorr6   warnr   )r   r   iitemtype_ZimportedSheetZ
parentHrefZfullhrefZusedEncodingZenctyperI   rZ   r[   er   r   r   _setHref  sV   



	
zCSSImportRule._setHrefc                 C      | j S rO   )r\   r(   r   r   r   r)   T      z+Location of the style sheet to be imported.c                 C   s   |    t|trtjj|| d| _n| |_|| _d}t| j	D ]\}}|j
dkr,|}q |j
dkr>| jdddf| j	|<  dS q | j	|d | jddd dS )z`
        :param media:
            a :class:`~cssutils.stylesheets.MediaList` or string
        )r   r   r   r   r   Nr   )Z_checkReadonly
isinstancestrr   r   r   _mediaZ_parentRuler]   r   r^   r@   )r   r   Zihrefrl   rm   r   r   r   	_setMediaY  s    



zCSSImportRule._setMediac                 C   rq   rO   )ru   r(   r   r   r   r)   t  rr   z[(DOM) A list of media types for this rule of type :class:`~cssutils.stylesheets.MediaList`.r'   c                 C   s   |du s	t |tr9|sd}|| _t| jD ]\}}|j}d|kr-|||j|jf| j|<  nq| j	r7|| j	_
dS dS | jd|  dS )z1Raises xml.dom.SyntaxErr if name is not a string.Nr   z#CSSImportRule: Not a valid name: %s)rs   rt   _namer]   r   r^   r_   r`   ra   
styleSheetrW   r6   r,   )r   r   rl   rm   typr   r   r   _setNamez  s   zCSSImportRule._setNamec                 C   rq   rO   )rw   r(   r   r   r   _getName  s   zCSSImportRule._getNamez(An optional name for the imported sheet.c                 C   rq   rO   )r   r(   r   r   r   r)     rr   z4(readonly) The style sheet referred to by this rule.c                 C   rq   rO   )ZIMPORT_RULEr(   r   r   r   r)     rr   z=The type of this rule, as defined by a CSSRule type constant.c                 C   s"   | j rt| jo
| jjS t| jS )z%Depending on if media is used at all.)r   boolr   r   r.   r(   r   r   r   _getWellformed  s   
zCSSImportRule._getWellformed)NNNNNF)r'   )r    
__module____qualname____doc__r   r"   r&   propertyr   r+   rP   rI   rp   r\   r   rv   r   rz   r{   r   rx   r^   r}   r.   __classcell__r   r   r   r   r      sj    / *A
)r   __all__rd   urllib.parserf   Zxml.domrQ   r   r'   r   ZCSSRuler   r   r   r   r   <module>   s    