
    D"Q                     2    d Z ddlmZ  G d de          ZdS )a  
Copyright (c) 2013, Dave Mankoff
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Dave Mankoff nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DAVE MANKOFF BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   )Minifierc                   *    e Zd ZdZ	 	 ddZd Zd ZdS )	HTMLMinMiddlewarea  WSGI Middleware that minifies html on the way out.

  :param by_default: Specifies if minification should be turned on or off by
    default. Defaults to ``True``.
  :param keep_header: The middleware recognizes one custom HTTP header that 
    can be used to turn minification on or off on a per-request basis:
    ``X-HTML-Min-Enable``. Setting the header to ``true`` will turn minfication
    on; anything else will turn minification off. If ``by_default`` is set to 
    ``False``, this header is how you would turn minification back on. The
    middleware, by default, removes the header from the output. Setting this
    to ``True`` leaves the header in tact.
  :param debug: A quick setting to turn all minification off. The middleware
    is effectively bypassed.

  This simple middleware minifies any HTML content that passes through it. Any
  additional keyword arguments beyond the three settings the middleware has are
  passed on to the internal minifier. The documentation for the options can
  be found under :class:`htmlmin.minify`.
  TFc                 `    || _         || _        || _        || _        t	          di || _        d S )N )app
by_defaultdebugkeep_headerr   minifier)selfr   r	   r   r
   kwargss         R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/htmlmin/middleware.py__init__zHTMLMinMiddleware.__init__2   s8    DH DODJ"D&&v&&DMMM    c                       j         r                     |          S g d fd	}d                      ||          D             }d         r  j        j        | gS |S )Nc                                                              |                     j        sd |D             } | ||           d S )Nc                 (    g | ]\  }}|d k    ||fS )X-HTML-Min-Enabler   ).0headervalues      r   
<listcomp>zOHTMLMinMiddleware.__call__.<locals>.minified_start_response.<locals>.<listcomp>C   s5     = = =}vu$(;;; E?;;;r   )appendshould_minifyr   )statusheadersexc_infor   r   start_responses      r   minified_start_responsez;HTMLMinMiddleware.__call__.<locals>.minified_start_response@   sh    4--g66777 == == = =nVWh/////r   c                     g | ]}|S r   r   )r   is     r   r   z.HTMLMinMiddleware.__call__.<locals>.<listcomp>G   s    BBB!ABBBr       )N)r
   r   r   minify)r   environr   r    htmlr   s   ` `  @r   __call__zHTMLMinMiddleware.__call__:   s    z /XXg~...M0 0 0 0 0 0 0 0 CBtxx)@AABBBDQ +"dm"D)**Kr   c                     d}d }|D ]=\  }}|s|dk    r|dk    rd}| n%|"|dk    r|                                 dk    }|r n>|o| j        r|dk    p	| j         o|S )NFzContent-Typez	text/htmlTr   true)lowerr	   )r   r   is_htmlflag_headerr   r   s         r   r   zHTMLMinMiddleware.should_minifyL   s    GK  	 	 >11e{6J6J"
%		+>!>!>{{}}. 	
% -/;%/ ,?*{-r   N)TFF)__name__
__module____qualname____doc__r   r'   r   r   r   r   r   r      sX         & 8=' ' ' '  $- - - - -r   r   N)r0   mainr   objectr   r   r   r   <module>r3      sW    6      >- >- >- >- >- >- >- >- >- >-r   