o
    `oi+                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ G dd	 d	eZd
d Zedd Zedd Zdd Zedd Ze dd ZdS )    N)	AppConfig)settings)Warningregister)GZipMiddleware)import_string)gettext_lazyc                   @   s    e Zd ZdZedZdd ZdS )DebugToolbarConfigdebug_toolbarzDebug Toolbarc                 C   s&   ddl m} | D ]}|  q
d S )Nr   DebugToolbar)debug_toolbar.toolbarr   get_panel_classesready)selfr   cls r   Z/var/www/html/kuke-dev/django-kuke/venv/lib/python3.10/site-packages/debug_toolbar/apps.pyr      s   
zDebugToolbarConfig.readyN)__name__
__module____qualname__name_Zverbose_namer   r   r   r   r   r	      s    r	   c                    sT    fdd |  dd}|  di  dd}|rt |}|du p%d|v }|p)|S )	a  
    Checks if a template configuration is valid.

    The toolbar requires either the toolbars to be unspecified or
    ``django.template.loaders.app_directories.Loader`` to be
    included in the loaders.
    If custom loaders are specified, then APP_DIRS must be True.
    c                 3   s>    | D ]}t |tr|d V   |d E dH  q|V  qdS )z
        Recursively flatten the settings list of template loaders.

        Check for (loader, [child_loaders]) tuples.
        Django's default cached loader uses this pattern.
        r      N)
isinstancetuple)loadersloaderflat_loadersr   r   r   %   s   

z+check_template_config.<locals>.flat_loadersZAPP_DIRSFOPTIONSr   Nz.django.template.loaders.app_directories.Loader)getlist)configZapp_dirsr   Zhas_app_loadersr   r   r   check_template_config   s   
r$   c                 K   s  ddl m} g }d }g }tdd tjD r |tdddd td	r1|td
ddd |S ttj	D ]\}}t
t|rB|}q6t
||rL|| q6|s[|tdddd |S t|dkrm|tdddd |S |d ur|d |k r|tdddd |S )Nr   )DebugToolbarMiddlewarec                 s   s    | ]}t | V  qd S N)r$   ).0r#   r   r   r   	<genexpr>G   s    z#check_middleware.<locals>.<genexpr>zAt least one DjangoTemplates TEMPLATES configuration needs to use django.template.loaders.app_directories.Loader or have APP_DIRS set to True.zInclude django.template.loaders.app_directories.Loader in ["OPTIONS"]["loaders"]. Alternatively use APP_DIRS=True for at least one django.template.backends.django.DjangoTemplates backend configuration.zdebug_toolbar.W006hintidZMIDDLEWARE_CLASSESz>debug_toolbar is incompatible with MIDDLEWARE_CLASSES setting.z,Use MIDDLEWARE instead of MIDDLEWARE_CLASSESzdebug_toolbar.W004zKdebug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.zBAdd debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.zdebug_toolbar.W001r   zTdebug_toolbar.middleware.DebugToolbarMiddleware occurs multiple times in MIDDLEWARE.zMLoad debug_toolbar.middleware.DebugToolbarMiddleware only once in MIDDLEWARE.zdebug_toolbar.W002zrdebug_toolbar.middleware.DebugToolbarMiddleware occurs before django.middleware.gzip.GZipMiddleware in MIDDLEWARE.zrMove debug_toolbar.middleware.DebugToolbarMiddleware to after django.middleware.gzip.GZipMiddleware in MIDDLEWARE.zdebug_toolbar.W003)Zdebug_toolbar.middlewarer%   allr   Z	TEMPLATESappendr   Zis_overridden	enumerateZ
MIDDLEWAREis_middleware_classr   len)app_configskwargsr%   errorsZ
gzip_indexZdebug_toolbar_indexesiZ
middlewarer   r   r   check_middleware?   sl   



	r5   c                 K   s:   ddl m} g }| D ]}| D ]}|| qq|S )zOAllow each panel to check the toolbar's integration for their its own purposes.r   r   )r   r   r   Z
run_checksr-   )r1   r2   r   r3   Zpanel_classZcheck_messager   r   r   check_panel_configs   s   r6   c                 C   s6   zt |}W n
 ty   Y d S w t|ot|| S r&   )r   ImportErrorinspectisclass
issubclass)Zmiddleware_classZmiddleware_pathZmiddleware_clsr   r   r   r/      s   r/   c                 K   s(   g }t  }|s|tdddd |S )Nz&Setting DEBUG_TOOLBAR_PANELS is empty.zASet DEBUG_TOOLBAR_PANELS to a non-empty list in your settings.py.zdebug_toolbar.W005r)   )dt_settingsZ
get_panelsr-   r   )r1   r2   r3   Zpanelsr   r   r   check_panels   s   r<   c                 K   s6   ddh}t td| }|rtddddgS g S )zP
    Check that JavaScript files are resolving to the correct content type.
    zapplication/javascriptztext/javascriptz
toolbar.jsz9JavaScript files are resolving to the wrong content type.a  The Django Debug Toolbar may not load properly while mimetypes are misconfigured. See the Django documentation for an explanation of why this occurs.
https://docs.djangoproject.com/en/stable/ref/contrib/staticfiles/#static-file-development-view

This typically occurs on Windows machines. The suggested solution is to modify HKEY_CLASSES_ROOT in the registry to specify the content type for JavaScript files.

[HKEY_CLASSES_ROOT\.js]
"Content Type"="application/javascript"zdebug_toolbar.W007r)   )set	mimetypes
guess_typeintersectionr   )r1   r2   Zjavascript_typesZcheck_failedr   r   r   js_mimetype_check   s   
rA   )r8   r>   Zdjango.appsr   Zdjango.confr   Zdjango.core.checksr   r   Zdjango.middleware.gzipr   Zdjango.utils.module_loadingr   Zdjango.utils.translationr   r   r
   r;   r	   r$   r5   r6   r/   r<   rA   r   r   r   r   <module>   s(    $
N


