
    =hh"                         d Z dgZddlZddlZddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ  G d dej                  j                         Zy)	zMediaList implements DOM Level 2 Style Sheets MediaList.

TODO:
    - delete: maybe if deleting from all, replace *all* with all others?
    - is unknown media an exception?
	MediaList    N)	normalize	pushtoken)PreDefProd
ProdParserSequence   )
MediaQueryc                        e Zd ZdZd fd	Zd Zd Zd Z ed d      Z	d	 Z
d
 Z ee
ed      Zd Zd Zd Zd Zd Zd Z ed d      Z ed       Z xZS )r   a  Provides the abstraction of an ordered collection of media,
    without defining or constraining how this collection is
    implemented.

    A single media in the list is an instance of :class:`MediaQuery`.
    An empty list is the same as a list that contains the medium "all".

    New format with :class:`MediaQuery`::

        : S* [media_query [ ',' S* media_query ]* ]?


    c                     t         |           d| _        t        |t              rdj                  |      }|| _        |r|| _        || _        y)a   
        :param mediaText:
            Unicodestring of parsable comma separared media
            or a (Python) list of media.
        :param parentRule:
            CSSRule this medialist is used in, e.g. an @import or @media.
        :param readonly:
            Not used yet.
        F,N)	super__init___wellformed
isinstancelistjoin_parentRule	mediaText	_readonly)selfr   
parentRulereadonly	__class__s       ^/var/www/api/v1/venv_fitandmore/lib/python3.12/site-packages/cssutils/stylesheets/medialist.pyr   zMediaList.__init__#   sI     	 i&+I%&DN!    c                 P    d| j                   j                   d| j                  dS )Nzcssutils.stylesheets.z(mediaText=))r   __name__r   r   s    r   __repr__zMediaList.__repr__:   s(    &t~~'>'>&?{4>>J\\]^^r   c                 j    d| j                   j                   d| j                  dt        |       ddS )Nz<cssutils.stylesheets.z object mediaText=z at 0xx>)r   r    r   idr!   s    r   __str__zMediaList.__str__=   s>    '(?(?'@@RSWSaSaRddjkmnrkstujvvwxxr   c              #   V   K   | j                   D ]  }|j                  dk(  s|  y w)Nr   )_seqtype)r   items     r   __iter__zMediaList.__iter__@   s%     IIDyyL(
 s   ))c                 *    t        t        |             S N)lenr   r!   s    r   <lambda>zMediaList.<lambda>F   s    Sd_r   z/The number of media in the list (DOM readonly).)docc                 @    t         j                  j                  |       S r.   )cssutilsserdo_stylesheets_medialistr!   s    r   _getMediaTextzMediaList._getMediaTextJ   s    ||44T::r   c           	      <   | j                          d }t        t        t        j                  |       d        |       t        t        j                  d       |       d             }t               j                  |d|d	
      \  }}}}d}|D ]1  }	|	j                  }
t        |
t              s |
j                  sd} nd}3 |s>d}|| _        | j                  j                  dt        j                  j                          || _        |rg }t"        j$                  j'                  d      }t"        j$                  j'                  d      }|D ]  }	|	j(                  dk(  rI|	j                  j*                  }|rz|dk(  r|}|j-                  |	        ns||v rI|j-                  |       nIt        |	j                  t"        j.                  j0                  j2                        r|j-                  |	       |j-                  |	        | j5                  |       yy)at  
        :param mediaText:
            simple value or comma-separated list of media

        :exceptions:
            - - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified string value has a syntax error and is
              unparsable.
            - - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this media list is readonly.
        c                  "    t        dd d       S )NMediaQueryStartc                     | dk(  xs |dk(  S )NIDENT( )tvs     r   r0   z;MediaList._setMediaText.<locals>.<lambda>.<locals>.<lambda>]   s    qG|7qCx7r   c                 4    dt        t        | |      d      fS )Nr   T)_partof)r   r   )r>   tokenss     r   r0   z;MediaList._setMediaText.<locals>.<lambda>.<locals>.<lambda>^   s    9Q/>%r   )namematchtoSeq)r   r=   r   r   r0   z)MediaList._setMediaText.<locals>.<lambda>[   s    T"7
r   )parentc                       yN)r   Nr=   r=   r   r   r0   z)MediaList._setMediaText.<locals>.<lambda>d   s    r   )minmaxF)rE   c                       yrH   r=   r=   r   r   r0   z)MediaList._setMediaText.<locals>.<lambda>f   s    Yr   r   ml)debugTzMediaQuery: No content.error)r   r   allN)_checkReadonlyr	   r   commentcommar   parsevaluer   r   
wellformedr   _logrN   xmldom	SyntaxErrr3   utilSeqr*   	mediaTypeappendcss
csscomment
CSSComment_setSeq)r   r   
mediaqueryprodsokseqstoreunused
atleastoner+   r?   
mediaTypesfinalseqcommentseqonlyr\   s                  r   _setMediaTextzMediaList._setMediaTextM   s    	

 V^^409JKLV\\.
EVW
 ",!3!3{E "4 "
C
 
D

A!Z(||B!%J  B!DIIOO5SWW=N=NOOJ}}((%(8H%]]...>N99, $

 4 4I $-'5H$OOD1!&*4$&--i8

HLL,C,C,N,NO"))$/%# & LL"/ r   z6The parsable textual representation of the media list.c                 v    | j                          t        |t              st        |      }|j                  r|S y r.   )rP   r   r   rU   r   	newMediums     r   __preparesetzMediaList.__prepareset   s6    )Z0"9-I  r   c                 R    | j                  |      }|r|dddf| j                  |<   yy)z^Overwriting ListSeq.__setitem__

        Any duplicate items are **not yet** removed.
        r   N)_MediaList__preparesetr)   )r   indexro   s      r   __setitem__zMediaList.__setitem__   s3     %%i0	 )<tDDIIe r   c                 B   | j                  |      }|r| D cg c]!  }t        |j                  j                        # }}t        |j                        }d| j                  _        d|v r9| j                  j                  d|z  t        j                  j                         ne|r2||v r.| j                  |       | j                  j                  |d       n1d|k(  r| j                          | j                  j                  |d       d| j                  _        yyc c}w )a`  Add the `newMedium` to the end of the list.
        If the `newMedium` is already used, it is first removed.

        :param newMedium:
            a string or a :class:`~cssutils.stylesheets.MediaQuery`
        :returns: Wellformedness of `newMedium`.
        :exceptions:
            - :exc:`~xml.dom.InvalidCharacterErr`:
              If the medium contains characters that are invalid in the
              underlying style language.
            - :exc:`~xml.dom.InvalidModificationErr`:
              If mediaText is "all" and a new medium is tried to be added.
              Exception is "handheld" which is set in any case (Opera does handle
              "all, handheld" special, this special case might be removed in the
              future).
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this list is readonly.
        FrO   zYMediaList: Ignoring new medium %r as already specified "all" (set ``mediaText`` instead).rM   r   T)rr   r   rT   r\   r)   r   rV   inforW   rX   InvalidModificationErrdeleteMediumr]   	_clearSeq)r   ro   r+   mtsnewmts        r   appendMediumzMediaList.appendMedium   s    & %%i0	?CDtt9TZZ112tCDi112E"'DII|		9;DE''88   5C<!!%(		  L9 E>NN$		  L9"&DII 9 Es   &Dc                 &    | j                  |       y)zSame as :meth:`appendMedium`.N)r|   rn   s     r   r]   zMediaList.append   s    )$r   c                    | j                          t        |      }t        |       D ],  \  }}t        |j                  j                        |k(  s)| |=  y | j
                  j                  d|z  t        j                  j                         y)aO  Delete a medium from the list.

        :param oldMedium:
            delete this medium from the list.
        :exceptions:
            - :exc:`~xml.dom.NotFoundErr`:
              Raised if `oldMedium` is not in the list.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this list is readonly.
        z"%s" not in this MediaListrM   N)
rP   r   	enumeraterT   r\   rV   rN   rW   rX   NotFoundErr)r   	oldMediumimqs       r   rx   zMediaList.deleteMedium   sx     	i(	t_EAr++,	9G %
 IIOO,y8@S@S  r   c                 @    	 | |   j                   S # t        $ r Y yw xY w)zReturn the mediaType of the `index`'th element in the list.
        If `index` is greater than or equal to the number of media in the
        list, returns ``None``.
        N)r\   
IndexError)r   rs   s     r   r+   zMediaList.item  s)    
	;((( 		s    	c                     | j                   S r.   )r   r!   s    r   r0   zMediaList.<lambda>  s
    T%%r   zHThe CSSRule (e.g. an @media or @import rule this list is part of or Nonec                     | j                   S r.   )r   r!   s    r   r0   zMediaList.<lambda>  s
    t'7'7r   )NNF)r    
__module____qualname____doc__r   r"   r'   r,   propertylengthr6   rl   r   rr   rt   r|   r]   rx   r+   r   rU   __classcell__)r   s   @r   r   r      s    "._y
 $=F
;K#Z DIE2h%. %'J 78Jr   )r   __all__xml.domrW   r3   cssutils.helperr   r   cssutils.prodparserr   r   r   r	   rb   r   rZ   _NewListBaser   r=   r   r   <module>r      s=    -   0 B B "9** 9r   