File: //usr/lib/python3/dist-packages/django/middleware/__pycache__/common.cpython-310.pyc
o
�a! � @ s� d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl m
Z
d dlmZ d dl
mZ d d lmZ G d
d� de�ZG dd
� d
e�ZdS )� N)�urlparse)�settings)�PermissionDenied)�
mail_managers)�HttpResponsePermanentRedirect)�
is_valid_path)�MiddlewareMixin)�escape_leading_slashesc @ s4 e Zd ZdZeZdd� 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.
c C s� |j �d�}|durtjD ]}|�|�rtd��q
|�� }tjo'|o'|�d� }|r1d|j |f nd}| �
|�r>| �|�}n|�� }|sJ||�� krS||7 }| �
|�S dS )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"