當前位置: 首頁>>代碼示例>>Python>>正文


Python locale.getlocale方法代碼示例

本文整理匯總了Python中locale.getlocale方法的典型用法代碼示例。如果您正苦於以下問題:Python locale.getlocale方法的具體用法?Python locale.getlocale怎麽用?Python locale.getlocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在locale的用法示例。


在下文中一共展示了locale.getlocale方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_option_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_option_locale(self):
        self.assertFailure('-L')
        self.assertFailure('--locale')
        self.assertFailure('-L', 'en')
        lang, enc = locale.getdefaultlocale()
        lang = lang or 'C'
        enc = enc or 'UTF-8'
        try:
            oldlocale = locale.getlocale(locale.LC_TIME)
            try:
                locale.setlocale(locale.LC_TIME, (lang, enc))
            finally:
                locale.setlocale(locale.LC_TIME, oldlocale)
        except (locale.Error, ValueError):
            self.skipTest('cannot set the system default locale')
        stdout = self.run_ok('--locale', lang, '--encoding', enc, '2004')
        self.assertIn('2004'.encode(enc), stdout) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_calendar.py

示例2: test_getsetlocale_issue1813

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_getsetlocale_issue1813(self):
        # Issue #1813: setting and getting the locale under a Turkish locale
        oldlocale = locale.getlocale()
        self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
        for loc in ('tr_TR', 'tr_TR.UTF-8', 'tr_TR.ISO8859-9'):
            try:
                locale.setlocale(locale.LC_CTYPE, loc)
                break
            except locale.Error:
                continue
        else:
            # Unsupported locale on this system
            self.skipTest('test needs Turkish locale')
        loc = locale.getlocale()
        try:
            locale.setlocale(locale.LC_CTYPE, loc)
        except Exception as e:
            self.fail("Failed to set locale %r (default locale is %r): %r" %
                      (loc, oldlocale, e))
        self.assertEqual(loc, locale.getlocale()) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_locale.py

示例3: _currency_symbols

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def _currency_symbols():
    """Compile a list of valid currency symbols."""
    current = locale.getlocale()
    locales = list(locale.locale_alias.values())
    symbols = set()

    for loc in locales:
        try:
            locale.setlocale(locale.LC_MONETARY, locale.normalize(loc))
            currency = "{int_curr_symbol}".format(**locale.localeconv())
            if currency != "":
                symbols.add(currency.strip())
        except (locale.Error, UnicodeDecodeError):
            continue

    locale.setlocale(locale.LC_MONETARY, current)
    return list(symbols) 
開發者ID:project-koku,項目名稱:koku,代碼行數:19,代碼來源:serializers.py

示例4: test_localeIndependent

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_localeIndependent(self):
        """
        The month name in the date is locale independent.
        """
        # A point about three months in the past.
        then = self.now - (60 * 60 * 24 * 31 * 3)
        stat = os.stat_result((0, 0, 0, 0, 0, 0, 0, 0, then, 0))

        # Fake that we're in a language where August is not Aug (e.g.: Spanish)
        currentLocale = locale.getlocale()
        locale.setlocale(locale.LC_ALL, "es_AR.UTF8")
        self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale)

        self.assertEqual(
            self._lsInTimezone('America/New_York', stat),
            '!---------    0 0        0               0 Aug 28 17:33 foo')
        self.assertEqual(
            self._lsInTimezone('Pacific/Auckland', stat),
            '!---------    0 0        0               0 Aug 29 09:33 foo')

    # If alternate locale is not available, the previous test will be
    # skipped, please install this locale for it to run 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:test_cftp.py

示例5: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def __init__(self):
        if os.path.isfile(os.path.dirname(os.path.abspath(__file__)) + '/keys/cert.crt') != True:
            print("First run, generating certificate..")
            execute_string = "openssl req -nodes -x509 -newkey rsa:4096 -keyout " + \
                            os.path.dirname(os.path.abspath(__file__)) + \
                            "/keys/key.pem -out " + os.path.dirname(os.path.abspath(__file__)) + \
                            "/keys/cert.crt -days 356 -subj " + \
                            "\"/C=AP/ST=Land/L=torc/O=AP Team/subjectAltName=IP:127.0.0.1\""

            proc = Popen(execute_string, stdout=PIPE, stderr=PIPE, shell=True)

            decode_locale = lambda s: s.decode(getlocale()[1])
            self.tool_stdout, self.tool_stderr = map(decode_locale, proc.communicate())

            # Callback / pause from here
            return_code = proc.returncode

# Pong!
# curl -i http://127.0.0.1:5000/ping 
開發者ID:rascal999,項目名稱:torc,代碼行數:21,代碼來源:__init__.py

示例6: get_unit_received

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def get_unit_received(self):
        """
        Returns (as a tuple) the GSX-compatible date and time of
        when this unit was received
        """
        import locale
        langs = gsxws.get_format('en_XXX')
        ts = self.unit_received_at
        loc = locale.getlocale()
        # reset locale to get correct AM/PM value
        locale.setlocale(locale.LC_TIME, None)
        result = ts.strftime(langs['df']), ts.strftime(langs['tf'])
        locale.setlocale(locale.LC_TIME, loc)
        return result 
開發者ID:fpsw,項目名稱:Servo,代碼行數:16,代碼來源:repair.py

示例7: _getlang

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def _getlang():
    # Figure out what the current language is set to.
    return locale.getlocale(locale.LC_TIME) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:5,代碼來源:_strptime.py

示例8: __enter__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def __enter__(self):
        self.oldlocale = _locale.getlocale(_locale.LC_TIME)
        _locale.setlocale(_locale.LC_TIME, self.locale) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:5,代碼來源:calendar.py

示例9: find_comma_decimal_point_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def find_comma_decimal_point_locale():
    """See if platform has a decimal point as comma locale.

    Find a locale that uses a comma instead of a period as the
    decimal point.

    Returns
    -------
    old_locale: str
        Locale when the function was called.
    new_locale: {str, None)
        First French locale found, None if none found.

    """
    if sys.platform == 'win32':
        locales = ['FRENCH']
    else:
        locales = ['fr_FR', 'fr_FR.UTF-8', 'fi_FI', 'fi_FI.UTF-8']

    old_locale = locale.getlocale(locale.LC_NUMERIC)
    new_locale = None
    try:
        for loc in locales:
            try:
                locale.setlocale(locale.LC_NUMERIC, loc)
                new_locale = loc
                break
            except locale.Error:
                pass
    finally:
        locale.setlocale(locale.LC_NUMERIC, locale=old_locale)
    return old_locale, new_locale 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:34,代碼來源:_locales.py

示例10: test_to_datetime_format_microsecond

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_to_datetime_format_microsecond(self, cache):

        # these are locale dependent
        lang, _ = locale.getlocale()
        month_abbr = calendar.month_abbr[4]
        val = '01-{}-2011 00:00:01.978'.format(month_abbr)

        format = '%d-%b-%Y %H:%M:%S.%f'
        result = to_datetime(val, format=format, cache=cache)
        exp = datetime.strptime(val, format)
        assert result == exp 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:13,代碼來源:test_tools.py

示例11: test_can_set_locale_invalid_get

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_can_set_locale_invalid_get(monkeypatch):
    # see gh-22129
    #
    # In some cases, an invalid locale can be set,
    # but a subsequent getlocale() raises a ValueError.

    def mock_get_locale():
        raise ValueError()

    with monkeypatch.context() as m:
        m.setattr(locale, "getlocale", mock_get_locale)
        assert not tm.can_set_locale("") 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_locale.py

示例12: test_set_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def test_set_locale():
    if com._all_none(_current_locale):
        # Not sure why, but on some Travis runs with pytest,
        # getlocale() returned (None, None).
        pytest.skip("Current locale is not set.")

    locale_override = os.environ.get("LOCALE_OVERRIDE", None)

    if locale_override is None:
        lang, enc = "it_CH", "UTF-8"
    elif locale_override == "C":
        lang, enc = "en_US", "ascii"
    else:
        lang, enc = locale_override.split(".")

    enc = codecs.lookup(enc).name
    new_locale = lang, enc

    if not tm.can_set_locale(new_locale):
        msg = "unsupported locale setting"

        with pytest.raises(locale.Error, match=msg):
            with tm.set_locale(new_locale):
                pass
    else:
        with tm.set_locale(new_locale) as normalized_locale:
            new_lang, new_enc = normalized_locale.split(".")
            new_enc = codecs.lookup(enc).name

            normalized_locale = new_lang, new_enc
            assert normalized_locale == new_locale

    # Once we exit the "with" statement, locale should be back to what it was.
    current_locale = locale.getlocale()
    assert current_locale == _current_locale 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:37,代碼來源:test_locale.py

示例13: set_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def set_locale(new_locale, lc_var=locale.LC_ALL):
    """Context manager for temporarily setting a locale.

    Parameters
    ----------
    new_locale : str or tuple
        A string of the form <language_country>.<encoding>. For example to set
        the current locale to US English with a UTF8 encoding, you would pass
        "en_US.UTF-8".
    lc_var : int, default `locale.LC_ALL`
        The category of the locale being set.

    Notes
    -----
    This is useful when you want to run a particular block of code under a
    particular locale, without globally setting the locale. This probably isn't
    thread-safe.
    """
    current_locale = locale.getlocale()

    try:
        locale.setlocale(lc_var, new_locale)
        normalized_locale = locale.getlocale()
        if com._all_not_none(*normalized_locale):
            yield '.'.join(normalized_locale)
        else:
            yield new_locale
    finally:
        locale.setlocale(lc_var, current_locale) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:31,代碼來源:testing.py

示例14: _skip_if_not_us_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def _skip_if_not_us_locale():
    lang, _ = locale.getlocale()
    if lang != 'en_US':
        return True 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:6,代碼來源:_test_decorators.py

示例15: preferredLanguages

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import getlocale [as 別名]
def preferredLanguages(self):

        if platform=='darwin':
            return NSLocale.preferredLanguages()

        elif platform=='win32':

            def wszarray_to_list(array):
                offset = 0
                while offset < len(array):
                    sz = ctypes.wstring_at(ctypes.addressof(array) + offset*2)
                    if sz:
                        yield sz
                        offset += len(sz)+1
                    else:
                        break

            num = ctypes.c_ulong()
            size = ctypes.c_ulong(0)
            if (GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), None, ctypes.byref(size)) and size.value):
                buf = ctypes.create_unicode_buffer(size.value)
                if GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, ctypes.byref(num), ctypes.byref(buf), ctypes.byref(size)):
                    return wszarray_to_list(buf)
            return []

        else:	# POSIX
            lang = locale.getlocale()[0]
            return lang and [lang.replace('_','-')] or []

# singletons 
開發者ID:EDCD,項目名稱:EDMarketConnector,代碼行數:32,代碼來源:l10n.py


注:本文中的locale.getlocale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。