From 75219d78c47cbfc11f4b5ef27c9894c250e6f9d2 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 17 Jan 2009 12:58:02 -0500 Subject: [PATCH] Fix bug where encryption keys with non-ascii characters caused crashes. Only write settings being saved if debug mode is on. Clear keys entered through the GUI when the encryption checkbox is disabled. --- wicd/configmanager.py | 18 +++++++++++------- wicd/misc.py | 2 +- wicd/netentry.py | 7 +++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/wicd/configmanager.py b/wicd/configmanager.py index 6630773..c95b911 100644 --- a/wicd/configmanager.py +++ b/wicd/configmanager.py @@ -26,14 +26,15 @@ reusable for other purposes as well. from ConfigParser import RawConfigParser -from wicd.misc import stringToNone, Noneify +from wicd.misc import stringToNone, Noneify, to_unicode class ConfigManager(RawConfigParser): """ A class that can be used to manage a given configuration file. """ - def __init__(self, path): + def __init__(self, path, debug=False): RawConfigParser.__init__(self) self.config_file = path + self.debug = debug self.read(path) def __repr__(self): @@ -57,8 +58,9 @@ class ConfigManager(RawConfigParser): """ if not self.has_section(section): self.add_section(section) - - RawConfigParser.set(self, section, str(option), str(value)) + if isinstance(value, basestring): + value = to_unicode(value) + RawConfigParser.set(self, section, str(option), value) if save: self.write() @@ -80,11 +82,13 @@ class ConfigManager(RawConfigParser): if self.has_option(section, option): ret = RawConfigParser.get(self, section, option) if default: - print ''.join(['found ', option, ' in configuration ', ret]) + if self.debug: + print ''.join(['found ', option, ' in configuration ', + str(ret)]) else: if default != "__None__": - print ''.join(['did not find ', option, - ' in configuration, setting default ', str(default)]) + if self.debug: + print 'did not find %s in configuration, setting default %s' % (option, str(default)) self.set(section, option, str(default), save=True) ret = default else: diff --git a/wicd/misc.py b/wicd/misc.py index 595b171..5f7f928 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -318,7 +318,7 @@ def get_gettext(): def to_unicode(x): """ Attempts to convert a string to utf-8. """ # If this is a unicode string, encode it and return - if type(x) not in [unicode, str]: + if not isinstance(x, basestring): return x if isinstance(x, unicode): return x.encode('utf-8') diff --git a/wicd/netentry.py b/wicd/netentry.py index 68d9509..e000e93 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -471,17 +471,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): if encryption_info[x].get_text() == "": error(self, language['encrypt_info_missing']) return False - self.set_net_prop(x, noneToString(encryption_info[x]. - get_text())) + self.set_net_prop(x, noneToString(encryption_info[x].get_text())) elif not self.chkbox_encryption.get_active() and \ wireless.GetWirelessProperty(networkid, "encryption"): error(self, language['enable_encryption']) return False else: - print 'encryption is ' + str(wireless.GetWirelessProperty(networkid, - "encryption")) print "no encryption specified..." self.set_net_prop("enctype", "None") + for x in self.encryption_info: + self.set_net_prop(x, "") AdvancedSettingsDialog.save_settings(self) if self.chkbox_global_settings.get_active():