summaryrefslogtreecommitdiffstats
path: root/recipes-security/selinux/selinux-python/0001-gettext-handle-unsupported-languages-properly.patch
blob: b83300d587fff6b61443dfb80876e73ce1bd4981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From 4693794ff8c52f87a4abdb68fe9dae6618023c03 Mon Sep 17 00:00:00 2001
From: Vit Mojzis <vmojzis@redhat.com>
Date: Fri, 24 Jun 2022 16:24:25 +0200
Subject: [PATCH] gettext: handle unsupported languages properly

With "fallback=True" gettext.translation behaves the same as
gettext.install and uses NullTranslations in case the
translation file for given language was not found (as opposed to
throwing an exception).

Fixes:
  # LANG is set to any "unsupported" language, e.g. en_US.UTF-8
  $ chcat --help
  Traceback (most recent call last):
  File "/usr/bin/chcat", line 39, in <module>
    t = gettext.translation(PROGNAME,
  File "/usr/lib64/python3.9/gettext.py", line 592, in translation
    raise FileNotFoundError(ENOENT,
  FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
Reviewed-by: Daniel Burgener <dburgener@linux.microsoft.com>
Acked-by: Petr Lautrbach <plautrba@redhat.com>

Upstream-Status: Backport
[https://github.com/SELinuxProject/selinux/commit/344463076b2a91e1d2c7f5cc3835dc1a53a05e88]

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
---
 chcat/chcat                           | 5 +++--
 semanage/semanage                     | 3 ++-
 semanage/seobject.py                  | 3 ++-
 sepolgen/src/sepolgen/sepolgeni18n.py | 4 +++-
 sepolicy/sepolicy.py                  | 3 ++-
 sepolicy/sepolicy/__init__.py         | 3 ++-
 sepolicy/sepolicy/generate.py         | 3 ++-
 sepolicy/sepolicy/gui.py              | 3 ++-
 sepolicy/sepolicy/interface.py        | 3 ++-
 9 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/chcat/chcat b/chcat/chcat
index e779fcc..952cb81 100755
--- a/chcat/chcat
+++ b/chcat/chcat
@@ -38,9 +38,10 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
-except ImportError:
+except:
     try:
         import builtins
         builtins.__dict__['_'] = str
diff --git a/semanage/semanage b/semanage/semanage
index 8f4e44a..f45061a 100644
--- a/semanage/semanage
+++ b/semanage/semanage
@@ -38,7 +38,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/semanage/seobject.py b/semanage/seobject.py
index ff8f4e9..0782c08 100644
--- a/semanage/seobject.py
+++ b/semanage/seobject.py
@@ -42,7 +42,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/sepolgen/src/sepolgen/sepolgeni18n.py b/sepolgen/src/sepolgen/sepolgeni18n.py
index 56ebd80..1ff307d 100644
--- a/sepolgen/src/sepolgen/sepolgeni18n.py
+++ b/sepolgen/src/sepolgen/sepolgeni18n.py
@@ -19,7 +19,9 @@
 
 try: 
     import gettext
-    t = gettext.translation( 'selinux-python' )
+    t = gettext.translation("selinux-python",
+                        localedir="/usr/share/locale",
+                        fallback=True)
     _ = t.gettext
 except:
     def _(str):
diff --git a/sepolicy/sepolicy.py b/sepolicy/sepolicy.py
index 7ebe0ef..c7a70e0 100755
--- a/sepolicy/sepolicy.py
+++ b/sepolicy/sepolicy.py
@@ -36,7 +36,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/sepolicy/sepolicy/__init__.py b/sepolicy/sepolicy/__init__.py
index 7208234..9c3caa0 100644
--- a/sepolicy/sepolicy/__init__.py
+++ b/sepolicy/sepolicy/__init__.py
@@ -31,7 +31,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/sepolicy/sepolicy/generate.py b/sepolicy/sepolicy/generate.py
index 67189fc..3717d5d 100644
--- a/sepolicy/sepolicy/generate.py
+++ b/sepolicy/sepolicy/generate.py
@@ -56,7 +56,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/sepolicy/sepolicy/gui.py b/sepolicy/sepolicy/gui.py
index b026374..5bdbfeb 100644
--- a/sepolicy/sepolicy/gui.py
+++ b/sepolicy/sepolicy/gui.py
@@ -49,7 +49,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
diff --git a/sepolicy/sepolicy/interface.py b/sepolicy/sepolicy/interface.py
index 599f97f..43f8644 100644
--- a/sepolicy/sepolicy/interface.py
+++ b/sepolicy/sepolicy/interface.py
@@ -38,7 +38,8 @@ try:
         kwargs['unicode'] = True
     t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    **kwargs)
+                    **kwargs,
+                    fallback=True)
     _ = t.gettext
 except:
     try:
-- 
2.25.1