a
    IgJ'                     @   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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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e	dd Z e	dd Z!dS )    N)	AppConfig)settings)ErrorWarningregister)GZipMiddleware)NoReverseMatchreverse)import_string)gettext_lazy)APP_NAMEr   )CONFIG_DEFAULTSc                   @   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   N/var/www/html/django/DPS/env/lib/python3.9/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 pJd|v }|pR|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 ]2}t |tr0|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	rb|td
ddd |S ttj	D ],\}}t
t|r|}qlt
||rl|| ql|s|tdddd nJt|dkr|tdddd n(|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>I       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_middlewareA   sf    


			r;   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_checksr3   )r7   r8   r   r9   Zpanel_classZcheck_messager   r   r   check_panel_configs   s    r<   c                 C   s6   zt |}W n ty    Y d S 0 t|o4t|| S r+   )r
   ImportErrorinspectisclass
issubclass)Zmiddleware_classZmiddleware_pathZmiddleware_clsr   r   r   r5      s    r5   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_panelsr3   r   )r7   r8   r9   Zpanelsr   r   r   check_panels   s    rB   c                 K   s6   ddh}t td| }|r2t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   )r7   r8   Zjavascript_typesZcheck_failedr   r   r   js_mimetype_check   s    
rG   c                 K   sz   t  d td k}ztt d d}W n ty@   d}Y n0 |oJ| }tjsrt  d rr|rrtdddd	gS g S d
S )zI
    Check that the toolbar is not being used when tests are running
    ZSHOW_TOOLBAR_CALLBACKz:render_panelTFZIS_RUNNING_TESTSz1The Django Debug Toolbar can't be used with testsaR  Django changes the DEBUG setting to False when running tests. By default the Django Debug Toolbar is installed because DEBUG is set to True. For most cases, you need to avoid installing the toolbar when running tests. If you feel this check is in error, you can set `DEBUG_TOOLBAR_CONFIG['IS_RUNNING_TESTS'] = False` to bypass this check.zdebug_toolbar.E001r/   N)	rA   Z
get_configr   r	   r   r   r   DEBUGr   )r7   r8   Zshow_toolbar_changedZtoolbar_urls_installedZlikely_error_setupr   r   r   0debug_toolbar_installed_when_running_tests_check   s.    




rI   c                 K   s0   g }t tdi }d|v r,|tdddd |S )NZDEBUG_TOOLBAR_CONFIGZOBSERVE_REQUEST_CALLBACKzSThe deprecated OBSERVE_REQUEST_CALLBACK setting is present in DEBUG_TOOLBAR_CONFIG.zFUse the UPDATE_ON_FETCH and/or SHOW_TOOLBAR_CALLBACK settings instead.zdebug_toolbar.W008r/   )getattrr   r3   r   )r7   r8   r9   ZUSER_CONFIGr   r   r   check_settings  s    rK   )"r>   rD   Zdjango.appsr   Zdjango.confr   Zdjango.core.checksr   r   r   Zdjango.middleware.gzipr   Zdjango.urlsr   r	   Zdjango.utils.module_loadingr
   Zdjango.utils.translationr   r   r   r   rA   Zdebug_toolbar.settingsr   r   r)   r;   r<   r5   rB   rG   rI   rK   r   r   r   r   <module>   s2   $
N




/