1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

fix to make None values always a blank string

This commit is contained in:
Kelly Brazil
2023-12-22 11:41:24 -08:00
parent 1868b28f74
commit 6dd5b29998
2 changed files with 18 additions and 10 deletions

View File

@ -75,7 +75,7 @@ import uuid
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '2.0'
version = '2.1'
description = 'INI file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -87,11 +87,18 @@ class info():
__version__ = info.version
def _remove_quotes(value):
if value is None:
value = ''
class MyDict(dict):
def __setitem__(self, key, value):
# convert None values to empty string
if value is None:
self[key] = ''
elif value.startswith('"') and value.endswith('"'):
else:
super().__setitem__(key, value)
def _remove_quotes(value):
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
elif value.startswith("'") and value.endswith("'"):
@ -146,6 +153,7 @@ def parse(data, raw=False, quiet=False):
if jc.utils.has_data(data):
ini_parser = configparser.ConfigParser(
dict_type = MyDict,
allow_no_value=True,
interpolation=None,
default_section=None,

View File

@ -97,7 +97,7 @@ import uuid
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.1'
version = '1.2'
description = 'INI with duplicate key file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -112,6 +112,9 @@ __version__ = info.version
class MultiDict(dict):
# https://stackoverflow.com/a/38286559/12303989
def __setitem__(self, key, value):
if value is None:
self[key] = ['']
if key in self:
if isinstance(value, list):
self[key].extend(value)
@ -125,10 +128,7 @@ class MultiDict(dict):
def _remove_quotes(value):
if value is None:
value = ''
elif value.startswith('"') and value.endswith('"'):
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
elif value.startswith("'") and value.endswith("'"):