From 2fbc23c1fd5a32153bf09b20b6a97a33bd228fbf Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 3 Apr 2024 13:42:43 +0200 Subject: [PATCH] packing our own strtobool --- 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 f5003a266..72750107c 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 92b4728c6..85e2b30e2 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 2ee0d44f1..24440908e 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 de1098999..89a2fc67b 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 3ad5f5f7c..91f133880 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 3515743e8..280231fbf 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 cdcb8ee0f..4d408c61c 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 602df5cc6..044090b75 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 3ef718ff1..e2b544811 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 24a0c4050..432021409 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 000000000..ffb6b9f93 --- /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))