ufw

problems with Turkish locale with a third party frontend

Bug #921758 reported by Sławomir Nizio
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ufw
Fix Released
Undecided
Jamie Strandboge

Bug Description

ufw 0.30.1
original bug report here: http://bugs.sabayon.org/show_bug.cgi?id=2952

ufw-frontends ( http://code.google.com/p/ufw-frontends/ ) is a nice third-party GUI frontend (currently Gtk+ only) for UFW.
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.setlocale(locale.LC_ALL, "tr_TR.UTF-8"); print "STRING".lower()'
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(self):
175 '''Get all settings from defaults file'''
176 self.defaults = {}
177 for f in [self.files['defaults'], self.files['conf']]:
178 try:
179 orig = ufw.util.open_file_read(f)
180 except Exception:
181 err_msg = _("Couldn't open '%s' for reading") % (f)
182 raise UFWError(err_msg)
183 pat = re.compile(r'^\w+="?\w+"?')
184 for line in orig:
185 if pat.search(line):
186 tmp = re.split(r'=', line.strip())
187 self.defaults[tmp[0].lower()] = tmp[1].lower().strip('"\ '')

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

Related branches

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thank you for the excellent bug report. I'll get this fixed up in the next version of ufw.

Changed in ufw:
assignee: nobody → Jamie Strandboge (jdstrand)
status: New → Triaged
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Patch to fix this issue.

Changed in ufw:
status: Triaged → In Progress
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Passes ufw test suite.

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

patch looks fine to me. ACK.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Fix committed to trunk. This will be included in the next release of ufw.

Changed in ufw:
status: In Progress → Fix Committed
Revision history for this message
Sławomir Nizio (snizio) wrote :

Awesome!

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

This should be fixed in 0.31.

Changed in ufw:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.