def quotevalue(self, value): """converts a realvalue from parsevalue back to a string that can be stored in the prefs file""" if isinstance(value, int) or isinstance(value, long): return str(value) elif isinstance(value, PrefNode): return value.getlabel() elif isinstance(value, UnresolvedPref): return repr(value) elif isinstance(value, str): return sparse.stringquote(value) elif isinstance(value, unicode): return "u" + sparse.stringquote(value.encode("utf-8")) elif value is None: return "" else: raise ValueError("don't know how to quote %r value: %r" % (type(value), value))
def writeDict(self, dictionary, indent): result = "" sortedKeys = dictionary.keys() sortedKeys.sort() for key in sortedKeys: quotedkey = key if isinstance(quotedkey, unicode): try: quotedkey = str(quotedkey) except UnicodeError: pass if isinstance(quotedkey, unicode): quotedkey = "u" + sparse.stringquote(quotedkey.encode("utf-8")) else: testalphakey = quotedkey.replace("_", "a").replace(".", "0") if not (testalphakey[:1].isalpha() and testalphakey.isalnum()): quotedkey = sparse.stringquote(quotedkey) if isinstance(dictionary[key], dict): result += indent + quotedkey + ":\n" result += self.writeDict(dictionary[key], indent + " ") else: result += indent + "%s = %s\n" % (quotedkey, dictionary[key]) return result
def writeDict(self, dictionary, indent): result = "" sortedKeys = dictionary.keys() sortedKeys.sort() for key in sortedKeys: quotedkey = key if isinstance(quotedkey, unicode): try: quotedkey = str(quotedkey) except UnicodeError: pass if isinstance(quotedkey, unicode): quotedkey = "u" + sparse.stringquote(quotedkey.encode("utf-8")) else: testalphakey = quotedkey.replace("_", "a").replace(".", "0") if not (testalphakey[:1].isalpha() and testalphakey.isalnum()): quotedkey = sparse.stringquote(quotedkey) if isinstance(dictionary[key], dict): result += indent + quotedkey + ":\n" result += self.writeDict(dictionary[key], indent+" ") else: result += indent + "%s = %s\n" % (quotedkey, dictionary[key]) return result