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

ini and kv parser: don't convert keynames to lowercase

This commit is contained in:
Kelly Brazil
2022-09-22 08:39:01 -07:00
parent 7ca0a511d5
commit 88222edb7f
6 changed files with 37 additions and 34 deletions

View File

@ -70,7 +70,7 @@ import configparser
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.7'
version = '1.8'
description = 'INI file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@ -145,6 +145,10 @@ def parse(data, raw=False, quiet=False):
ini = configparser.ConfigParser(allow_no_value=True,
interpolation=None,
strict=False)
# don't convert keys to lower-case:
ini.optionxform = lambda option: option
try:
ini.read_string(data)
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}

View File

@ -1 +1 @@
{"Settings": {"detailedlog": "1", "runstatus": "1", "statusport": "6090", "statusrefresh": "10", "archive": "1", "logfile": "/opt/ecs/mvuser/MV_IPTel/log/MV_IPTel.log", "version": "0.9 Build 4 Created July 11 2004 14:00", "servername": "Unknown"}, "FTP": {"runftp": "1", "ftpport": "21", "ftpdataport": "20", "ftpdir": "/opt/ecs/mvuser/MV_IPTel/data/FTPdata", "ftp_timeout": "5", "enablesu": "1", "suusername": "mvuser", "supassword": "Avaya"}, "FTPS": {"runftps": "0", "ftpport": "990", "ftpdataport": "889"}, "TFTP": {"runtrivialftp": "1", "trivialftpport": "69", "tftpdir": "/opt/ecs/mvuser/MV_IPTel/data/TFTPdata"}, "HTTP": {"runhttp": "1", "httpport": "81", "httpdir": "/opt/ecs/mvuser/MV_IPTel/data/HTTPdata"}, "HTTPS": {"runhttps": "0", "httpsport": "411", "httpsdir": "/opt/ecs/mvuser/MV_IPTel/data/HTTPSdata", "certfile": "/opt/ecs/mvuser/MV_IPTel/certs/IPTelcert.pem", "keyfile": "/opt/ecs/mvuser/MV_IPTel/certs/IPTelkey.pem", "clientauth": "0", "iptel": "0", "sslv2": "0", "sslv3": "0", "tlsv1": "1", "useproxy": "0", "proxyaddr": "simon.avaya.com", "proxyport": "9000"}, "BACKUP_SERVERS": {"fileserver": "0", "requestupdates": "0", "requestbackup": "0", "useprimarysvr": "0", "primaryip": "192.168.0.13", "usesecondarysvr": "0", "secondaryip": "192.168.0.10", "updateinterval": "2", "customftp": "1", "customftpdir": "home/mvuser/backup", "customftpuname": "tom", "customftppwd": "jerry", "cdrbackup": "0", "bcmsbackup": "0", "retaindays": "7.0"}, "SNMP": {"usesnmp": "1"}}
{"Settings":{"DetailedLog":"1","RunStatus":"1","StatusPort":"6090","StatusRefresh":"10","Archive":"1","LogFile":"/opt/ecs/mvuser/MV_IPTel/log/MV_IPTel.log","Version":"0.9 Build 4 Created July 11 2004 14:00","ServerName":"Unknown"},"FTP":{"RunFTP":"1","FTPPort":"21","FTPDataPort":"20","FTPDir":"/opt/ecs/mvuser/MV_IPTel/data/FTPdata","FTP_TimeOut":"5","EnableSU":"1","SUUserName":"mvuser","SUPassword":"Avaya"},"FTPS":{"RunFTPS":"0","FTPPort":"990","FTPDataPort":"889"},"TFTP":{"RunTrivialFTP":"1","TrivialFTPPort":"69","TFTPDir":"/opt/ecs/mvuser/MV_IPTel/data/TFTPdata"},"HTTP":{"RunHTTP":"1","HTTPPort":"81","HTTPDir":"/opt/ecs/mvuser/MV_IPTel/data/HTTPdata"},"HTTPS":{"RunHTTPS":"0","HTTPSPort":"411","HTTPSDir":"/opt/ecs/mvuser/MV_IPTel/data/HTTPSdata","CertFile":"/opt/ecs/mvuser/MV_IPTel/certs/IPTelcert.pem","KeyFile":"/opt/ecs/mvuser/MV_IPTel/certs/IPTelkey.pem","ClientAuth":"0","IPTel":"0","SSLV2":"0","SSLV3":"0","TLSV1":"1","UseProxy":"0","ProxyAddr":"simon.avaya.com","ProxyPort":"9000"},"BACKUP_SERVERS":{"FileServer":"0","RequestUpdates":"0","RequestBackup":"0","UsePrimarySvr":"0","PrimaryIP":"192.168.0.13","UseSecondarySvr":"0","SecondaryIP":"192.168.0.10","UpdateInterval":"2","CustomFTP":"1","CustomFTPDir":"home/mvuser/backup","CustomFTPUName":"tom","CustomFTPPwd":"jerry","CDRBackup":"0","BCMSBackup":"0","RetainDays":"7.0"},"SNMP":{"UseSNMP":"1"}}

View File

@ -1 +1 @@
{"bitbucket.org": {"serveraliveinterval": "45", "compression": "yes", "compressionlevel": "9", "forwardx11": "yes", "user": "hg"}, "topsecret.server.com": {"serveraliveinterval": "45", "compression": "yes", "compressionlevel": "9", "forwardx11": "no", "port": "50022"}}
{"bitbucket.org":{"ServerAliveInterval":"45","Compression":"yes","CompressionLevel":"9","ForwardX11":"yes","User":"hg"},"topsecret.server.com":{"ServerAliveInterval":"45","Compression":"yes","CompressionLevel":"9","ForwardX11":"no","Port":"50022"}}

View File

@ -1 +1 @@
{"type": "Ethernet", "proxy_method": "none", "browser_only": "no", "bootproto": "dhcp", "defroute": "yes", "ipv4_failure_fatal": "no", "ipv6init": "yes", "ipv6_autoconf": "yes", "ipv6_defroute": "yes", "ipv6_failure_fatal": "no", "ipv6_addr_gen_mode": "stable-privacy", "name": "ens33", "uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", "device": "ens33", "onboot": "yes", "value_with_spaces": "this value includes spaces", "value_with_quotes_inside": "this value \"has quotation marks\" inside", "value_with_quotes_inside2": "\"this value\" has quotations at the beginning but not the end", "value_with_quotes_inside3": "this value has quotation marks \"at the end\""}
{"TYPE":"Ethernet","PROXY_METHOD":"none","BROWSER_ONLY":"no","BOOTPROTO":"dhcp","DEFROUTE":"yes","IPV4_FAILURE_FATAL":"no","IPV6INIT":"yes","IPV6_AUTOCONF":"yes","IPV6_DEFROUTE":"yes","IPV6_FAILURE_FATAL":"no","IPV6_ADDR_GEN_MODE":"stable-privacy","NAME":"ens33","UUID":"d92ece08-9e02-47d5-b2d2-92c80e155744","DEVICE":"ens33","ONBOOT":"yes","value_with_spaces":"this value includes spaces","value_with_quotes_inside":"this value \"has quotation marks\" inside","value_with_quotes_inside2":"\"this value\" has quotations at the beginning but not the end","value_with_quotes_inside3":"this value has quotation marks \"at the end\""}

View File

@ -8,32 +8,31 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.ini'), 'r', encoding='utf-8') as f:
self.generic_ini_test = f.read()
generic_ini_test = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.ini'), 'r', encoding='utf-8') as f:
self.generic_ini_iptelserver = f.read()
generic_ini_iptelserver = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-double-quote.ini'), 'r', encoding='utf-8') as f:
self.generic_ini_double_quote = f.read()
generic_ini_double_quote = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-single-quote.ini'), 'r', encoding='utf-8') as f:
self.generic_ini_single_quote = f.read()
generic_ini_single_quote = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-test.json'), 'r', encoding='utf-8') as f:
self.generic_ini_test_json = json.loads(f.read())
generic_ini_test_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-iptelserver.json'), 'r', encoding='utf-8') as f:
self.generic_ini_iptelserver_json = json.loads(f.read())
generic_ini_iptelserver_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-double-quote.json'), 'r', encoding='utf-8') as f:
self.generic_ini_double_quote_json = json.loads(f.read())
generic_ini_double_quote_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/ini-single-quote.json'), 'r', encoding='utf-8') as f:
self.generic_ini_single_quote_json = json.loads(f.read())
generic_ini_single_quote_json = json.loads(f.read())
def test_ini_nodata(self):
"""

View File

@ -8,20 +8,20 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.txt'), 'r', encoding='utf-8') as f:
self.generic_ini_keyvalue = f.read()
generic_ini_keyvalue = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.txt'), 'r', encoding='utf-8') as f:
self.generic_ini_keyvalue_ifcfg = f.read()
generic_ini_keyvalue_ifcfg = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue.json'), 'r', encoding='utf-8') as f:
self.generic_ini_keyvalue_json = json.loads(f.read())
generic_ini_keyvalue_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/keyvalue-ifcfg.json'), 'r', encoding='utf-8') as f:
self.generic_ini_keyvalue_ifcfg_json = json.loads(f.read())
generic_ini_keyvalue_ifcfg_json = json.loads(f.read())
def test_kv_nodata(self):
"""