Skip to contentSkip to conversation

translation patch for semanage

PATCH Daniel J Walsh 2 participants 4 messages Jan 11, 2007 – Jan 16, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

This patch works around a unicode problem in python.

semanage/semanage +12 -3
@@ -23,12 +23,21 @@
 import os, sys, getopt
 import seobject
 import selinux
+PROGNAME="policycoreutils"
+
 import gettext
+gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
+gettext.textdomain(PROGNAME)
+import codecs
+import locale
+sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.__stderr__, 'replace')
+sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.__stdout__, 'replace')
 
 try:
-       gettext.install('policycoreutils')
-except:
-       pass
+       gettext.install(PROGNAME, localedir="/usr/share/locale", unicode=1)
+except IOError:
+       import __builtin__
+       __builtin__.__dict__['_'] = unicode
 
 is_mls_enabled=selinux.is_selinux_mls_enabled()
 
#1 lore raw
Quoted 1 line · Daniel J Walsh

This patch works around a unicode problem in python.

Can you give a little more detail - perhaps a BZ? It appears that this patch and the seobject patch or to force all translated strings to be unicode and output as unicode, correct? Why is this necessary?

semanage/semanage line 29

Quoted 12 lines

--- nsapolicycoreutils/semanage/semanage 2006-11-16
17:14:26.000000000 -0500
+++ policycoreutils-1.33.10/semanage/semanage 2007-01-09
11:55:52.000000000 -0500

semanage/semanage +3 -0
@@ -23,12 +23,21 @@
 import os, sys, getopt
 import seobject
 import selinux
+PROGNAME="policycoreutils"
+
 import gettext
+gettext.bindtextdomain(PROGNAME, "/usr/share/locale")

Why is the location of the local files being forced? Is this appropriate for all distros or does it need to be configurable?

Review line 38

Quoted 10 lines
(quoted diff) +5 -0
+gettext.textdomain(PROGNAME)
+import codecs
+import locale
+sys.stderr =
 codecs.getwriter(locale.getpreferredencoding())(sys.__stderr__,
 'replace')
+sys.stdout =
 codecs.getwriter(locale.getpreferredencoding())(sys.__stdout__,
 'replace')

Is this related to
http://mail.python.org/pipermail/pythonmac-sig/2004-March/010651.html?
I.e., is this to force the encoding rather than relying on the term to correctly communicate that it supports unicode / utf8 / etc.?

If so, is this the "right" fix or just expedient?

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 9 lines · Karl MacMillan
Quoted 2 lines · Daniel J Walsh

This patch works around a unicode problem in python.

Can you give a little more detail - perhaps a BZ? It appears that this patch and the seobject patch or to force all translated strings to be unicode and output as unicode, correct? Why is this necessary?

No this patch forces all output strings to be the locale default. So it basically does the right thing. BTW print works correctly.

I can not find any matching bugs on python source forge but trying to login there is causing me no end of head aches. Asking people in the know around here, I get this response

+import codecs

Quoted 5 lines
(quoted diff) +2 -0
+import locale
+sys.stderr =

codecs.getwriter(locale.getpreferredencoding())(sys.__stderr__,'replace')

I was told by Ray that you knew about this problem in python? Do you know if this is an open bug?

Don't know if it's an open bug per se; other than python is well known to be broken w/ respect to codecs.

Thanks,
-Jonathan

Quoted 35 lines
Quoted 6 lines

--- nsapolicycoreutils/semanage/semanage 2006-11-16
17:14:26.000000000 -0500
+++ policycoreutils-1.33.10/semanage/semanage 2007-01-09
11:55:52.000000000 -0500

semanage/semanage line 30

Quoted 8 lines
semanage/semanage +3 -0
@@ -23,12 +23,21 @@
 import os, sys, getopt
 import seobject
 import selinux
+PROGNAME="policycoreutils"
+
 import gettext
+gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
 

Why is the location of the local files being forced? Is this appropriate for all distros or does it need to be configurable?

Review line 40

Quoted 10 lines
(quoted diff) +5 -0
+gettext.textdomain(PROGNAME)
+import codecs
+import locale
+sys.stderr =
 codecs.getwriter(locale.getpreferredencoding())(sys.__stderr__,
 'replace')
+sys.stdout =
 codecs.getwriter(locale.getpreferredencoding())(sys.__stdout__,
 'replace')
 

Is this related to
http://mail.python.org/pipermail/pythonmac-sig/2004-March/010651.html?
I.e., is this to force the encoding rather than relying on the term to correctly communicate that it supports unicode / utf8 / etc.?

Quoted 7 lines

If so, is this the "right" fix or just expedient?

Karl

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
In reply to Daniel J Walsh
Quoted 2 lines · Daniel J Walsh

This patch works around a unicode problem in python.

Both this patch and the related seobject patch are merged as of policycoreutils 1.33.13.

Karl

Quoted 20 lines

------------------------------------------------------------------------

semanage/semanage +8 -0
@@ -23,12 +23,21 @@
 import os, sys, getopt
 import seobject
 import selinux
+PROGNAME="policycoreutils"
+
 import gettext
+gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
+gettext.textdomain(PROGNAME)
+import codecs
+import locale
+sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.__stderr__, 'replace')
+sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.__stdout__, 'replace')
 
 try:

semanage/semanage line 43

Quoted 10 lines
semanage/semanage +4 -3
-       gettext.install('policycoreutils')
-except:
-       pass
+       gettext.install(PROGNAME, localedir="/usr/share/locale", unicode=1)
+except IOError:
+       import __builtin__
+       __builtin__.__dict__['_'] = unicode
 
 is_mls_enabled=selinux.is_selinux_mls_enabled()
 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.