From 9449c59fbb6495a3888f3c644b9c7951782c9ee7 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 3 Apr 2024 16:17:15 +0200 Subject: [PATCH] Code - Getting ready for newer python versions - packing our own strtobool (#2291) --- changedetectionio/__init__.py | 2 +- changedetectionio/api/api_v1.py | 2 +- .../blueprint/browser_steps/__init__.py | 2 +- .../blueprint/price_data_follower/__init__.py | 2 +- .../content_fetchers/__init__.py | 2 +- changedetectionio/flask_app.py | 2 +- changedetectionio/forms.py | 2 +- changedetectionio/model/Watch.py | 2 +- changedetectionio/processors/__init__.py | 2 +- changedetectionio/store.py | 2 +- changedetectionio/strtobool.py | 23 +++++++++++++++++++ 11 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 changedetectionio/strtobool.py diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index f5003a26..72750107 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -4,7 +4,7 @@ __version__ = '0.45.17' -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from json.decoder import JSONDecodeError import os #os.environ['EVENTLET_NO_GREENDNS'] = 'yes' diff --git a/changedetectionio/api/api_v1.py b/changedetectionio/api/api_v1.py index 92b4728c..85e2b30e 100644 --- a/changedetectionio/api/api_v1.py +++ b/changedetectionio/api/api_v1.py @@ -1,5 +1,5 @@ import os -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from flask_expects_json import expects_json from changedetectionio import queuedWatchMetaData diff --git a/changedetectionio/blueprint/browser_steps/__init__.py b/changedetectionio/blueprint/browser_steps/__init__.py index 2ee0d44f..24440908 100644 --- a/changedetectionio/blueprint/browser_steps/__init__.py +++ b/changedetectionio/blueprint/browser_steps/__init__.py @@ -12,7 +12,7 @@ # # -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from flask import Blueprint, request, make_response import os diff --git a/changedetectionio/blueprint/price_data_follower/__init__.py b/changedetectionio/blueprint/price_data_follower/__init__.py index de109899..89a2fc67 100644 --- a/changedetectionio/blueprint/price_data_follower/__init__.py +++ b/changedetectionio/blueprint/price_data_follower/__init__.py @@ -1,5 +1,5 @@ -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from flask import Blueprint, flash, redirect, url_for from flask_login import login_required from changedetectionio.store import ChangeDetectionStore diff --git a/changedetectionio/content_fetchers/__init__.py b/changedetectionio/content_fetchers/__init__.py index 3ad5f5f7..91f13388 100644 --- a/changedetectionio/content_fetchers/__init__.py +++ b/changedetectionio/content_fetchers/__init__.py @@ -1,5 +1,5 @@ import sys -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from loguru import logger from changedetectionio.content_fetchers.exceptions import BrowserStepsStepException import os diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index 06aa2d69..e2302db5 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -6,7 +6,7 @@ import queue import threading import time from copy import deepcopy -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from functools import wraps from threading import Event diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index cdcb8ee0..4d408c61 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -1,6 +1,6 @@ import os import re -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from wtforms import ( BooleanField, diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 602df5cc..044090b7 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -1,4 +1,4 @@ -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool import os import re import time diff --git a/changedetectionio/processors/__init__.py b/changedetectionio/processors/__init__.py index 3ef718ff..e2b54481 100644 --- a/changedetectionio/processors/__init__.py +++ b/changedetectionio/processors/__init__.py @@ -3,7 +3,7 @@ import os import hashlib import re from copy import deepcopy -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from loguru import logger class difference_detection_processor(): diff --git a/changedetectionio/store.py b/changedetectionio/store.py index 24a0c405..43202140 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -1,4 +1,4 @@ -from distutils.util import strtobool +from changedetectionio.strtobool import strtobool from flask import ( flash diff --git a/changedetectionio/strtobool.py b/changedetectionio/strtobool.py new file mode 100644 index 00000000..ffb6b9f9 --- /dev/null +++ b/changedetectionio/strtobool.py @@ -0,0 +1,23 @@ +# Because strtobool was removed in python 3.12 distutils + +_MAP = { + 'y': True, + 'yes': True, + 't': True, + 'true': True, + 'on': True, + '1': True, + 'n': False, + 'no': False, + 'f': False, + 'false': False, + 'off': False, + '0': False +} + + +def strtobool(value): + try: + return _MAP[str(value).lower()] + except KeyError: + raise ValueError('"{}" is not a valid bool value'.format(value))