当前位置: 首页>>代码示例>>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;未经允许,请勿转载。