diff options
author | Florian Scherf <f.scherf@pengutronix.de> | 2016-01-11 18:11:35 +0100 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2016-01-12 14:47:53 +0100 |
commit | 807c0a74349957f34c8ea94ad1936caf86ad5640 (patch) | |
tree | 2bd7b5fffd5698cd59fab76a48795de7148154a5 /patches | |
parent | a3bc20b2ff900f2460b0b9c20f8cbfad78b276f3 (diff) | |
download | ptxdist-807c0a74349957f34c8ea94ad1936caf86ad5640.tar.gz ptxdist-807c0a74349957f34c8ea94ad1936caf86ad5640.tar.xz |
python-django: add patch to improve startup performance
Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'patches')
-rw-r--r-- | patches/Django-1.8.7/0001-Fixed-25322-Lazily-compiled-core.validators-regular-.patch | 123 | ||||
-rw-r--r-- | patches/Django-1.8.7/series | 1 |
2 files changed, 124 insertions, 0 deletions
diff --git a/patches/Django-1.8.7/0001-Fixed-25322-Lazily-compiled-core.validators-regular-.patch b/patches/Django-1.8.7/0001-Fixed-25322-Lazily-compiled-core.validators-regular-.patch new file mode 100644 index 000000000..3c3b0eac4 --- /dev/null +++ b/patches/Django-1.8.7/0001-Fixed-25322-Lazily-compiled-core.validators-regular-.patch @@ -0,0 +1,123 @@ +From 1753a76267a4dda6858d117858f233c0ed662a7f Mon Sep 17 00:00:00 2001 +From: Jonas Haag <jonas@lophus.org> +Date: Wed, 26 Aug 2015 09:12:05 +0200 +Subject: [PATCH 1/1] Fixed #25322 -- Lazily compiled core.validators regular + expressions. + +This speeds up import of 'django.core.validators' which can save a +few hundred milliseconds when importing the module for the first +time. It can be a significant speedup to the django-admin command. +--- + django/core/validators.py | 34 +++++++++++++++++++++++----------- + 1 file changed, 23 insertions(+), 11 deletions(-) + +diff --git a/django/core/validators.py b/django/core/validators.py +index 89d184f..7719b40 100644 +--- a/django/core/validators.py ++++ b/django/core/validators.py +@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError + from django.utils import six + from django.utils.deconstruct import deconstructible + from django.utils.encoding import force_text ++from django.utils.functional import SimpleLazyObject + from django.utils.ipv6 import is_valid_ipv6_address + from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit + from django.utils.translation import ugettext_lazy as _, ungettext_lazy +@@ -14,6 +15,18 @@ from django.utils.translation import ugettext_lazy as _, ungettext_lazy + 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, six.string_types): ++ 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(object): + regex = '' +@@ -36,9 +49,7 @@ class RegexValidator(object): + if self.flags and not isinstance(self.regex, six.string_types): + raise TypeError("If the flags are set, regex must be a regular expression string.") + +- # Compile the regex if it was not passed pre-compiled. +- if isinstance(self.regex, six.string_types): +- self.regex = re.compile(self.regex, self.flags) ++ self.regex = _lazy_re_compile(self.regex, self.flags) + + def __call__(self, value): + """ +@@ -77,7 +88,7 @@ class URLValidator(RegexValidator): + tld_re = r'\.(?:[a-z' + ul + r']{2,}|xn--[a-z0-9]+)\.?' + host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)' + +- regex = re.compile( ++ regex = _lazy_re_compile( + r'^(?:[a-z0-9\.\-]*)://' # scheme is validated separately + r'(?:\S+(?::\S*)?@)?' # user:pass authentication + r'(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')' +@@ -126,7 +137,7 @@ class URLValidator(RegexValidator): + url = value + + integer_validator = RegexValidator( +- re.compile('^-?\d+\Z'), ++ _lazy_re_compile('^-?\d+\Z'), + message=_('Enter a valid integer.'), + code='invalid', + ) +@@ -140,16 +151,17 @@ def validate_integer(value): + class EmailValidator(object): + message = _('Enter a valid email address.') + code = 'invalid' +- user_regex = re.compile( ++ ++ user_regex = _lazy_re_compile( + r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string + re.IGNORECASE) +- domain_regex = re.compile( ++ domain_regex = _lazy_re_compile( + # max length of the domain is 249: 254 (max email length) minus one + # period, two characters for the TLD, @ sign, & one character before @. + r'(?:[A-Z0-9](?:[A-Z0-9-]{0,247}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,}(?<!-))\Z', + re.IGNORECASE) +- literal_regex = re.compile( ++ literal_regex = _lazy_re_compile( + # literal form, ipv4 or ipv6 address (SMTP 4.1.3) + r'\[([A-f0-9:\.]+)\]\Z', + re.IGNORECASE) +@@ -209,14 +221,14 @@ class EmailValidator(object): + + validate_email = EmailValidator() + +-slug_re = re.compile(r'^[-a-zA-Z0-9_]+\Z') ++slug_re = _lazy_re_compile(r'^[-a-zA-Z0-9_]+\Z') + validate_slug = RegexValidator( + slug_re, + _("Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."), + 'invalid' + ) + +-ipv4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z') ++ipv4_re = _lazy_re_compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z') + validate_ipv4_address = RegexValidator(ipv4_re, _('Enter a valid IPv4 address.'), 'invalid') + + +@@ -257,7 +269,7 @@ def ip_address_validators(protocol, unpack_ipv4): + raise ValueError("The protocol '%s' is unknown. Supported: %s" + % (protocol, list(ip_address_validator_map))) + +-comma_separated_int_list_re = re.compile('^[\d,]+\Z') ++comma_separated_int_list_re = _lazy_re_compile('^[\d,]+\Z') + validate_comma_separated_integer_list = RegexValidator( + comma_separated_int_list_re, + _('Enter only digits separated by commas.'), +-- +2.6.4 + diff --git a/patches/Django-1.8.7/series b/patches/Django-1.8.7/series new file mode 100644 index 000000000..3f7010a4a --- /dev/null +++ b/patches/Django-1.8.7/series @@ -0,0 +1 @@ +0001-Fixed-25322-Lazily-compiled-core.validators-regular-.patch |