Esempio n. 1
0
 def test_getencoding(self):
     # Invoke getencoding to make sure it does not cause exceptions.
     enc = locale.getencoding()
     self.assertIsInstance(enc, str)
     self.assertNotEqual(enc, "")
     # make sure it is valid
     codecs.lookup(enc)
Esempio n. 2
0
def setUpModule():
    global candidate_locales
    # Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
    # workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
    # the locale encoding ISO-8859-2, the thousands separator is b'\xA0' and it is
    # decoded as U+30000020 (an invalid character) by mbstowcs().
    if sys.platform == 'sunos5':
        old_locale = locale.setlocale(locale.LC_ALL)
        try:
            locales = []
            for loc in candidate_locales:
                try:
                    locale.setlocale(locale.LC_ALL, loc)
                except Error:
                    continue
                encoding = locale.getencoding()
                try:
                    localeconv()
                except Exception as err:
                    print("WARNING: Skip locale %s (encoding %s): [%s] %s"
                        % (loc, encoding, type(err), err))
                else:
                    locales.append(loc)
            candidate_locales = locales
        finally:
            locale.setlocale(locale.LC_ALL, old_locale)

    # Workaround for MSVC6(debug) crash bug
    if "MSC v.1200" in sys.version:
        def accept(loc):
            a = loc.split(".")
            return not(len(a) == 2 and len(a[-1]) >= 9)
        candidate_locales = [loc for loc in candidate_locales if accept(loc)]
Esempio n. 3
0
 def setUp(self):
     enc = codecs.lookup(locale.getencoding() or 'ascii').name
     if enc not in ('utf-8', 'iso8859-1', 'cp1252'):
         raise unittest.SkipTest('encoding not suitable')
     if enc != 'iso8859-1' and (sys.platform == 'darwin' or is_android
                                or sys.platform.startswith('freebsd')):
         raise unittest.SkipTest('wcscoll/wcsxfrm have known bugs')
     BaseLocalizedTest.setUp(self)
Esempio n. 4
0
 def display_header(self):
     # Print basic platform information
     print("==", platform.python_implementation(), *sys.version.split())
     print("==", platform.platform(aliased=True),
                   "%s-endian" % sys.byteorder)
     print("== cwd:", os.getcwd())
     cpu_count = os.cpu_count()
     if cpu_count:
         print("== CPU count:", cpu_count)
     print("== encodings: locale=%s, FS=%s"
           % (locale.getencoding(), sys.getfilesystemencoding()))
Esempio n. 5
0
def collect_locale(info_add):
    import locale

    info_add('locale.getencoding', locale.getencoding())