This file is indexed.

/usr/lib/python2.7/dist-packages/Wammu/Locales.py is in wammu 0.40-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- coding: UTF-8 -*-
#
# Copyright © 2003 - 2015 Michal Čihař <michal@cihar.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# vim: expandtab sw=4 ts=4 sts=4:
'''
Wammu - Phone manager
Locales initialisation and gettext wrapper
'''

import os
import gettext
import locale
import codecs
import sys

_TRANSLATION = None


LOCAL_LOCALE_PATH = os.path.join('build', 'share', 'locale')
LOCALE_PATH = None

FALLBACK_LOCALE_CHARSET = 'iso-8859-1'

# Determine "correct" character set
try:
    # works only in python > 2.3
    LOCALE_CHARSET = locale.getpreferredencoding()
except:
    try:
        LOCALE_CHARSET = locale.getdefaultlocale()[1]
    except:
        try:
            LOCALE_CHARSET = sys.getdefaultencoding()
        except:
            LOCALE_CHARSET = FALLBACK_LOCALE_CHARSET
if LOCALE_CHARSET in [None, 'ANSI_X3.4-1968']:
    LOCALE_CHARSET = FALLBACK_LOCALE_CHARSET

try:
    CONSOLE_CHARSET = sys.stdout.encoding
except AttributeError:
    CONSOLE_CHARSET = None
if CONSOLE_CHARSET is None:
    CONSOLE_CHARSET = LOCALE_CHARSET
CONSOLE_ENCODER = codecs.getencoder(CONSOLE_CHARSET)

def ConsoleStrConv(txt):
    """
    This function coverts something (txt) to string form usable on console.
    """
    try:
        if isinstance(txt, str):
            return txt
        elif isinstance(txt, unicode):
            return str(CONSOLE_ENCODER(txt, 'replace')[0])
        return str(txt)
    except UnicodeEncodeError:
        return '???'

def StrConv(txt):
    """
    This function coverts something (txt) to string form usable by wxPython. There
    is problem that in default configuration in most distros (maybe all) default
    encoding for unicode objects is ascii. This leads to exception when converting
    something different than ascii. And this exception is not catched inside
    wxPython and leads to segfault.

    So if wxPython supports unicode, we give it unicode, otherwise locale
    dependant text.
    """
    try:
        if isinstance(txt, unicode):
            return txt
        elif isinstance(txt, str):
            return unicode(txt, LOCALE_CHARSET)
        return str(txt)
    except UnicodeEncodeError:
        return '???'

# detect html charset
HTML_CHARSET = LOCALE_CHARSET

# prepare html encoder
HTML_ENCODER = codecs.getencoder(HTML_CHARSET)

def HtmlStrConv(txt):
    """
    This function coverts something (txt) to string form usable by wxPython
    html widget. There is problem that in default configuration in most distros
    (maybe all) default encoding for unicode objects is ascii. This leads to
    exception when converting something different than ascii. And this
    exception is not catched inside wxPython and leads to segfault.

    So if wxPython supports unicode, we give it unicode, otherwise locale
    dependant text.
    """
    try:
        if isinstance(txt, unicode):
            return txt
        elif isinstance(txt, str):
            return unicode(txt, LOCALE_CHARSET)
        return str(txt)
    except UnicodeEncodeError:
        return '???'

def UnicodeConv(txt):
    """
    This function coverts something (txt) to string form usable by wxPython. There
    is problem that in default configuration in most distros (maybe all) default
    encoding for unicode objects is ascii. This leads to exception when converting
    something different than ascii. And this exception is not catched inside
    wxPython and leads to segfault.

    So if wxPython supports unicode, we give it unicode, otherwise locale
    dependant text.
    """
    try:
        if isinstance(txt, unicode):
            return txt
        elif isinstance(txt, str):
            return unicode(txt, LOCALE_CHARSET)
        return unicode(str(txt), LOCALE_CHARSET)
    except UnicodeEncodeError:
        return unicode('???')


def Init():
    '''
    Initialises gettext for wammu domain and installs global function _,
    which handles translations.
    '''
    global LOCALE_PATH
    switch = False
    if (os.path.exists('setup.py') and
        os.path.exists(LOCAL_LOCALE_PATH) and
        os.path.exists(
            os.path.join('Wammu', '__init__.py')
            )):
        LOCALE_PATH = LOCAL_LOCALE_PATH
        switch = True
    Install()
    if switch:
        print ConsoleStrConv(ugettext('Automatically switched to local locales.'))


def UseLocal():
    '''
    Use locales from current build dir.
    '''
    global LOCALE_PATH
    LOCALE_PATH = LOCAL_LOCALE_PATH
    Install()


def ngettext(msgid1, msgid2, n):
    if _TRANSLATION:
        return _TRANSLATION.ungettext(msgid1, msgid2, n)
    if n == 1:
        return msgid1
    else:
        return msgid2


def ugettext(message):
    if _TRANSLATION:
        return _TRANSLATION.ugettext(message)
    return message


def Install():
    global _TRANSLATION
    try:
        _TRANSLATION = gettext.translation(
            'wammu',
            localedir=LOCALE_PATH
        )
    except IOError:
        print ConsoleStrConv('Failed to load translation!')