mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Fixed encoding problems that would cause wicd to crash if a network returned an essid with exotic characters.
Reduced log spam, and altered how logging gets done a little bit. Cleaned up some comments, docstrings, etc.
This commit is contained in:
19
misc.py
19
misc.py
@@ -55,7 +55,7 @@ def RunRegex(regex, string):
|
||||
return None
|
||||
|
||||
def log(text):
|
||||
log = self.LogWriter()
|
||||
log = LogWriter()
|
||||
log.write(text + "\n")
|
||||
|
||||
def WriteLine(my_file, text):
|
||||
@@ -215,6 +215,19 @@ def get_gettext():
|
||||
_ = lang.gettext
|
||||
return _
|
||||
|
||||
|
||||
def to_unicode(x):
|
||||
try: # This may never fail, but let's be safe
|
||||
default_encoding = locale.getpreferredencoding()
|
||||
except:
|
||||
default_encoding = None
|
||||
if default_encoding:
|
||||
return x.decode(default_encoding).encode('utf-8')
|
||||
else:
|
||||
return x.decode('utf-8').encode('utf-8')
|
||||
|
||||
|
||||
|
||||
class LogWriter():
|
||||
""" A class to provide timestamped logging. """
|
||||
def __init__(self):
|
||||
@@ -260,7 +273,7 @@ class LogWriter():
|
||||
self.file.write(
|
||||
data.replace('\n', '\n' + self.get_time() + ' :: '))
|
||||
if self.eol: self.file.write('\n')
|
||||
self.file.flush()
|
||||
self.file.close()
|
||||
|
||||
|
||||
def get_time(self):
|
||||
@@ -273,4 +286,4 @@ class LogWriter():
|
||||
return ''.join([
|
||||
str(x[0]).rjust(4,'0'), '/', str(x[1]).rjust(2,'0'), '/',
|
||||
str(x[2]).rjust(2,'0'), ' ', str(x[3]).rjust(2,'0'), ':',
|
||||
str(x[4]).rjust(2,'0'), ':', str(x[5]).rjust(2,'0')])
|
||||
str(x[4]).rjust(2,'0'), ':', str(x[5]).rjust(2,'0')])
|
||||
|
||||
Reference in New Issue
Block a user