diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-10-26 16:42:32 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-29 09:22:26 +0100 |
| commit | e3d0b4d5501c6d0bc39f035e4345e5bdfde12e41 (patch) | |
| tree | a8ddbafdf4a38a87df6f65fc4d02dba08c725096 /django/utils/text.py | |
| parent | 39a34d4bf94bc8325119bc23b64f3a041a85dd2d (diff) | |
Fixed #30899 -- Lazily compiled import time regular expressions.
Diffstat (limited to 'django/utils/text.py')
| -rw-r--r-- | django/utils/text.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index 03e2d05177..5e1409116e 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -7,6 +7,7 @@ from io import BytesIO from django.utils.deprecation import RemovedInDjango40Warning from django.utils.functional import SimpleLazyObject, keep_lazy_text, lazy +from django.utils.regex_helper import _lazy_re_compile from django.utils.translation import gettext as _, gettext_lazy, pgettext @@ -17,11 +18,11 @@ def capfirst(x): # Set up regular expressions -re_words = re.compile(r'<[^>]+?>|([^<>\s]+)', re.S) -re_chars = re.compile(r'<[^>]+?>|(.)', re.S) -re_tag = re.compile(r'<(/)?(\S+?)(?:(\s*/)|\s.*?)?>', re.S) -re_newlines = re.compile(r'\r\n|\r') # Used in normalize_newlines -re_camel_case = re.compile(r'(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))') +re_words = _lazy_re_compile(r'<[^>]+?>|([^<>\s]+)', re.S) +re_chars = _lazy_re_compile(r'<[^>]+?>|(.)', re.S) +re_tag = _lazy_re_compile(r'<(/)?(\S+?)(?:(\s*/)|\s.*?)?>', re.S) +re_newlines = _lazy_re_compile(r'\r\n|\r') # Used in normalize_newlines +re_camel_case = _lazy_re_compile(r'(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))') @keep_lazy_text @@ -306,7 +307,7 @@ def compress_sequence(sequence): # Expression to match some_token and some_token="with spaces" (and similarly # for single-quoted strings). -smart_split_re = re.compile(r""" +smart_split_re = _lazy_re_compile(r""" ((?: [^\s'"]* (?: @@ -355,7 +356,7 @@ def _replace_entity(match): return match.group(0) -_entity_re = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));") +_entity_re = _lazy_re_compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));") @keep_lazy_text |
