本文整理汇总了Python中locale.LC_ALL属性的典型用法代码示例。如果您正苦于以下问题:Python locale.LC_ALL属性的具体用法?Python locale.LC_ALL怎么用?Python locale.LC_ALL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类locale
的用法示例。
在下文中一共展示了locale.LC_ALL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_localeIndependent
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [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
示例2: main
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def main():
from locale import setlocale, LC_ALL
setlocale(LC_ALL, '') # initialize locales because python doesn't
try:
# auto completion
if len(argv) >= 2 and argv[1] == "--auto_complete":
possible_completions()
sys.exit(0)
# normal call
process(argv[1:])
except (KeyboardInterrupt, PermissionError):
sys.exit(1)
except SystemExit as e:
sys.exit(e)
except:
logging.error("", exc_info=True)
sys.exit(1)
示例3: __init__
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def __init__(self, savFileName, ioUtf8=False, ioLocale=None):
"""Constructor. Note that interface locale and encoding can only
be set once"""
locale.setlocale(locale.LC_ALL, "")
self.savFileName = savFileName
self.libc = cdll.LoadLibrary(ctypes.util.find_library("c"))
self.spssio = self.loadLibrary()
self.wholeCaseIn = self.spssio.spssWholeCaseIn
self.wholeCaseOut = self.spssio.spssWholeCaseOut
self.encoding_and_locale_set = False
if not self.encoding_and_locale_set:
self.encoding_and_locale_set = True
self.ioLocale = ioLocale
self.ioUtf8 = ioUtf8
示例4: set_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def set_locale():
"""Load the proper locale for date strings, only once"""
if hasattr(set_locale, 'cached'):
return getattr(set_locale, 'cached')
from locale import Error, LC_ALL, setlocale
locale_lang = get_global_setting('locale.language').split('.')[-1]
locale_lang = locale_lang[:-2] + locale_lang[-2:].upper()
# NOTE: setlocale() only works if the platform supports the Kodi configured locale
try:
setlocale(LC_ALL, locale_lang)
except (Error, ValueError) as exc:
if locale_lang != 'en_GB':
log(3, "Your system does not support locale '{locale}': {error}", locale=locale_lang, error=exc)
set_locale.cached = False
return False
set_locale.cached = True
return True
示例5: updateDate
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def updateDate( self ):
try:
locale.setlocale( locale.LC_ALL , 'en_US' )
except locale.Error:
locale.setlocale( locale.LC_ALL , 'us_us' )
except:
pass
self.date = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S")
# Mark the object as deleted
示例6: set_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [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)
示例7: can_set_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def can_set_locale(lc, lc_var=locale.LC_ALL):
"""
Check to see if we can set a locale, and subsequently get the locale,
without raising an Exception.
Parameters
----------
lc : str
The locale to attempt to set.
lc_var : int, default `locale.LC_ALL`
The category of the locale being set.
Returns
-------
is_valid : bool
Whether the passed locale can be set
"""
try:
with set_locale(lc, lc_var=lc_var):
pass
except (ValueError,
locale.Error): # horrible name for a Exception subclass
return False
else:
return True
示例8: set_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [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".
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)
try:
normalized_locale = locale.getlocale()
except ValueError:
yield new_locale
else:
if com._all_not_none(*normalized_locale):
yield '.'.join(normalized_locale)
else:
yield new_locale
finally:
locale.setlocale(lc_var, current_locale)
示例9: set_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [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".
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)
try:
normalized_locale = locale.getlocale()
except ValueError:
yield new_locale
else:
if all(lc is not None for lc in normalized_locale):
yield '.'.join(normalized_locale)
else:
yield new_locale
finally:
locale.setlocale(lc_var, current_locale)
示例10: test_fetchInternalDateLocaleIndependent
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def test_fetchInternalDateLocaleIndependent(self):
"""
The month name in the date is locale independent.
"""
# Fake that we're in a language where December is not Dec
currentLocale = locale.setlocale(locale.LC_ALL, None)
locale.setlocale(locale.LC_ALL, "es_AR.UTF8")
self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale)
return self.testFetchInternalDate(1)
# if alternate locale is not available, the previous test will be skipped,
# please install this locale for it to run. Avoid using locale.getlocale to
# learn the current locale; its values don't round-trip well on all
# platforms. Fortunately setlocale returns a value which does round-trip
# well.
示例11: setUp
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def setUp(self):
self.oldloc = locale.setlocale(locale.LC_ALL)
示例12: tearDown
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def tearDown(self):
locale.setlocale(locale.LC_ALL, self.oldloc)
示例13: test_bug_3061
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def test_bug_3061(self):
try:
tmp = locale.setlocale(locale.LC_ALL, "fr_FR")
except locale.Error:
self.skipTest('could not set locale.LC_ALL to fr_FR')
# This should not cause an exception
time.strftime("%B", (2009,2,1,0,0,0,0,0,0))
示例14: test_setlocale_category
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def test_setlocale_category(self):
locale.setlocale(locale.LC_ALL)
locale.setlocale(locale.LC_TIME)
locale.setlocale(locale.LC_CTYPE)
locale.setlocale(locale.LC_COLLATE)
locale.setlocale(locale.LC_MONETARY)
locale.setlocale(locale.LC_NUMERIC)
# crasher from bug #7419
self.assertRaises(locale.Error, locale.setlocale, 12345)
示例15: test_invalid_locale_format_in_localetuple
# 需要导入模块: import locale [as 别名]
# 或者: from locale import LC_ALL [as 别名]
def test_invalid_locale_format_in_localetuple(self):
with self.assertRaises(TypeError):
locale.setlocale(locale.LC_ALL, b'fi_FI')