Exemple #1
0
 def _decode_value(self, key, value):
     type = self._key_types.get(key)
     if not type and key.startswith('X-'):
         # Try to guess it
         if value == 'true': return True
         elif value == 'false': return False
         else:
             try:
                 value = float(value)
                 return value
             except:
                 return json.loads('"%s"' % value.replace('"', r'\"')) # force string
     else:
         # Strict typing
         if not type or type == 'string':
             return json.loads('"%s"' % value.replace('"', r'\"')) # force string
         elif type == 'boolean':
             if value == 'true': return True
             else: return False # 'false' or invalid value
         elif type == 'numeric':
             try:
                 value = float(value)
                 return value
             except:
                 return 0 # invalid value
         else:
             assert False, 'BUG: unknown key type: %s' % type
	def _decode_desktop_value(self, value):
		if value == 'true': return True
		elif value == 'false': return False
		else:
			try:
				value = float(value)
				return value
			except:
				return json.loads('"%s"' % value.replace('"', '\\"')) # force string