options_defaults.py 997 B

1234567891011121314151617181920212223242526
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. def parse_options_defaults(options, preferencesBranch):
  5. # this returns a unicode string
  6. pref_list = []
  7. for pref in options:
  8. if ('value' in pref):
  9. value = pref["value"]
  10. if isinstance(value, float):
  11. continue
  12. elif isinstance(value, bool):
  13. value = str(pref["value"]).lower()
  14. elif isinstance(value, str): # presumably ASCII
  15. value = "\"" + unicode(pref["value"]) + "\""
  16. elif isinstance(value, unicode):
  17. value = "\"" + pref["value"] + "\""
  18. else:
  19. value = str(pref["value"])
  20. pref_list.append("pref(\"extensions." + preferencesBranch + "." + pref["name"] + "\", " + value + ");")
  21. return "\n".join(pref_list) + "\n"