1
0
mirror of https://github.com/gryf/wicd.git synced 2026-02-08 17:35:54 +01:00

Fix unicode bugs with ESSIDs and keys

This commit is contained in:
David Paleino
2011-12-15 19:21:53 +01:00
parent 4f79658524
commit 69e9e92def
4 changed files with 22 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ reusable for other purposes as well.
import sys, os
from ConfigParser import RawConfigParser, ParsingError
import codecs
from wicd.misc import Noneify, to_unicode
@@ -116,6 +117,7 @@ class ConfigManager(RawConfigParser):
if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws)
and ret.endswith(self.mrk_ws)):
ret = ret[3:-3]
ret = to_unicode(ret)
if default:
if self.debug:
print ''.join(['found ', option, ' in configuration ',
@@ -175,7 +177,8 @@ class ConfigManager(RawConfigParser):
in the '.d' directory are read in normal sorted order and section
entries in these files override entries in the main file.
"""
RawConfigParser.read(self, path)
if os.path.exists(path):
RawConfigParser.readfp(self, codecs.open(path, 'r', 'utf-8'))
path_d = path + ".d"
files = []
@@ -186,7 +189,7 @@ class ConfigManager(RawConfigParser):
for fname in files:
p = RawConfigParser()
p.read(fname)
p.readfp(codecs.open(fname, 'r', 'utf-8'))
for section_name in p.sections():
# New files override old, so remove first to avoid DuplicateSectionError.
self.remove_section(section_name)

View File

@@ -413,7 +413,7 @@ def noneToString(text):
if text in (None, ""):
return "None"
else:
return str(text)
return to_unicode(text)
def to_unicode(x):
""" Attempts to convert a string to utf-8. """
@@ -422,6 +422,19 @@ def to_unicode(x):
return x
if isinstance(x, unicode):
return x.encode('utf-8')
# FIXME: this is a workaround to correctly parse utf-8
# encoded ESSIDs returned by iwlist -- python replaces
# \xNN with \\xNN, thus losing the characters :/.
# It should really be handled in a better way. Maybe
# using index()/find()?
if '\\' in x:
begin = x.split('\\x')[:1]
chars = x.split('\\x')[1:]
end = [chars[-1][2:]]
chars[-1] = chars[-1][:2]
x = ''.join(begin + map(lambda c: chr(int(c, 16)), chars) + end)
encoding = locale.getpreferredencoding()
try:
ret = x.decode(encoding).encode('utf-8')

View File

@@ -274,10 +274,10 @@ class ConnectionStatus(object):
if wired.CheckIfWiredConnecting():
info = ["wired"]
else:
info = ["wireless", str(wireless.GetCurrentNetwork(iwconfig))]
info = ["wireless", wireless.GetCurrentNetwork(iwconfig)]
elif state == misc.WIRELESS:
self.reconnect_tries = 0
info = [str(wifi_ip), str(wireless.GetCurrentNetwork(iwconfig)),
info = [str(wifi_ip), wireless.GetCurrentNetwork(iwconfig),
str(self._get_printable_sig_strength()),
str(wireless.GetCurrentNetworkID(iwconfig)),
wireless.GetCurrentBitrate(iwconfig)]

View File

@@ -1502,8 +1502,7 @@ class BaseWirelessInterface(BaseInterface):
output = self.GetIwconfig()
else:
output = iwconfig
network = misc.RunRegex(re.compile('.*ESSID:"(.*?)"',
re.I | re.M | re.S), output)
network = misc.to_unicode(misc.RunRegex(essid_pattern, output))
if network:
network = misc.to_unicode(network)
return network