From 62dc568d20f168343f329f52c4e85d76932f5c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20C=2E=20Barrionuevo=20da=20Luz?= Date: Fri, 30 Apr 2021 01:17:14 -0300 Subject: [PATCH] safely parse DEBUG environment variable --- inotify/adapters.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/inotify/adapters.py b/inotify/adapters.py index e8301da..80a92e3 100644 --- a/inotify/adapters.py +++ b/inotify/adapters.py @@ -4,6 +4,7 @@ import struct import collections import time +from distutils.util import strtobool from errno import EINTR @@ -34,7 +35,15 @@ ]) _STRUCT_HEADER_LENGTH = struct.calcsize(_HEADER_STRUCT_FORMAT) -_IS_DEBUG = bool(int(os.environ.get('DEBUG', '0'))) + +def _cast_boolean(value): + """ + Helper to convert config values to boolean as ConfigParser do. + """ + value = str(value) + return bool(value) if value == '' else bool(strtobool(value)) + +_IS_DEBUG = _cast_boolean(os.environ.get('DEBUG', '0')) class EventTimeoutException(Exception):