summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-10-26 16:42:32 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-29 09:22:26 +0100
commite3d0b4d5501c6d0bc39f035e4345e5bdfde12e41 (patch)
treea8ddbafdf4a38a87df6f65fc4d02dba08c725096 /django/test
parent39a34d4bf94bc8325119bc23b64f3a041a85dd2d (diff)
Fixed #30899 -- Lazily compiled import time regular expressions.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/client.py6
-rw-r--r--django/test/html.py5
2 files changed, 6 insertions, 5 deletions
diff --git a/django/test/client.py b/django/test/client.py
index 98ede36499..0a683f5026 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -1,7 +1,6 @@
import json
import mimetypes
import os
-import re
import sys
from copy import copy
from functools import partial
@@ -26,15 +25,16 @@ from django.utils.encoding import force_bytes
from django.utils.functional import SimpleLazyObject
from django.utils.http import urlencode
from django.utils.itercompat import is_iterable
+from django.utils.regex_helper import _lazy_re_compile
__all__ = ('Client', 'RedirectCycleError', 'RequestFactory', 'encode_file', 'encode_multipart')
BOUNDARY = 'BoUnDaRyStRiNg'
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
-CONTENT_TYPE_RE = re.compile(r'.*; charset=([\w\d-]+);?')
+CONTENT_TYPE_RE = _lazy_re_compile(r'.*; charset=([\w\d-]+);?')
# Structured suffix spec: https://tools.ietf.org/html/rfc6838#section-4.2.8
-JSON_CONTENT_TYPE_RE = re.compile(r'^application\/(.+\+)?json')
+JSON_CONTENT_TYPE_RE = _lazy_re_compile(r'^application\/(.+\+)?json')
class RedirectCycleError(Exception):
diff --git a/django/test/html.py b/django/test/html.py
index 511c08bb26..36b44b0466 100644
--- a/django/test/html.py
+++ b/django/test/html.py
@@ -1,12 +1,13 @@
"""Compare two HTML documents."""
-import re
from html.parser import HTMLParser
+from django.utils.regex_helper import _lazy_re_compile
+
# ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020
# SPACE.
# https://infra.spec.whatwg.org/#ascii-whitespace
-ASCII_WHITESPACE = re.compile(r'[\t\n\f\r ]+')
+ASCII_WHITESPACE = _lazy_re_compile(r'[\t\n\f\r ]+')
def normalize_whitespace(string):