From 1f2c8336d145c31cb9c3c3b712a78b742b4de997 Mon Sep 17 00:00:00 2001 From: abhiabhi94 <13880786+abhiabhi94@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:25:37 +0530 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E2=9A=A1=EF=B8=8F=20Prevent=20comp?= =?UTF-8?q?iling=20of=20regex=20for=20IP=20on=20every=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hitcount/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hitcount/utils.py b/hitcount/utils.py index 60c2520..afe0dcd 100644 --- a/hitcount/utils.py +++ b/hitcount/utils.py @@ -1,11 +1,13 @@ -import re - from django.apps import apps +try: + from django.utils.regex_helper import _lazy_re_compile +except ImportError: + from django.core.validators import _lazy_re_compile from hitcount.conf import settings # this is not intended to be an all-knowing IP address regex -IP_RE = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') +IP_RE = _lazy_re_compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') def get_ip(request): From 71bc3ef48f3584d1b4d27a867b0c495d6ec62759 Mon Sep 17 00:00:00 2001 From: abhiabhi94 <13880786+abhiabhi94@users.noreply.github.com> Date: Wed, 7 Jul 2021 17:09:32 +0530 Subject: [PATCH 2/2] chore: Rename deprecated settings to make it more explicilty internal --- hitcount/conf/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hitcount/conf/__init__.py b/hitcount/conf/__init__.py index 8ac55a5..de01a9b 100644 --- a/hitcount/conf/__init__.py +++ b/hitcount/conf/__init__.py @@ -10,7 +10,7 @@ def _setup(self): self._wrapped = Settings(app_settings, django_settings) -DEPRECATED_SETTINGS = { +_DEPRECATED_DJANGO_SETTINGS = { 'USE_TZ' if django.VERSION > (4, 0) else None, 'PASSWORD_RESET_TIMEOUT_DAYS' if django.VERSION > (3, 0) else None, 'DEFAULT_CONTENT_TYPE' if django.VERSION > (2, 2) else None, @@ -24,7 +24,7 @@ def __init__(self, *args): setattr(self, attr, getattr(item, attr)) for item in args for attr in dir(item) - if attr == attr.upper() and attr.upper() not in DEPRECATED_SETTINGS + if attr == attr.upper() and attr.upper() not in _DEPRECATED_DJANGO_SETTINGS ]