3
3
Copyright (c) 2019 InnoGames GmbH
4
4
"""
5
5
6
- from distutils .util import strtobool
7
6
from ipaddress import IPv4Address , IPv4Network , IPv6Address , IPv6Network
8
7
from itertools import chain
9
8
from types import GeneratorType
@@ -461,7 +460,7 @@ def set(self, key, value):
461
460
if isinstance (self [key ], MultiAttr ):
462
461
self [key ].add (value )
463
462
elif type (self [key ]) is bool :
464
- self [key ] = bool ( strtobool (value ) )
463
+ self [key ] = strtobool (value )
465
464
elif type (self [key ]) is int :
466
465
self [key ] = int (value )
467
466
else :
@@ -595,3 +594,21 @@ def _format_attribute_value(value):
595
594
if isinstance (value , dict ):
596
595
return _format_obj (value )
597
596
return json_to_datatype (value )
597
+
598
+
599
+ def strtobool (val ) -> bool :
600
+ """
601
+ Convert a string representation of truth to true or false.
602
+ Acts the same as distutils.util.strtobool, which was removed in Python 3.12.
603
+
604
+ True values are 'y', 'yes', 't', 'true', 'on', and '1';
605
+ false values are 'n', 'no', 'f', 'false', 'off', and '0'.
606
+ Raises ValueError if 'val' is anything else.
607
+ """
608
+ val = val .lower ()
609
+ if val in ('y' , 'yes' , 't' , 'true' , 'on' , '1' ):
610
+ return True
611
+ elif val in ('n' , 'no' , 'f' , 'false' , 'off' , '0' ):
612
+ return False
613
+ else :
614
+ raise ValueError (f"invalid truth value { val } " )
0 commit comments