problems with Turkish locale with a third party frontend
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ufw |
Fix Released
|
Undecided
|
Jamie Strandboge |
Bug Description
ufw 0.30.1
original bug report here: http://
ufw-frontends ( http://
It works without any problem - unless it's run in Turkish (tr_TR.UTF-8) locale.
I'm filing the bug report for ufw, not there for the reasons:
a) it works in ufw because for some reason locale inside _get_defaults() in backend.py is reset, so no tr_TR.UTF-8 that causing the problem there. If something changes in the future, ufw will suffer this bug too;
b) someone who knows Python well, after quick review agreed it seems more of a bug in UFW and suggests using UTF-8 encoding for files (snippet below).
Of course you know UFW best and what to think about it, but please take a look.
Now about the problem.
Consider the following:
python -c 'import locale; locale.
if "STRING" is not u"nicode string", it prints "strIng". This is exactly what happens in UFW backend when ran from ufw-frontends.
Result is this message:
Missing policy for 'input'
on command line when one tries to run, for example, "ufw status".
Problem is in backend.py, here:
174 def _get_defaults(
175 '''Get all settings from defaults file'''
176 self.defaults = {}
177 for f in [self.files[
178 try:
179 orig = ufw.util.
180 except Exception:
181 err_msg = _("Couldn't open '%s' for reading") % (f)
182 raise UFWError(err_msg)
183 pat = re.compile(
184 for line in orig:
185 if pat.search(line):
186 tmp = re.split(r'=', line.strip())
187 self.defaults[
line 187 and the lower() function.
Maybe-solutions out of my head:
a) set LC_CTYPE to C.
b) use .decode() and .encode()?
and from that guy mentioned above, which I have tested mostly and does the job:
--- src/util.py
+++ src/util.py
@@ -205,8 +205,9 @@
def open_file_read(f):
'''Opens the specified file read-only'''
+ import codecs
try:
- orig = open(f, 'r')
+ orig = codecs.open(f, 'r', "UTF-8")
except Exception:
raise
Thank you for the excellent bug report. I'll get this fixed up in the next version of ufw.