From e3d0b4d5501c6d0bc39f035e4345e5bdfde12e41 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Sat, 26 Oct 2019 16:42:32 +0200 Subject: Fixed #30899 -- Lazily compiled import time regular expressions. --- django/http/request.py | 4 ++-- django/http/response.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'django/http') diff --git a/django/http/request.py b/django/http/request.py index 98a51f57c8..933af0f13e 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -1,7 +1,6 @@ import cgi import codecs import copy -import re from io import BytesIO from itertools import chain from urllib.parse import quote, urlencode, urljoin, urlsplit @@ -19,9 +18,10 @@ from django.utils.datastructures import ( from django.utils.encoding import escape_uri_path, iri_to_uri from django.utils.functional import cached_property from django.utils.http import is_same_domain, limited_parse_qsl +from django.utils.regex_helper import _lazy_re_compile RAISE_ERROR = object() -host_validation_re = re.compile(r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9\.:]+\])(:\d+)?$") +host_validation_re = _lazy_re_compile(r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9\.:]+\])(:\d+)?$") class UnreadablePostError(OSError): diff --git a/django/http/response.py b/django/http/response.py index c39519c4bb..269953c0af 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -17,8 +17,9 @@ from django.http.cookie import SimpleCookie from django.utils import timezone from django.utils.encoding import iri_to_uri from django.utils.http import http_date +from django.utils.regex_helper import _lazy_re_compile -_charset_from_content_type_re = re.compile(r';\s*charset=(?P[^\s;]+)', re.I) +_charset_from_content_type_re = _lazy_re_compile(r';\s*charset=(?P[^\s;]+)', re.I) class BadHeaderError(ValueError): -- cgit v1.3