Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getproperties(fp, keys):
keys = set(keys)
def getprops(seq):
props = {}
for k,v in seq:
if k in keys:
props[k] = v
return props
return load(fp, object_pairs_hook=getprops)
def tojson(infile, outfile, encoding):
"""Convert a Java .properties file to JSON"""
with click.open_file(infile, encoding=encoding) as fp:
props = load(fp)
with outfile:
json.dump(props, outfile, sort_keys=True, indent=4,
separators=(',', ': '))
outfile.write('\n')
def format(outfile, separator, file, encoding):
""" Format/"canonicalize" a Java .properties file """
with click.open_file(file, encoding=encoding) as fpin:
with click.open_file(outfile, 'w', encoding=encoding) as fpout:
dump(load(fpin), fpout, sort_keys=True, separator=separator)