Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes-issue-34 #164

Open
wants to merge 1 commit into
base: 5.2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@
from urllib.parse import urlparse
import logging


def json_decomment(json_obj, prefix='#', null=False):
"""
Remove any JSON object emember whose name begins with 'prefix'
(default '#') and return the result. If 'null' is True, replace
the prefixed items with a null value instead of deleting them.
"""
if type(json_obj) is dict:
result = {}
for item in json_obj.keys():
if item.startswith(prefix):
if null:
result[item] = None
else:
next
else:
result[item] = json_decomment(json_obj[item], prefix=prefix, null=null)
return result
elif type(json_obj) is list:
result = []
for item in json_obj:
result.append(json_decomment(item, prefix=prefix, null=null))
return result
else:
return json_obj


class BaseConnect(object):

def __init__(self, **kwargs):
Expand Down Expand Up @@ -133,6 +160,8 @@ def _raw_config_to_psconfig(self, raw_config):

try:
json_obj = json.loads(raw_config)
# remove comments
json_obj = json_decomment(json_obj)
except Exception as e:
json_error = e

Expand Down
Loading