mirror of
https://github.com/django/django.git
synced 2025-11-29 06:51:10 +00:00
Refs #30899 -- Moved _lazy_re_compile() to the django.utils.regex_helper.
This commit is contained in:
parent
6c6d24a4fe
commit
c4cba148d8
2 changed files with 19 additions and 13 deletions
|
|
@ -6,26 +6,14 @@ from urllib.parse import urlsplit, urlunsplit
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.encoding import punycode
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.ipv6 import is_valid_ipv6_address
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
from django.utils.translation import gettext_lazy as _, ngettext_lazy
|
||||
|
||||
# These values, if given to validate(), will trigger the self.required check.
|
||||
EMPTY_VALUES = (None, '', [], (), {})
|
||||
|
||||
|
||||
def _lazy_re_compile(regex, flags=0):
|
||||
"""Lazily compile a regex with flags."""
|
||||
def _compile():
|
||||
# Compile the regex if it was not passed pre-compiled.
|
||||
if isinstance(regex, str):
|
||||
return re.compile(regex, flags)
|
||||
else:
|
||||
assert not flags, "flags must be empty if regex is passed pre-compiled"
|
||||
return regex
|
||||
return SimpleLazyObject(_compile)
|
||||
|
||||
|
||||
@deconstructible
|
||||
class RegexValidator:
|
||||
regex = ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue