summaryrefslogtreecommitdiff
path: root/django/db
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/db
parent39a34d4bf94bc8325119bc23b64f3a041a85dd2d (diff)
Fixed #30899 -- Lazily compiled import time regular expressions.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/mysql/base.py5
-rw-r--r--django/db/backends/oracle/operations.py4
-rw-r--r--django/db/backends/sqlite3/base.py3
-rw-r--r--django/db/backends/sqlite3/introspection.py3
-rw-r--r--django/db/models/sql/constants.py4
5 files changed, 10 insertions, 9 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index d60ff7937d..74c98a091c 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -3,14 +3,13 @@ MySQL database backend for Django.
Requires mysqlclient: https://pypi.org/project/mysqlclient/
"""
-import re
-
from django.core.exceptions import ImproperlyConfigured
from django.db import utils
from django.db.backends import utils as backend_utils
from django.db.backends.base.base import BaseDatabaseWrapper
from django.utils.asyncio import async_unsafe
from django.utils.functional import cached_property
+from django.utils.regex_helper import _lazy_re_compile
try:
import MySQLdb as Database
@@ -47,7 +46,7 @@ django_conversions = {
# This should match the numerical portion of the version numbers (we can treat
# versions like 5.0.24 and 5.0.24a as the same).
-server_version_re = re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
+server_version_re = _lazy_re_compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
class CursorWrapper:
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index 4a6c71e149..59f55dccd5 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -1,5 +1,4 @@
import datetime
-import re
import uuid
from functools import lru_cache
@@ -12,6 +11,7 @@ from django.db.utils import DatabaseError
from django.utils import timezone
from django.utils.encoding import force_bytes, force_str
from django.utils.functional import cached_property
+from django.utils.regex_helper import _lazy_re_compile
from .base import Database
from .utils import BulkInsertMapper, InsertVar, Oracle_datetime
@@ -102,7 +102,7 @@ END;
# if the time zone name is passed in parameter. Use interpolation instead.
# https://groups.google.com/forum/#!msg/django-developers/zwQju7hbG78/9l934yelwfsJ
# This regexp matches all time zone names from the zoneinfo database.
- _tzname_re = re.compile(r'^[\w/:+-]+$')
+ _tzname_re = _lazy_re_compile(r'^[\w/:+-]+$')
def _prepare_tzname_delta(self, tzname):
if '+' in tzname:
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index f959f921f1..45a22f5a36 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -23,6 +23,7 @@ from django.utils import timezone
from django.utils.asyncio import async_unsafe
from django.utils.dateparse import parse_datetime, parse_time
from django.utils.duration import duration_microseconds
+from django.utils.regex_helper import _lazy_re_compile
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
@@ -380,7 +381,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
-FORMAT_QMARK_REGEX = re.compile(r'(?<!%)%s')
+FORMAT_QMARK_REGEX = _lazy_re_compile(r'(?<!%)%s')
class SQLiteCursorWrapper(Database.Cursor):
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 5e33d2a7e2..5186e6d14b 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -7,10 +7,11 @@ from django.db.backends.base.introspection import (
BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
)
from django.db.models.indexes import Index
+from django.utils.regex_helper import _lazy_re_compile
FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('pk',))
-field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
+field_size_re = _lazy_re_compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
def get_field_size(name):
diff --git a/django/db/models/sql/constants.py b/django/db/models/sql/constants.py
index 28f4242a7a..1ff44252c5 100644
--- a/django/db/models/sql/constants.py
+++ b/django/db/models/sql/constants.py
@@ -2,7 +2,7 @@
Constants specific to the SQL storage portion of the ORM.
"""
-import re
+from django.utils.regex_helper import _lazy_re_compile
# Size of each "chunk" for get_iterator calls.
# Larger values are slightly faster at the expense of more storage space.
@@ -16,7 +16,7 @@ SINGLE = 'single'
CURSOR = 'cursor'
NO_RESULTS = 'no results'
-ORDER_PATTERN = re.compile(r'\?|[-+]?[.\w]+$')
+ORDER_PATTERN = _lazy_re_compile(r'\?|[-+]?[.\w]+$')
ORDER_DIR = {
'ASC': ('ASC', 'DESC'),
'DESC': ('DESC', 'ASC'),