本文整理汇总了Python中_locale.setlocale方法的典型用法代码示例。如果您正苦于以下问题:Python _locale.setlocale方法的具体用法?Python _locale.setlocale怎么用?Python _locale.setlocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_locale
的用法示例。
在下文中一共展示了_locale.setlocale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compile
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def _compile(*key):
# internal: compile pattern
pattern, flags = key
bypass_cache = flags & DEBUG
if not bypass_cache:
cachekey = (type(key[0]),) + key
try:
p, loc = _cache[cachekey]
if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE):
return p
except KeyError:
pass
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError('Cannot process flags argument with a compiled pattern')
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
try:
p = sre_compile.compile(pattern, flags)
except error, v:
raise error, v # invalid expression
示例2: test_setlocale
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def test_setlocale(self):
c_list = [ _locale.LC_ALL,
_locale.LC_COLLATE,
_locale.LC_CTYPE,
_locale.LC_MONETARY,
_locale.LC_NUMERIC,
_locale.LC_TIME,
]
for c in c_list:
resultLocale = None
_locale.setlocale(c,"English")
resultLocale = _locale.setlocale(c)
self.assertEqual(resultLocale,"English_United States.1252")
for c in c_list:
resultLocale = None
_locale.setlocale(c,"French")
resultLocale = _locale.setlocale(c)
self.assertEqual(resultLocale,"French_France.1252")
示例3: test_setlocale_negative
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def test_setlocale_negative(self):
#the locale is empty string
c= _locale.LC_ALL
locale =''
_locale.setlocale(c,locale)
#the locale is None
locale = _locale.setlocale(c)
resultLocale =_locale.setlocale(c)
self.assertEqual(locale,resultLocale)
#set Numeric as a unknown locale,should thorw a _locale.Error
locale ="11-22"
self.assertRaises(_locale.Error,_locale.setlocale,c,locale)
locale ="@^#^&%"
self.assertRaises(_locale.Error,_locale.setlocale,c,locale)
locale ="xxxxxx"
self.assertRaises(_locale.Error,_locale.setlocale,c,locale)
示例4: test_strcoll
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def test_strcoll(self):
_locale.setlocale(_locale.LC_COLLATE,"English")
self.validcollate()
_locale.setlocale(_locale.LC_COLLATE,"French")
self.validcollate()
示例5: test_bad_category
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def test_bad_category(self):
self.assertRaises(TypeError, _locale.setlocale, 'LC_NUMERIC', 'en_US.UTF8')
self.assertRaises(TypeError, _locale.setlocale, 'LC_NUMERIC', None)
示例6: _compile
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def _compile(pattern, flags):
# internal: compile pattern
try:
p, loc = _cache[type(pattern), pattern, flags]
if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE):
return p
except KeyError:
pass
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
"cannot process flags argument with a compiled pattern")
return pattern
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
p = sre_compile.compile(pattern, flags)
if not (flags & DEBUG):
if len(_cache) >= _MAXCACHE:
_cache.clear()
if p.flags & LOCALE:
if not _locale:
return p
loc = _locale.setlocale(_locale.LC_CTYPE)
else:
loc = None
_cache[type(pattern), pattern, flags] = p, loc
return p
示例7: _compile
# 需要导入模块: import _locale [as 别名]
# 或者: from _locale import setlocale [as 别名]
def _compile(pattern, flags):
# internal: compile pattern
bypass_cache = flags & DEBUG
if not bypass_cache:
try:
p, loc = _cache[type(pattern), pattern, flags]
if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE):
return p
except KeyError:
pass
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
"Cannot process flags argument with a compiled pattern")
return pattern
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
p = sre_compile.compile(pattern, flags)
if not bypass_cache:
if len(_cache) >= _MAXCACHE:
_cache.clear()
if p.flags & LOCALE:
if not _locale:
return p
loc = _locale.setlocale(_locale.LC_CTYPE)
else:
loc = None
_cache[type(pattern), pattern, flags] = p, loc
return p