o
    j                     @   sZ   d Z dgZddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ G dd dejjZdS )zImplements a DOM for MediaQuery, see
http://www.w3.org/TR/css3-mediaqueries/.

A cssutils implementation, not defined in official DOM.

MediaQuery    N)	normalize)ChoicePreDefProd
ProdParserSequencec                       s~   e Zd ZdZg dZd fdd	Zdd Zd	d
 Zdd Zdd Z	e
ee	ddZdd Ze
dd eddZe
dd Z  ZS )r   a  
    A Media Query consists of one of ``MediaQuery.MEDIA_TYPES``
    and one or more expressions involving media features.

    Format::

        media_query
         : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
         | expression [ AND S* expression ]*
         ;
        media_type
         : IDENT
         ;
        expression
         : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
         ;
        media_feature
         : IDENT
         ;

    )
allZbrailleZhandheldprintZ
projectionZspeechscreenttytvZembossedNFc                    s6   t    d| _d| _|| _|r|| _d| _|| _dS )z
        :param mediaText:
            unicodestring of parsable media

        # _standalone: True if new from ML parser
        F N)super__init___wellformed
_mediaType_partof	mediaTextZ	_readonly)selfr   readonlyr   	__class__ `/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/cssutils/stylesheets/mediaquery.pyr   4   s   

zMediaQuery.__init__c                 C   s   d| j j d| jdS )Nzcssutils.stylesheets.z(mediaText=))r   __name__r   r   r   r   r   __repr__F      zMediaQuery.__repr__c                 C   s$   d| j j d| jdt| ddS )Nz<cssutils.stylesheets.z object mediaText=z at 0xx>)r   r   r   idr   r   r   r   __str__I   s   $zMediaQuery.__str__c                 C   s   t j| S N)cssutilsZserZdo_stylesheets_mediaqueryr   r   r   r   _getMediaTextL   s   zMediaQuery._getMediaTextc           	   
      s        fdd}tttddd dddtd fd	dddd
ttddd dd| dd dt| ttddd d| dd d}t |d|\}}}}| _|rvz|d }W n	 tyf   Y n	w d|vro|j _	 
| dS dS )a9  
        :param mediaText:
            a single media query string, e.g. ``print and (min-width: 25cm)``

        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified string value has a syntax error and is
              unparsable.
            - :exc:`~xml.dom.InvalidCharacterErr`:
              Raised if the given mediaType is unknown.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this media query is readonly.

        media_query
         : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
         | expression [ AND S* expression ]*
         ;
        media_type
         : IDENT
         ;
        expression
         : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
         ;
        media_feature
         : IDENT
         ;

        c                	      sT   t tjdddtddd dt tjdd	dtjj d
d dtjdd jdS )N
expression()namecharZmedia_featurec                 S   s   | t jjkS r$   )r   typesIDENTtvr   r   r   <lambda>p   s    z<MediaQuery._setMediaText.<locals>.<lambda>.<locals>.<lambda>r)   matchcolon:c                   S      dS )N)r      r   r   r   r   r   r0   t       Zminmaxzexpression ENDr   )r)   r*   stopIfNoMoreMatch)	r   r   r*   r   r%   cssvalueZMediaQueryValueProdr   r   r   r   r   r0   n   s    z*MediaQuery._setMediaText.<locals>.<lambda>zONLY|NOTc                 S   s   | t jjkot|dv S )Nonlynotr   r+   r,   r   r-   r   r   r   r0      r   Tz
not simple)r)   r2   optionaltoStore
media_typec                    s   | t jjkot| jv S r$   )r   r+   r,   r   MEDIA_TYPESr-   r   r   r   r0      s   )r)   r2   r9   rA   ANDc                 S      | t jjkot|dkS Nandr?   r-   r   r   r   r0      r   )r)   r2   rA   c                   S   r5   N)r   Nr   r   r   r   r   r0      r7   r8   c                 S   rE   rF   r?   r-   r   r   r   r0      r   r1   c                   S   r5   rH   r   r   r   r   r   r0      r7   r   N)_checkReadonlyr   r   r   r   parser   KeyErrorr;   	mediaTypeZ_setSeq)	r   r   r'   ZprodsokseqstoreZunusedrB   r   r   r   _setMediaTextO   sd   
.zMediaQuery._setMediaTextz6The parsable textual representation of the media list.)docc                 C   s   |    t|}|| jvr| jjd| tjjd dS || _t	| j
D ]\}}t|jtrAt|jdv r5q#|dddf| j
|<  dS q#| j
d|d dS )a  
        :param mediaType:
            one of :attr:`MEDIA_TYPES`

        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified string value has a syntax error and is
              unparsable.
            - :exc:`~xml.dom.InvalidCharacterErr`:
              Raised if the given mediaType is unknown.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this media query is readonly.
        z,MediaQuery: Syntax Error in media type "%s".)errorr<   r,   Nr   )rI   r   rC   _logrR   xmldomZ	SyntaxErrr   	enumerateZ_seq
isinstancer;   strinsert)r   rL   Z
nmediaTypeir    r   r   r   _setMediaType   s    

zMediaQuery._setMediaTypec                 C      | j S r$   )r   r   r   r   r   r0          zMediaQuery.<lambda>z`The media type of this MediaQuery (one of ``MEDIA_TYPES``) but only if it is a simple MediaType!c                 C   r\   r$   )r   r   r   r   r   r0      r]   )NFF)r   
__module____qualname____doc__rC   r   r   r#   r&   rP   propertyr   r[   rL   Z
wellformed__classcell__r   r   r   r   r      s(    h&)r`   __all__Zxml.domrT   r%   Zcssutils.helperr   Zcssutils.prodparserr   r   r   r   r   utilZ_NewBaser   r   r   r   r   <module>   s    