o
    /h8                     @   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__
_atkeyword_styleSheethreftype_tempSeqappend_setSeqmediacssutilsstylesheets	MediaListr   r   	_readonly)selfr   r   r   r   r   readonlyseq	__class__ N/var/www/html/myenv/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   ser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   __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   Fr2   z!CSSImportRule: Unexpected string.)r4   r   _logr0   )expectedr   r5   	tokenizer)_CSSImportRule__donamer7   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   r:   Fr2   zCSSImportRule: Unexpected URI.)_uritokenvaluer   r;   r0   )r<   r   r5   r=   r@   r6   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)importmediaqueryendonlyr   r3   EOFFr2   CSSImportRule: No ";" found: %s)r5   )r   z$CSSImportRule: Invalid MediaList: %sz CSSImportRule: Unexpected ident.)
startswith_tokensupto2insertpop_tokenvalue_type_prodsSTRINGr;   r0   	_valuestrr   r   r   r   r2   r   )	r<   r   r5   r=   mediatokenslastlastvallasttypnewMediar>   cssTextr7   r   r   r   _ident   s>   

z)CSSImportRule._setCssText.<locals>._identc                    s:    |}| drd|krdS d d< jd| | S )Nr3   rD   Fr2   zCSSImportRule: Unexpected char.)rJ   endswithr;   r0   )r<   r   r5   r=   valr6   r   r   _char   s   
z(CSSImportRule._setCssText.<locals>._charr   )rM   URIIDENTCHAR)r<   r   r=   productionsr7   r2   Fz CSSImportRule: No href found: %srD   rE   r1   r   r   r   r	   r
   N)r   _setCssText
_tokenize2
_nexttokenrK   rL   
IMPORT_SYMr;   r0   rN   xmldomInvalidModificationErrrJ   r   _parser   	atkeywordr   r   r   r   r   r   r   )r   rU   r=   attokenr?   rB   rV   rY   newseqr2   r<   okr   rT   r   r_   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   	ownerRuletitleF/zCannot read Stylesheet.)NNr      )encodingOverrideencodingz@CSSImportRule: While processing imported style sheet href=%s: %rT)
neverraise)_href	enumerater   typelinecol_seqr   cssCSSStyleSheetr   r   	hrefFoundr   r   helperpath2urlosgetcwdurllibparseurljoin_resolveImportOSError_setFetcher_fetcher_setCssTextWithEncodingOverride
ValueErrorr;   warnr   )r   r   iitemtype_importedSheet
parentHreffullhrefusedEncodingenctyperU   rq   rr   er   r   r   _setHref  sV   



	
zCSSImportRule._setHrefc                 C      | j S r^   )rt   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   )_checkReadonly
isinstancestrr   r   r   _media_parentRuleru   r   rv   rH   )r   r   ihrefr   r   r   r   r   	_setMediaY  s    



zCSSImportRule._setMediac                 C   r   r^   )r   r*   r   r   r   r+   t  r   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)r   r   _nameru   r   rv   rw   rx   ry   
styleSheetrn   r;   r0   )r   r   r   r   typr   r   r   _setNamez  s   zCSSImportRule._setNamec                 C   r   r^   )r   r*   r   r   r   _getName  s   zCSSImportRule._getNamez(An optional name for the imported sheet.c                 C   r   r^   )r   r*   r   r   r   r+     r   z4(readonly) The style sheet referred to by this rule.c                 C   r   r^   )IMPORT_RULEr*   r   r   r   r+     r   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   r2   r*   r   r   r   _getWellformed  s   
zCSSImportRule._getWellformed)NNNNNF)r)   )r"   
__module____qualname____doc__r   r$   r(   propertyr!   r/   r_   rU   r   rt   r   r   r   r   r   r   r   rv   r   r2   __classcell__r   r   r   r   r      sj    / *A
)r   __all__r   urllib.parser   xml.domrc   r   r)   r   CSSRuler   r   r   r   r   <module>   s    