40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
|
def format_prefs(input_string):
|
||
|
# Split the input string by newlines to get individual lines
|
||
|
lines = input_string.strip().split('\n')
|
||
|
formatted_lines = []
|
||
|
|
||
|
for line in lines:
|
||
|
# Split each line by space to separate the key and value
|
||
|
parts = line.split(' ')
|
||
|
key = parts[0]
|
||
|
value = ' '.join(parts[1:])
|
||
|
|
||
|
# Format the value correctly based on its type
|
||
|
if value in ('true', 'false'):
|
||
|
formatted_value = value.lower() # Keep booleans lowercase
|
||
|
elif value.isdigit():
|
||
|
formatted_value = value # Keep integers as is
|
||
|
else:
|
||
|
# Wrap strings in quotes, unless they are already wrapped
|
||
|
formatted_value = value if value.startswith('"') and value.endswith('"') else f'"{value}"'
|
||
|
|
||
|
# Create the formatted preference string
|
||
|
formatted_line = f'user_pref("{key}", {formatted_value});'
|
||
|
formatted_lines.append(formatted_line)
|
||
|
|
||
|
# Join the formatted lines back together with newlines
|
||
|
return '\n'.join(formatted_lines)
|
||
|
|
||
|
# Example usage:
|
||
|
input_string = """
|
||
|
browser.safebrowsing.malware.enabled false
|
||
|
browser.safebrowsing.phishing.enabled false
|
||
|
browser.safebrowsing.downloads.enabled false
|
||
|
browser.safebrowsing.downloads.remote.enabled false
|
||
|
browser.safebrowsing.downloads.remote.url ""
|
||
|
browser.safebrowsing.downloads.remote.block_potentially_unwanted false
|
||
|
browser.safebrowsing.downloads.remote.block_uncommon false
|
||
|
browser.safebrowsing.allowOverride false
|
||
|
"""
|
||
|
|
||
|
print(format_prefs(input_string))
|