
    ]hc"                         d Z ddlmZmZmZmZ dgZdZdZddl	m
Z
 ddlZddlZddlZdd	lmZ dd
lmZ ej"                  dk  reZ G d de      Zy)zA validating CSSParser    )unicode_literalsdivisionabsolute_importprint_function	CSSParserrestructuredtextz$Id$   )path2urlN)	tokenize2)css)      c                   \    e Zd ZdZ	 	 	 d
dZd ZddZ	 	 	 ddZ	 	 	 ddZ	 	 ddZ	dd	Z
y)r   a  Parse a CSS StyleSheet from URL, string or file and return a DOM Level 2
    CSS StyleSheet object.

    Usage::

        parser = CSSParser()
        # optionally
        parser.setFetcher(fetcher)
        sheet = parser.parseFile('test1.css', 'ascii')
        print sheet.cssText
    Nc                 N   |t         j                  j                  |       |t         j                  j                  |       t         j                  j                  | _        |r|| _        nd| _        t        j                  |      | _	        | j                  |       || _        y)ae  
        :param log:
            logging object
        :param loglevel:
            logging loglevel
        :param raiseExceptions:
            if log should simply log (default) or raise errors during
            parsing. Later while working with the resulting sheets
            the setting used in css_parser.log.raiseExeptions is used
        :param fetcher:
            see ``setFetcher(fetcher)``
        :param parseComments:
            if comments should be added to CSS DOM or simply omitted
        :param validate:
            if parsing should validate, may be overwritten in parse methods
        NF)
doComments)
css_parserlogsetLogsetLevelraiseExceptions_CSSParser__globalRaising_CSSParser__parseRaisingr   	Tokenizer_CSSParser__tokenizer
setFetcher	_validate)selfr   loglevelr   fetcherparseCommentsvalidates          ~/home/pod-website-builder.sw7ft.com/pod-website-builder/website-analyzer/venv/lib/python3.12/site-packages/css_parser/parse.py__init__zCSSParser.__init__#   s    & ?NN!!#&NN##H-  *~~=="1D #(D$..-H !    c                     |r | j                   t        j                  _        y| j                  t        j                  _        y)zsduring parse exceptions may be handled differently depending on
        init parameter ``raiseExceptions``
        N)r   r   r   r   r   )r   parses     r"   __parseSettingzCSSParser.__parseSettingH   s+     -1-@-@JNN*-1-A-AJNN*r$   c                     | j                  d       t        |t              r|j                  |      }|| j                  }t        j                  ||      }| j                  d       |S )a  Parse given `cssText` which is assumed to be the content of
        a HTML style attribute.

        :param cssText:
            CSS string to parse
        :param encoding:
            It will be used to decode `cssText` if given as a (byte)
            string.
        :param validate:
            If given defines if validation is used. Uses CSSParser settings as
            fallback
        :returns:
            :class:`~css_parser.css.CSSStyleDeclaration`
        T)
validatingF)_CSSParser__parseSetting
isinstancebytesdecoder   r   CSSStyleDeclaration)r   cssTextencodingr!   styles        r"   
parseStylezCSSParser.parseStyleQ   s^     	D!gu%nnX.G~~H''HEE"r$   c                    | j                  d       t        |t              r  t        j                  d      ||      d   }|| j
                  }t        j                  j                  |t        j                  j                  |      ||      }|j                  | j                         |j                  | j                  j                  |d      |       | j                  d       |S )	ab  Parse `cssText` as :class:`~css_parser.css.CSSStyleSheet`.
        Errors may be raised (e.g. UnicodeDecodeError).

        :param cssText:
            CSS string to parse
        :param encoding:
            If ``None`` the encoding will be read from BOM or an @charset
            rule or defaults to UTF-8.
            If given overrides any found encoding including the ones for
            imported sheets.
            It also will be used to decode `cssText` if given as a (byte)
            string.
        :param href:
            The ``href`` attribute to assign to the parsed style sheet.
            Used to resolve other urls in the parsed sheet like @import hrefs.
        :param media:
            The ``media`` attribute to assign to the parsed style sheet
            (may be a MediaList, list or a string).
        :param title:
            The ``title`` attribute to assign to the parsed style sheet.
        :param validate:
            If given defines if validation is used. Uses CSSParser settings as
            fallback
        :returns:
            :class:`~css_parser.css.CSSStyleSheet`.
        Tr   )r0   r   )hrefmediatitler)   )	fullsheet)encodingOverrideF)r*   r+   r,   codecs
getdecoderr   r   r   CSSStyleSheetstylesheets	MediaList_setFetcher_CSSParser__fetcher_setCssTextWithEncodingOverrider   tokenize)r   r/   r0   r4   r5   r6   r!   sheets           r"   parseStringzCSSParser.parseStringj   s    : 	D!gu%.f''.wJ1MG~~H,, ,,66u=#	 - %
 	$..)--d.>.>.G.GRV /H /X?G 	. 	I 	E"r$   c                     |st        |      }t        |d      }|j                         }|j                          | j	                  ||||||      S )a  Retrieve content from `filename` and parse it. Errors may be raised
        (e.g. IOError).

        :param filename:
            of the CSS file to parse, if no `href` is given filename is
            converted to a (file:) URL and set as ``href`` of resulting
            stylesheet.
            If `href` is given it is set as ``sheet.href``. Either way
            ``sheet.href`` is used to resolve e.g. stylesheet imports via
            @import rules.
        :param encoding:
            Value ``None`` defaults to encoding detection via BOM or an
            @charset rule.
            Other values override detected encoding for the sheet at
            `filename` including any imported sheets.
        :returns:
            :class:`~css_parser.css.CSSStyleSheet`.
        rbr0   r4   r5   r6   r!   )r
   openreadcloserC   )	r   filenamer0   r4   r5   r6   r!   fr   s	            r"   	parseFilezCSSParser.parseFile   sX    * H%D4 ffh		)1%)e)1   3 	3r$   c                     t         j                  j                  || j                  |      \  }}}|dk(  rd}|| j	                  ||||||      S y)a#  Retrieve content from URL `href` and parse it. Errors may be raised
        (e.g. URLError).

        :param href:
            URL of the CSS file to parse, will also be set as ``href`` of
            resulting stylesheet
        :param encoding:
            Value ``None`` defaults to encoding detection via HTTP, BOM or an
            @charset rule.
            A value overrides detected encoding for the sheet at ``href``
            including any imported sheets.
        :returns:
            :class:`~css_parser.css.CSSStyleSheet`.
        )r   overrideEncoding   NrF   )r   util_readUrlr?   rC   )r   r4   r0   r5   r6   r!   enctypetexts           r"   parseUrlzCSSParser.parseUrl   sp      #-//":":!) #; #+'4 a<H##D8)-U%-5 $ 7 7 r$   c                     || _         y)a1  Replace the default URL fetch function with a custom one.

        :param fetcher:
            A function which gets a single parameter

            ``url``
                the URL to read

            and must return ``(encoding, content)`` where ``encoding`` is the
            HTTP charset normally given via the Content-Type header (which may
            simply omit the charset in which case ``encoding`` would be
            ``None``) and ``content`` being the string (or unicode) content.

            The Mimetype should be 'text/css' but this has to be checked by the
            fetcher itself (the default fetcher emits a warning if encountering
            a different mimetype).

            Calling ``setFetcher`` with ``fetcher=None`` resets css_parser
            to use its default function.
        N)r?   )r   r   s     r"   r   zCSSParser.setFetcher   s    * !r$   )NNNNTT)zutf-8N)NNNNN)NNNN)N)__name__
__module____qualname____doc__r#   r*   r2   rC   rL   rT   r    r$   r"   r   r      s\    
 AE-1#"JB2 DH!0d ,0/33B ?C7:!r$   )rY   
__future__r   r   r   r   __all____docformat____version__helperr
   r9   r   sys r   r   version_infostrr,   objectr   rZ   r$   r"   <module>re      sR     R R-"    
  fEY! Y!r$   