
    Mf]                         d Z ddlmZmZ  G d d          Z G d d          Z G d d          Zg Z	 d	d
lm	Z
 ee
z  Zd	dlmZ ed eD             z  Zn# e$ r
ZY dZ[ndZ[ww xY w G d d          ZdS )a  
Django-plotly-dash middleware

This middleware enables the collection of items from templates for inclusion in the header and footer

Copyright (c) 2018 Gibbs Consulting and others - see CONTRIBUTIONS.md

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

   )serve_locallystatic_pathc                   *    e Zd ZdZd Zd Zd Zd ZdS )EmbeddedHolderz7Hold details of embedded content from processing a viewc                 0    d| _         d| _        d| _        d S N )cssconfigscriptsselfs    \/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django_plotly_dash/middleware.py__init__zEmbeddedHolder.__init__"   s        c                     |r	|| _         dS dS )zAdd css contentN)r
   )r   r
   s     r   add_csszEmbeddedHolder.add_css&   s     	DHHH	 	r   c                     |r	|| _         dS dS )zAdd config contentN)r   )r   r   s     r   
add_configzEmbeddedHolder.add_config*   s     	! DKKK	! 	!r   c                 .    |r| xj         |z  c_         dS dS )zAdd js contentN)r   )r   r   s     r   add_scriptszEmbeddedHolder.add_scripts.   s(     	$LLG#LLLL	$ 	$r   N)__name__
__module____qualname____doc__r   r   r   r    r   r   r   r       sV        ==    ! ! !$ $ $ $ $r   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )ContentCollectorz
    Collect content during view processing, and substitute in response by finding magic strings.

    This enables view functionality, such as template tags, to introduce content such as css and js
    inclusion into the header and footer.
    c                 V    d| _         d| _        t                      | _        d| _        d S )N%DJANGO_PLOTLY_DASH_HEADER_PLACEHOLDER%DJANGO_PLOTLY_DASH_FOOTER_PLACEHOLDERutf-8)header_placeholderfooter_placeholderr   embedded_holder	_encodingr   s    r   r   zContentCollector.__init__:   s+    "I"I-// r   c                    	 |                      |j        | j        | j        j                  }|                      || j        d                    | j        j        | j        j        g                    |_        n# t          $ r Y nw xY w|S )z9Locate placeholder magic strings and replace with content
)
_replacecontentr#   r%   r
   r$   joinr   r   AttributeError)r   responsec1s      r   adjust_responsez ContentCollector.adjust_responseA   s    	x/#6#379 9B  $}}R-1-D-1YY8L8S8<8L8T8V .W .W X  XH  	 	 	D	 s   A5A8 8
BBc                     |                     |                     |          |                     |r|nd                    S r   )replace_encode)r   r*   placeholdersubstitutions       r   r)   zContentCollector._replaceS   sA    t||K88#||L,PLLbQQS S 	Sr   c                 6    |                     | j                  S Nencoder&   r   strings     r   r2   zContentCollector._encodeW       }}T^,,,r   N)r   r   r   r   r   r/   r)   r2   r   r   r   r   r   3   s]         ! ! !  $S S S- - - - -r   r   c                       e Zd ZdZd Zd ZdS )BaseMiddlewarezDjango-plotly-dash middlewarec                     || _         d S r6   )get_response)r   r?   s     r   r   zBaseMiddleware.__init__]   s    (r   c                     t                      |_        |                     |          }|j                            |          }|S r6   )r   dpd_content_handlerr?   r/   )r   requestr-   s      r   __call__zBaseMiddleware.__call__`   s>    &6&8&8#$$W--.>>xHHr   N)r   r   r   r   r   rC   r   r   r   r=   r=   Z   s8        ##) ) )    r   r=       )substitutions)static_substitutionsc                 6    g | ]\  }}|t          |          fS r   )r   ).0xys      r   
<listcomp>rK   o   s'    OOO$!Q1k!nn-OOOr   Nc                   $    e Zd ZdZd Zd Zd ZdS )ExternalRedirectionMiddlewarezHMiddleware to force redirection in third-party content through rewritingc                 ~     | _         g }t                      r
|t          z  }d _         fd|D              _        d S )Nr"   c                 j    g | ]/\  }}                     |                               |          f0S r   )r2   )rH   sourcetargetr   s      r   rK   z:ExternalRedirectionMiddleware.__init__.<locals>.<listcomp>   sS     Z Z Z9G  $||F33#||F335 Z Z Zr   )r?   r   dpd_substitutionsr&   rE   )r   r?   rE   s   `  r   r   z&ExternalRedirectionMiddleware.__init__w   sf    (?? 	/..M Z Z Z ZKXZ Z Zr   c                     |                      |          }	 |j        }| j        D ]\  }}|                    ||          }||_        n# t          $ r Y nw xY w|S r6   )r?   r*   rE   r1   r,   )r   rB   r-   r*   rP   rQ   s         r   rC   z&ExternalRedirectionMiddleware.__call__   s    $$W--
	&G"&"4 : :!//&&99&H 	 	 	D	 s   1A	 	
AAc                 6    |                     | j                  S r6   r7   r9   s     r   r2   z%ExternalRedirectionMiddleware._encode   r;   r   N)r   r   r   r   r   rC   r2   r   r   r   rM   rM   t   sJ        NNZ Z Z  $- - - - -r   rM   )r   utilr   r   r   r   r=   rR   dpd_static_support.mappingsrE   dpd_direct_substitutionsrF   dpd_ss_substitutions	ExceptionerM   r   r   r   <module>r[      sY   6 - , , , , , , ,$ $ $ $ $ $ $ $&%- %- %- %- %- %- %- %-N          	UUUUUU11XXXXXXOO:NOOOO 	 	 	DDDD	#- #- #- #- #- #- #- #- #- #-s    A A% A%