From patchwork Thu Aug 4 18:34:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 9264063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99E3A6048B for ; Thu, 4 Aug 2016 18:38:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A9A7283E4 for ; Thu, 4 Aug 2016 18:38:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EE352841F; Thu, 4 Aug 2016 18:38:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.nsa.gov [8.44.101.8]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB626283E4 for ; Thu, 4 Aug 2016 18:38:42 +0000 (UTC) Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 04 Aug 2016 18:38:41 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IcegM012031; Thu, 4 Aug 2016 14:38:40 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u74IYkdG250318 for ; Thu, 4 Aug 2016 14:34:46 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IYmrk011375 for ; Thu, 4 Aug 2016 14:34:48 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BUAQBGiqNXdMHAVdFcHAEBgnqBA3yxLIVkhAwghX0CgUhMAQEBAQEBEwEKCxQXhRACAQMSCCYBATcBD0ARNAEFARw7iA8BoRSBMj4xilSFKgEBBYtFAQEBAQYCARwIEIQPjWELgweIKoVydIophhqIamWBUocNhXqOaTCBD4JZggJhAYcqAQEB X-IPAS-Result: A1BUAQBGiqNXdMHAVdFcHAEBgnqBA3yxLIVkhAwghX0CgUhMAQEBAQEBEwEKCxQXhRACAQMSCCYBATcBD0ARNAEFARw7iA8BoRSBMj4xilSFKgEBBYtFAQEBAQYCARwIEIQPjWELgweIKoVydIophhqIamWBUocNhXqOaTCBD4JZggJhAYcqAQEB X-IronPort-AV: E=Sophos;i="5.28,471,1464667200"; d="scan'208";a="5626389" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 04 Aug 2016 14:35:35 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 04 Aug 2016 18:34:46 +0000 Received: by mail-pf0-f193.google.com with SMTP id y134so18686607pfg.3 for ; Thu, 04 Aug 2016 11:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perfinion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3HTzufstB3NTNJNOs+MAJD0kLCbSI0GPDe99B0kUEeg=; b=khjmMYZsk+KO5UZibM+ZCkzw113mtFkw4oqMBuchJGuiz5JEEKIOpSHkaO+da1NK15 zvXdoQKmia8Mg5oRD9/PseynD+naV2J82M4mzifyZtipxAU3ThVOGctQiF2eqqehIpBt wOdWabHkWHkiZ4WhcwcyZnNMbthUxDblSAFYM9UR4iBUAEJVKsY0XHNVwgtvwwk0kmuo MPpDn2mx470IMzbqsiLedX0uXRM+CmuoLXgDnjeLNgIxrT6H/kBk/7Db++LtetgvIz71 6+5X+UoqDWENM5K3D3CINGozoWvFzIc7ugaxg13tJtmdU9P+hCJoLfS+15x0vrOkxUAX bUfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3HTzufstB3NTNJNOs+MAJD0kLCbSI0GPDe99B0kUEeg=; b=N7y5S/cVI5+vq2Uh5sa7fCn/0mnzRzVs6e55NxBJPT/aKzz+vo7t3VPIuoaCu1ABCG IiH1HOlE3pOHUD8hz0BsnX2ttn6/S+T7BiDvWQ0CLL+JkeABz4dmT6AMmsV2gvPunIHz zXARu8Sx0Foaa9HlWe6+jjlK9/jF30PYPYEpcuLn3VHmMZkMe+gqfxgW5aZCMacFtD7x VYCsthIHtgBweLWdoTp4eOkuttnlKJrrqynF43uOBJ+KkPj9dUbd+FtPGWwdkEnFgsSH oMFd6pzhyi5KP7oeUca9OnWDiYycIk0Et6XG40dV3/2Fw+rWuJS7yn/x/f6nyztQt0of CKhA== X-Gm-Message-State: AEkoouvMhGVXcfvZJPvYRQaR8WdUat1HHPAXwDqBJmzQju6hNRuf6wefn2vr/uXeVe84YQ== X-Received: by 10.98.28.142 with SMTP id c136mr127876312pfc.131.1470335685950; Thu, 04 Aug 2016 11:34:45 -0700 (PDT) Received: from localhost ([2404:e800:e600:57b:dcfa:b5a4:c9d2:f744]) by smtp.gmail.com with ESMTPSA id p64sm22089664pfd.11.2016.08.04.11.34.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 11:34:45 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 09/12] policycoreutils: gettext compat for py2 and 3 Date: Fri, 5 Aug 2016 02:34:02 +0800 Message-Id: <1470335645-24224-10-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1470335645-24224-1-git-send-email-jason@perfinion.com> References: <1470335645-24224-1-git-send-email-jason@perfinion.com> X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP Install gettext the same way everywhere and have fallbacks to use str/unicode depending on python version. --- policycoreutils/gui/booleansPage.py | 22 +++++++++++++--------- policycoreutils/gui/domainsPage.py | 21 +++++++++++++-------- policycoreutils/gui/fcontextPage.py | 22 +++++++++++++--------- policycoreutils/gui/loginsPage.py | 21 +++++++++++++-------- policycoreutils/gui/mappingsPage.py | 21 +++++++++++++-------- policycoreutils/gui/modulesPage.py | 21 +++++++++++++-------- policycoreutils/gui/polgengui.py | 22 +++++++++++++--------- policycoreutils/gui/portsPage.py | 25 +++++++++++++------------ policycoreutils/gui/semanagePage.py | 21 +++++++++++++-------- policycoreutils/gui/statusPage.py | 24 ++++++++++++++++-------- policycoreutils/gui/system-config-selinux.py | 22 +++++++++++++--------- policycoreutils/gui/usersPage.py | 22 +++++++++++++++------- policycoreutils/sandbox/sandbox | 15 ++++++++------- policycoreutils/scripts/chcat | 13 ++++++++++--- policycoreutils/semanage/semanage | 4 ++-- policycoreutils/semanage/seobject.py | 23 ++++++++++++++++------- policycoreutils/sepolicy/sepolicy.py | 21 +++++++++++++-------- policycoreutils/sepolicy/sepolicy/__init__.py | 23 ++++++++++++++--------- policycoreutils/sepolicy/sepolicy/generate.py | 22 +++++++++++++--------- policycoreutils/sepolicy/sepolicy/gui.py | 21 +++++++++++++-------- policycoreutils/sepolicy/sepolicy/interface.py | 22 +++++++++++++--------- 21 files changed, 263 insertions(+), 165 deletions(-) diff --git a/policycoreutils/gui/booleansPage.py b/policycoreutils/gui/booleansPage.py index 507a79d..7057ff4 100644 --- a/policycoreutils/gui/booleansPage.py +++ b/policycoreutils/gui/booleansPage.py @@ -40,18 +40,22 @@ DISABLED = 2 ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode from glob import fnmatch diff --git a/policycoreutils/gui/domainsPage.py b/policycoreutils/gui/domainsPage.py index 9992d00..8f113ce 100644 --- a/policycoreutils/gui/domainsPage.py +++ b/policycoreutils/gui/domainsPage.py @@ -32,17 +32,22 @@ from semanagePage import * ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class domainsPage(semanagePage): diff --git a/policycoreutils/gui/fcontextPage.py b/policycoreutils/gui/fcontextPage.py index c8d6ba8..2b95099 100644 --- a/policycoreutils/gui/fcontextPage.py +++ b/policycoreutils/gui/fcontextPage.py @@ -47,18 +47,22 @@ class context: ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class fcontextPage(semanagePage): diff --git a/policycoreutils/gui/loginsPage.py b/policycoreutils/gui/loginsPage.py index 982e252..8e0b7a2 100644 --- a/policycoreutils/gui/loginsPage.py +++ b/policycoreutils/gui/loginsPage.py @@ -30,17 +30,22 @@ from semanagePage import * ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class loginsPage(semanagePage): diff --git a/policycoreutils/gui/mappingsPage.py b/policycoreutils/gui/mappingsPage.py index 1429bf7..3b4ceb6 100644 --- a/policycoreutils/gui/mappingsPage.py +++ b/policycoreutils/gui/mappingsPage.py @@ -28,17 +28,22 @@ import seobject ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class loginsPage: diff --git a/policycoreutils/gui/modulesPage.py b/policycoreutils/gui/modulesPage.py index 3b83e45..c7c7848 100644 --- a/policycoreutils/gui/modulesPage.py +++ b/policycoreutils/gui/modulesPage.py @@ -32,17 +32,22 @@ from subprocess import Popen, PIPE ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class modulesPage(semanagePage): diff --git a/policycoreutils/gui/polgengui.py b/policycoreutils/gui/polgengui.py index 1c349a7..1f97ada 100644 --- a/policycoreutils/gui/polgengui.py +++ b/policycoreutils/gui/polgengui.py @@ -58,18 +58,22 @@ def get_all_modules(): ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode gnome.program_init("SELinux Policy Generation Tool", "5") diff --git a/policycoreutils/gui/portsPage.py b/policycoreutils/gui/portsPage.py index 8e74ac0..7e7a653 100644 --- a/policycoreutils/gui/portsPage.py +++ b/policycoreutils/gui/portsPage.py @@ -30,21 +30,22 @@ from semanagePage import * ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) -TYPE_COL = 0 -PROTOCOL_COL = 1 -MLS_COL = 2 -PORT_COL = 3 try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class portsPage(semanagePage): diff --git a/policycoreutils/gui/semanagePage.py b/policycoreutils/gui/semanagePage.py index 5d7f2cf..d07ce27 100644 --- a/policycoreutils/gui/semanagePage.py +++ b/policycoreutils/gui/semanagePage.py @@ -28,17 +28,22 @@ import seobject ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode def idle_func(): diff --git a/policycoreutils/gui/statusPage.py b/policycoreutils/gui/statusPage.py index 991d8f3..de27752 100644 --- a/policycoreutils/gui/statusPage.py +++ b/policycoreutils/gui/statusPage.py @@ -23,6 +23,7 @@ import os import gobject import sys import tempfile +import selinux INSTALLPATH = '/usr/share/system-config-selinux' sys.path.append(INSTALLPATH) @@ -40,15 +41,22 @@ RELABELFILE = "/.autorelabel" ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) -import selinux try: - gettext.install(PROGNAME, localedir="/usr/share/locale", unicode=1) -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True + gettext.install(PROGNAME, + localedir="/usr/share/locale", + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class statusPage: diff --git a/policycoreutils/gui/system-config-selinux.py b/policycoreutils/gui/system-config-selinux.py index 7d342d0..8d2be13 100644 --- a/policycoreutils/gui/system-config-selinux.py +++ b/policycoreutils/gui/system-config-selinux.py @@ -47,18 +47,22 @@ import selinux ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode gnome.program_init("SELinux Management Tool", "5") diff --git a/policycoreutils/gui/usersPage.py b/policycoreutils/gui/usersPage.py index abf8d3b..eb978ea 100644 --- a/policycoreutils/gui/usersPage.py +++ b/policycoreutils/gui/usersPage.py @@ -30,14 +30,22 @@ from semanagePage import * ## I18N ## PROGNAME = "policycoreutils" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: - gettext.install(PROGNAME, localedir="/usr/share/locale", unicode=1) -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True + gettext.install(PROGNAME, + localedir="/usr/share/locale", + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode class usersPage(semanagePage): diff --git a/policycoreutils/sandbox/sandbox b/policycoreutils/sandbox/sandbox index 9e0024f..4f5128a 100644 --- a/policycoreutils/sandbox/sandbox +++ b/policycoreutils/sandbox/sandbox @@ -35,18 +35,19 @@ from tempfile import mkdtemp import pwd import sepolicy -PROGNAME = "policycoreutils" SEUNSHARE = "/usr/sbin/seunshare" SANDBOXSH = "/usr/share/sandbox/sandboxX.sh" -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) - +PROGNAME = "policycoreutils" try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - codeset='utf-8') -except IOError: + codeset='utf-8', + **kwargs) +except: try: import builtins builtins.__dict__['_'] = str diff --git a/policycoreutils/scripts/chcat b/policycoreutils/scripts/chcat index 267390e..2269ee0 100755 --- a/policycoreutils/scripts/chcat +++ b/policycoreutils/scripts/chcat @@ -30,11 +30,18 @@ import string import getopt import selinux import seobject -import gettext +PROGNAME = "policycoreutils" try: - gettext.install('policycoreutils') -except IOError: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True + gettext.install(PROGNAME, + localedir="/usr/share/locale", + codeset='utf-8', + **kwargs) +except: try: import builtins builtins.__dict__['_'] = str diff --git a/policycoreutils/semanage/semanage b/policycoreutils/semanage/semanage index e6e3a49..d945243 100644 --- a/policycoreutils/semanage/semanage +++ b/policycoreutils/semanage/semanage @@ -27,9 +27,9 @@ import traceback import argparse import seobject import sys -import gettext PROGNAME = "policycoreutils" try: + import gettext kwargs = {} if sys.version_info < (3,): kwargs['unicode'] = True @@ -37,7 +37,7 @@ try: localedir="/usr/share/locale", codeset='utf-8', **kwargs) -except IOError: +except: try: import builtins builtins.__dict__['_'] = str diff --git a/policycoreutils/semanage/seobject.py b/policycoreutils/semanage/seobject.py index 2cc56d9..bd261df 100644 --- a/policycoreutils/semanage/seobject.py +++ b/policycoreutils/semanage/seobject.py @@ -34,13 +34,22 @@ import sepolicy sepolicy.gen_bool_dict() from IPy import IP -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) - -import gettext -translation = gettext.translation(PROGNAME, localedir="/usr/share/locale", fallback=True) -_ = translation.ugettext +try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True + gettext.install(PROGNAME, + localedir="/usr/share/locale", + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode import syslog diff --git a/policycoreutils/sepolicy/sepolicy.py b/policycoreutils/sepolicy/sepolicy.py index 7d57f6e..3e502a7 100755 --- a/policycoreutils/sepolicy/sepolicy.py +++ b/policycoreutils/sepolicy/sepolicy.py @@ -27,18 +27,23 @@ import selinux import sepolicy from sepolicy import get_os_version, get_conditionals, get_conditionals_format_text import argparse -import gettext PROGNAME = "policycoreutils" -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode usage = "sepolicy generate [-h] [-n NAME] [-p PATH] [" usage_dict = {' --newtype': ('-t [TYPES [TYPES ...]]',), ' --customize': ('-d DOMAIN', '-a ADMIN_DOMAIN', "[ -w WRITEPATHS ]",), ' --admin_user': ('[-r TRANSITION_ROLE ]', "[ -w WRITEPATHS ]",), ' --application': ('COMMAND', "[ -w WRITEPATHS ]",), ' --cgi': ('COMMAND', "[ -w WRITEPATHS ]",), ' --confined_admin': ('-a ADMIN_DOMAIN', "[ -w WRITEPATHS ]",), ' --dbus': ('COMMAND', "[ -w WRITEPATHS ]",), ' --desktop_user': ('', "[ -w WRITEPATHS ]",), ' --inetd': ('COMMAND', "[ -w WRITEPATHS ]",), ' --init': ('COMMAND', "[ -w WRITEPATHS ]",), ' --sandbox': ("[ -w WRITEPATHS ]",), ' --term_user': ("[ -w WRITEPATHS ]",), ' --x_user': ("[ -w WRITEPATHS ]",)} diff --git a/policycoreutils/sepolicy/sepolicy/__init__.py b/policycoreutils/sepolicy/sepolicy/__init__.py index 6aec4c0..c8d3b90 100644 --- a/policycoreutils/sepolicy/sepolicy/__init__.py +++ b/policycoreutils/sepolicy/sepolicy/__init__.py @@ -6,8 +6,6 @@ from . import _policy import selinux import glob -PROGNAME = "policycoreutils" -import gettext import sepolgen.defaults as defaults import sepolgen.interfaces as interfaces import sys @@ -15,16 +13,23 @@ import os import re import gzip -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) +PROGNAME = "policycoreutils" try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode TYPE = _policy.TYPE ROLE = _policy.ROLE diff --git a/policycoreutils/sepolicy/sepolicy/generate.py b/policycoreutils/sepolicy/sepolicy/generate.py index 2d83702..00361c6 100644 --- a/policycoreutils/sepolicy/sepolicy/generate.py +++ b/policycoreutils/sepolicy/sepolicy/generate.py @@ -53,18 +53,22 @@ import sepolgen.defaults as defaults ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode def get_rpm_nvr_from_header(hdr): diff --git a/policycoreutils/sepolicy/sepolicy/gui.py b/policycoreutils/sepolicy/sepolicy/gui.py index 0ffe9ee..7f1888c 100644 --- a/policycoreutils/sepolicy/sepolicy/gui.py +++ b/policycoreutils/sepolicy/sepolicy/gui.py @@ -39,20 +39,25 @@ import sepolicy.manpage import dbus import os import re -import gettext import unicodedata PROGNAME = "policycoreutils" -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode reverse_file_type_str = {} for f in sepolicy.file_type_str: diff --git a/policycoreutils/sepolicy/sepolicy/interface.py b/policycoreutils/sepolicy/sepolicy/interface.py index 85f7351..c2cb971 100644 --- a/policycoreutils/sepolicy/sepolicy/interface.py +++ b/policycoreutils/sepolicy/sepolicy/interface.py @@ -33,18 +33,22 @@ __all__ = ['get_all_interfaces', 'get_interfaces_from_xml', 'get_admin', 'get_us ## I18N ## PROGNAME = "policycoreutils" - -import gettext -gettext.bindtextdomain(PROGNAME, "/usr/share/locale") -gettext.textdomain(PROGNAME) try: + import gettext + kwargs = {} + if sys.version_info < (3,): + kwargs['unicode'] = True gettext.install(PROGNAME, localedir="/usr/share/locale", - unicode=False, - codeset='utf-8') -except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + codeset='utf-8', + **kwargs) +except: + try: + import builtins + builtins.__dict__['_'] = str + except ImportError: + import __builtin__ + __builtin__.__dict__['_'] = unicode def get_interfaces_from_xml(path):