https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/middleware/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/middleware/__pycache__/common.cpython-310.pyc
o

�a!�@s�ddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZGd
d�de�ZGdd
�d
e�ZdS)�N)�urlparse)�settings)�PermissionDenied)�
mail_managers)�HttpResponsePermanentRedirect)�
is_valid_path)�MiddlewareMixin)�escape_leading_slashesc@s4eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
S)�CommonMiddlewarea
    "Common" middleware for taking care of some basic operations:

        - Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS

        - URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings,
          append missing slashes and/or prepends missing "www."s.

            - If APPEND_SLASH is set and the initial URL doesn't end with a
              slash, and it is not found in urlpatterns, form a new URL by
              appending a slash at the end. If this new URL is found in
              urlpatterns, return an HTTP redirect to this new URL; otherwise
              process the initial URL as usual.

          This behavior can be customized by subclassing CommonMiddleware and
          overriding the response_redirect_class attribute.
    cCs�|j�d�}|durtjD]}|�|�rtd��q
|��}tjo'|o'|�d�}|r1d|j	|fnd}|�
|�r>|�|�}n|��}|sJ||��krS||7}|�
|�SdS)z�
        Check for denied User-Agents and rewrite the URL based on
        settings.APPEND_SLASH and settings.PREPEND_WWW
        �HTTP_USER_AGENTNzForbidden user agentzwww.z%s://www.%s�)�META�getr�DISALLOWED_USER_AGENTS�searchr�get_host�PREPEND_WWW�
startswith�scheme�should_redirect_with_slash�get_full_path_with_slash�
get_full_path�response_redirect_class)�self�request�
user_agent�user_agent_regex�host�must_prepend�redirect_url�path�r!�:/usr/lib/python3/dist-packages/django/middleware/common.py�process_request"s 

�

�z CommonMiddleware.process_requestcCsTtjr(|j�d�s(t|dd�}t|j|�s(td|j|�}|r(|j}t|dd�SdS)z�
        Return True if settings.APPEND_SLASH is True and appending a slash to
        the request path turns an invalid path into a valid one.
        �/�urlconfNz%s/�should_append_slashTF)r�APPEND_SLASH�	path_info�endswith�getattrr�func)rrr%�match�viewr!r!r"r?sz+CommonMiddleware.should_redirect_with_slashcCsD|jdd�}t|�}tjr |jdvr td|j|��|d���|S)z�
        Return the full path of the request with a trailing slash appended.

        Raise a RuntimeError if settings.DEBUG is True and request.method is
        POST, PUT, or PATCH.
        T)�force_append_slash)�POST�PUT�PATCHa"You called this URL via %(method)s, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining %(method)s data. Change your form to point to %(url)s (note the trailing slash), or set APPEND_SLASH=False in your Django settings.)�method�url)rr	r�DEBUGr2�RuntimeErrorr)rr�new_pathr!r!r"rMs
���
z)CommonMiddleware.get_full_path_with_slashcCsL|jdkr|�|�r|�|�|��S|js$|�d�s$tt|j��|j	d<|S)z�
        When the status code of the response is 404, it may redirect to a path
        with an appended slash if should_redirect_with_slash() returns True.
        �zContent-Length)
�status_coderrr�	streaming�
has_header�str�len�content�headers)rr�responser!r!r"�process_responseds
z!CommonMiddleware.process_responseN)
�__name__�
__module__�__qualname__�__doc__rrr#rrr@r!r!r!r"r

sr
c@s$eZdZdd�Zdd�Zdd�ZdS)�BrokenLinkEmailsMiddlewarecCs�|jdkrFtjsF|��}|��}|j�dd�}|�||||�sF|j�dd�}|j�dd�}td|�	||�r7dnd|fd	||||fd
d�|S)z=Send broken link emails for relevant 404 NOT FOUND responses.r7�HTTP_REFERERrrz<none>�REMOTE_ADDRzBroken %slink on %sz	INTERNAL z=Referrer: %s
Requested URL: %s
User agent: %s
IP address: %s
T)�
fail_silently)
r8rr4rrr
r�is_ignorable_requestr�is_internal_request)rrr?�domainr �referer�ua�ipr!r!r"r@xs$�
��	z+BrokenLinkEmailsMiddleware.process_responsecCstt�dt�|�|��S)ze
        Return True if the referring URL is the same domain as the current
        request.
        z
^https?://%s/)�bool�rer,�escape)rrKrLr!r!r"rJ�sz.BrokenLinkEmailsMiddleware.is_internal_requestcs�|sdStjr��d�r|�dd�krdS|�||�s"d|vr"dSt|�}|jd|fvr4|j�kr4dSt�fdd�tjD��S)	z�
        Return True if the given request *shouldn't* notify the site managers
        according to project settings or in situations outlined by the inline
        comments.
        Tr$N����?rc3s�|]}|���VqdS)N)r)�.0�pattern��urir!r"�	<genexpr>�s�zBBrokenLinkEmailsMiddleware.is_ignorable_request.<locals>.<genexpr>)	rr'r)rJr�netlocr �any�IGNORABLE_404_URLS)rrrWrKrL�parsed_refererr!rVr"rI�s z/BrokenLinkEmailsMiddleware.is_ignorable_requestN)rArBrCr@rJrIr!r!r!r"rEvsrE)rP�urllib.parser�django.confr�django.core.exceptionsr�django.core.mailr�django.httpr�django.urlsr�django.utils.deprecationr�django.utils.httpr	r
rEr!r!r!r"�<module>si

https://t.me/RX1948 - 2025