mirror of
https://github.com/gryf/wicd.git
synced 2026-04-24 07:01:27 +02:00
Fix unicode bugs with ESSIDs and keys
This commit is contained in:
@@ -28,6 +28,7 @@ reusable for other purposes as well.
|
|||||||
import sys, os
|
import sys, os
|
||||||
|
|
||||||
from ConfigParser import RawConfigParser, ParsingError
|
from ConfigParser import RawConfigParser, ParsingError
|
||||||
|
import codecs
|
||||||
|
|
||||||
from wicd.misc import Noneify, to_unicode
|
from wicd.misc import Noneify, to_unicode
|
||||||
|
|
||||||
@@ -116,6 +117,7 @@ class ConfigManager(RawConfigParser):
|
|||||||
if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws)
|
if (isinstance(ret, basestring) and ret.startswith(self.mrk_ws)
|
||||||
and ret.endswith(self.mrk_ws)):
|
and ret.endswith(self.mrk_ws)):
|
||||||
ret = ret[3:-3]
|
ret = ret[3:-3]
|
||||||
|
ret = to_unicode(ret)
|
||||||
if default:
|
if default:
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print ''.join(['found ', option, ' in configuration ',
|
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
|
in the '.d' directory are read in normal sorted order and section
|
||||||
entries in these files override entries in the main file.
|
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"
|
path_d = path + ".d"
|
||||||
files = []
|
files = []
|
||||||
@@ -186,7 +189,7 @@ class ConfigManager(RawConfigParser):
|
|||||||
|
|
||||||
for fname in files:
|
for fname in files:
|
||||||
p = RawConfigParser()
|
p = RawConfigParser()
|
||||||
p.read(fname)
|
p.readfp(codecs.open(fname, 'r', 'utf-8'))
|
||||||
for section_name in p.sections():
|
for section_name in p.sections():
|
||||||
# New files override old, so remove first to avoid DuplicateSectionError.
|
# New files override old, so remove first to avoid DuplicateSectionError.
|
||||||
self.remove_section(section_name)
|
self.remove_section(section_name)
|
||||||
|
|||||||
+14
-1
@@ -413,7 +413,7 @@ def noneToString(text):
|
|||||||
if text in (None, ""):
|
if text in (None, ""):
|
||||||
return "None"
|
return "None"
|
||||||
else:
|
else:
|
||||||
return str(text)
|
return to_unicode(text)
|
||||||
|
|
||||||
def to_unicode(x):
|
def to_unicode(x):
|
||||||
""" Attempts to convert a string to utf-8. """
|
""" Attempts to convert a string to utf-8. """
|
||||||
@@ -422,6 +422,19 @@ def to_unicode(x):
|
|||||||
return x
|
return x
|
||||||
if isinstance(x, unicode):
|
if isinstance(x, unicode):
|
||||||
return x.encode('utf-8')
|
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()
|
encoding = locale.getpreferredencoding()
|
||||||
try:
|
try:
|
||||||
ret = x.decode(encoding).encode('utf-8')
|
ret = x.decode(encoding).encode('utf-8')
|
||||||
|
|||||||
+2
-2
@@ -274,10 +274,10 @@ class ConnectionStatus(object):
|
|||||||
if wired.CheckIfWiredConnecting():
|
if wired.CheckIfWiredConnecting():
|
||||||
info = ["wired"]
|
info = ["wired"]
|
||||||
else:
|
else:
|
||||||
info = ["wireless", str(wireless.GetCurrentNetwork(iwconfig))]
|
info = ["wireless", wireless.GetCurrentNetwork(iwconfig)]
|
||||||
elif state == misc.WIRELESS:
|
elif state == misc.WIRELESS:
|
||||||
self.reconnect_tries = 0
|
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(self._get_printable_sig_strength()),
|
||||||
str(wireless.GetCurrentNetworkID(iwconfig)),
|
str(wireless.GetCurrentNetworkID(iwconfig)),
|
||||||
wireless.GetCurrentBitrate(iwconfig)]
|
wireless.GetCurrentBitrate(iwconfig)]
|
||||||
|
|||||||
+1
-2
@@ -1502,8 +1502,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
output = self.GetIwconfig()
|
output = self.GetIwconfig()
|
||||||
else:
|
else:
|
||||||
output = iwconfig
|
output = iwconfig
|
||||||
network = misc.RunRegex(re.compile('.*ESSID:"(.*?)"',
|
network = misc.to_unicode(misc.RunRegex(essid_pattern, output))
|
||||||
re.I | re.M | re.S), output)
|
|
||||||
if network:
|
if network:
|
||||||
network = misc.to_unicode(network)
|
network = misc.to_unicode(network)
|
||||||
return network
|
return network
|
||||||
|
|||||||
Reference in New Issue
Block a user