From 2d990fb7fa6a04bb709aa9d7f687ec009c557c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ehrlich?= Date: Mon, 26 Jan 2015 11:23:48 +0100 Subject: [PATCH] [1.8.x] Fixed #24221 - Used precompiled regexp for percent-placeholder matching. Backport of ea0ea7859a224225950a4df7c23eb3a7d823ddcd from master --- django/views/generic/edit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index ef70501bc2..6f514c3a70 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -12,6 +12,8 @@ from django.views.generic.base import TemplateResponseMixin, ContextMixin, View from django.views.generic.detail import (SingleObjectMixin, SingleObjectTemplateResponseMixin, BaseDetailView) +PERCENT_PLACEHOLDER_REGEX = re.compile(r'%\([^\)]+\)') # RemovedInDjango20Warning + class FormMixinBase(type): def __new__(cls, name, bases, attrs): @@ -163,7 +165,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): Returns the supplied URL. """ if self.success_url: - if re.search(r'%\([^\)]+\)', self.success_url): + if PERCENT_PLACEHOLDER_REGEX.search(self.success_url): warnings.warn( "%()s placeholder style in success_url is deprecated. " "Please replace them by the {} Python format syntax.", @@ -297,7 +299,7 @@ class DeletionMixin(object): def get_success_url(self): if self.success_url: - if re.search(r'%\([^\)]+\)', self.success_url): + if PERCENT_PLACEHOLDER_REGEX.search(self.success_url): warnings.warn( "%()s placeholder style in success_url is deprecated. " "Please replace them by the {} Python format syntax.",