
    -Ph                     d    d Z ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ dZ G d d	          ZdS )
z:mod:`sassutils.wsgi` --- WSGI middleware for development purpose
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    N)resource_filename   )Manifest)CompileError)SassMiddlewarec                   :    e Zd ZdZi dfdZd Zed             ZdS )r   a\	  WSGI middleware for development purpose.  Every time a CSS file has
    requested it finds a matched Sass/SCSS source file and then compiled
    it into CSS.

    It shows syntax errors in three ways:

    Heading comment
        The result CSS includes detailed error message in the heading
        CSS comment e.g.:

        .. code-block:: css

            /*
            Error: invalid property name
            */

    Red text in ``body:before``
        The result CSS draws detailed error message in ``:before``
        pseudo-class of ``body`` element e.g.:

        .. code-block:: css

            body:before {
                content: 'Error: invalid property name';
                color: maroon;
                background-color: white;
            }

        In most cases you could be aware of syntax error by refreshing your
        working document because it will removes all other styles and leaves
        only a red text.

    :mod:`logging`
        It logs syntax errors if exist during compilation to
        ``sassutils.wsgi.SassMiddleware`` logger with level ``ERROR``.

        To enable this::

            from logging import Formatter, StreamHandler, getLogger
            logger = getLogger('sassutils.wsgi.SassMiddleware')
            handler = StreamHandler(level=logging.ERROR)
            formatter = Formatter(fmt='*' * 80 + '\n%(message)s\n' + '*' * 80)
            handler.setFormatter(formatter)
            logger.addHandler(handler)

        Or simply::

            import logging
            logging.basicConfig()

    :param app: the WSGI application to wrap
    :type app: :class:`collections.abc.Callable`
    :param manifests: build settings.  the same format to
                      :file:`setup.py` script's ``sass_manifests``
                      option
    :type manifests: :class:`collections.abc.Mapping`
    :param package_dir: optional mapping of package names to directories.
                        the same format to :file:`setup.py` script's
                        ``package_dir`` option
    :type package_dir: :class:`collections.abc.Mapping`

    .. versionchanged:: 0.4.0
       It creates also source map files with filenames followed by
       :file:`.map` suffix.

    .. versionadded:: 0.8.0
       It logs syntax errors if exist during compilation to
       ``sassutils.wsgi.SassMiddleware`` logger with level ``ERROR``.

    200 OKc                    t          |          st          dt          |          z             || _        t	          j        |          | _        t          |t          j	        j
                  st          dt          |          z             || _        t          |          | _        | j        D ]&}|| j        v rt          |d          }|| j        |<   'g | _        | j                                        D ]j\  }}|j        }|                    d          sd|z   }|                    d          s|dz  }| j        |         }| j                            |||f           kd S )Nz2app must be a WSGI-compliant callable object, not z*package_dir must be a mapping object, not  /)callable	TypeErrorreprappr   normalize_manifests	manifests
isinstancecollectionsabcMappingerror_statusdictpackage_dirr   pathsitems	wsgi_path
startswithendswithappend)	selfr   r   r   r   package_namepathmanifestr   s	            N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sassutils/wsgi.py__init__zSassMiddleware.__init__Y   s    }} 	c#   !5i@@+{'>?? 	<[!!"   ),, N 	2 	2Lt///$\266D-1D\**
&*n&:&:&<&< 	B 	B"L( *I'',, ,)O	%%c** !S 	*<8KJy+x@AAAA	B 	B    c                 x   |                     dd          }|                    d          ry| j        D ]p\  }}}|                    |          s|t	          |          d          }|                    ||          }	 |                    ||d          }	n# t          $ r Y  n t          $ r}
t          j
        t          dz             }|                    t          |
                      || j        dg           dt          |
                              d	          d
d|                     t          |
                                        d	          dddgcY d }
~
c S d }
~
ww xY wd } |ddg            |t"          j                            ||	                    c S |                     ||          S )N	PATH_INFOr   z.cssT)
source_mapz.SassMiddleware)Content-Typeztext/css; charset=utf-8s   /*
zutf-8s   
*/

s   body:before { content: s(   ; color: maroon; background-color: whites'   ; white-space: pre-wrap; display: blocks=   ; font-family: "Courier New", monospace; user-select: text; }c              3      K   t          | d          5 }	 |                    d          }|r|V  nn	 d d d            d S # 1 swxY w Y   d S )Nrbr   i   )openread)r"   in_chunks      r$   	read_filez*SassMiddleware.__call__.<locals>.read_file   s      dD)) &S&$'HHTNNE$ &&+ %&
 !&& & & & & & & & & & & & & & & & & &s    AAAr	   )r*   ztext/css)getr   r   r   lenunresolve_filename	build_oneOSErrorr   logging	getLogger__name__errorstrr   encodequote_css_stringosr"   joinr   )r    environstart_responser"   prefixr   r#   css_filenamesass_filenameresulteloggerr1   s                r$   __call__zSassMiddleware.__call__z   s   {{;,,==   *	D15 )D )D-Xv.. #CKKLL1 ( ; ;! !%//#%#' 0  FF
    EE#   $.x:K/KLLFLLQ((("N)DE  
  Qw!7!72--c!ff55<<WEECB2        "& & & x*F)GHHH yk6!B!BCCCCCxx000s%   ?B
E(&	E(/B,E#E(#E(c                 L    dd                     d | D                       z   dz   S )z&Quotes a string as CSS string literal.'r   c              3   :   K   | ]}d t          |          z  V  dS )z\%06xN)ord).0cs     r$   	<genexpr>z2SassMiddleware.quote_css_string.<locals>.<genexpr>   s-      ::1XA.::::::r&   )r?   )ss    r$   r=   zSassMiddleware.quote_css_string   s/     RWW::::::::S@@r&   N)r9   
__module____qualname____doc__r%   rH   staticmethodr=    r&   r$   r   r      sr        E EP +-B B B BB-1 -1 -1^ A A \A A Ar&   r   )rS   collections.abcr   r7   os.pathr>   pkg_resourcesr   builderr   sassr   __all__r   rU   r&   r$   <module>r\      s           + + + + + +            
[A [A [A [A [A [A [A [A [A [Ar&   