summaryrefslogtreecommitdiff
path: root/django/forms
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/forms
parent39a34d4bf94bc8325119bc23b64f3a041a85dd2d (diff)
Fixed #30899 -- Lazily compiled import time regular expressions.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py3
-rw-r--r--django/forms/widgets.py4
2 files changed, 4 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 36ec634929..285f8cfc76 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -28,6 +28,7 @@ from django.utils import formats
from django.utils.dateparse import parse_duration
from django.utils.duration import duration_string
from django.utils.ipv6 import clean_ipv6_address
+from django.utils.regex_helper import _lazy_re_compile
from django.utils.translation import gettext_lazy as _, ngettext_lazy
__all__ = (
@@ -243,7 +244,7 @@ class IntegerField(Field):
default_error_messages = {
'invalid': _('Enter a whole number.'),
}
- re_decimal = re.compile(r'\.0*\s*$')
+ re_decimal = _lazy_re_compile(r'\.0*\s*$')
def __init__(self, *, max_value=None, min_value=None, **kwargs):
self.max_value, self.min_value = max_value, min_value
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index f9627f2918..59b7880cd4 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -4,7 +4,6 @@ HTML Widget classes
import copy
import datetime
-import re
import warnings
from collections import defaultdict
from itertools import chain
@@ -17,6 +16,7 @@ from django.utils.datastructures import OrderedSet
from django.utils.dates import MONTHS
from django.utils.formats import get_format
from django.utils.html import format_html, html_safe
+from django.utils.regex_helper import _lazy_re_compile
from django.utils.safestring import mark_safe
from django.utils.topological_sort import (
CyclicDependencyError, stable_topological_sort,
@@ -935,7 +935,7 @@ class SelectDateWidget(Widget):
template_name = 'django/forms/widgets/select_date.html'
input_type = 'select'
select_widget = Select
- date_re = re.compile(r'(\d{4}|0)-(\d\d?)-(\d\d?)$')
+ date_re = _lazy_re_compile(r'(\d{4}|0)-(\d\d?)-(\d\d?)$')
def __init__(self, attrs=None, years=None, months=None, empty_label=None):
self.attrs = attrs or {}