Fixed up the loading and saving of non-ascii values to the config file.

bzr-revno: 794
This commit is contained in:
Mattias Põldaru 2010-04-14 21:58:47 +02:00 committed by Raoul Snyman
commit 5708528ba0
2 changed files with 15 additions and 10 deletions

View File

@ -139,8 +139,9 @@ class PluginConfig(object):
list = [] list = []
if list_count > 0: if list_count > 0:
for counter in range(0, list_count): for counter in range(0, list_count):
item = unicode(self.get_config(u'%s %d' % (name, counter))) item = self.get_config(u'%s %d' % (name, counter))
list.append(item) if item:
list.append(item)
return list return list
def set_list(self, name, list): def set_list(self, name, list):

View File

@ -41,15 +41,17 @@ class Registry(object):
""" """
Check if a value exists. Check if a value exists.
""" """
return self.config.has_option(section, key) return self.config.has_option(section.encode('utf-8'),
key.encode('utf-8'))
def get_value(self, section, key, default=None): def get_value(self, section, key, default=None):
""" """
Get a single value from the registry. Get a single value from the registry.
""" """
try: try:
if self.config.get(section, key): if self.config.get(section.encode('utf-8'), key.encode('utf-8')):
return self.config.get(section, key) return self.config.get(section.encode('utf-8'),
key.encode('utf-8')).decode('utf-8')
else: else:
return default return default
except: except:
@ -60,7 +62,8 @@ class Registry(object):
Set a single value in the registry. Set a single value in the registry.
""" """
try : try :
self.config.set(section, key, unicode(value)) self.config.set(section.encode('utf-8'), key.encode('utf-8'),
unicode(value).encode('utf-8'))
return self._save() return self._save()
except: except:
return False return False
@ -70,7 +73,8 @@ class Registry(object):
Delete a single value from the registry. Delete a single value from the registry.
""" """
try: try:
self.config.remove_option(section, key) self.config.remove_option(section.encode('utf-8'),
key.encode('utf-8'))
return self._save() return self._save()
except: except:
return False return False
@ -79,14 +83,14 @@ class Registry(object):
""" """
Check if a section exists. Check if a section exists.
""" """
return self.config.has_section(section) return self.config.has_section(section.encode('utf-8'))
def create_section(self, section): def create_section(self, section):
""" """
Create a new section in the registry. Create a new section in the registry.
""" """
try: try:
self.config.add_section(section) self.config.add_section(section.encode('utf-8'))
return self._save() return self._save()
except: except:
return False return False
@ -96,7 +100,7 @@ class Registry(object):
Delete a section (including all values). Delete a section (including all values).
""" """
try: try:
self.config.remove_section(section) self.config.remove_section(section.encode('utf-8'))
return self._save() return self._save()
except: except:
return False return False