本文整理汇总了Python中locale.resetlocale方法的典型用法代码示例。如果您正苦于以下问题:Python locale.resetlocale方法的具体用法?Python locale.resetlocale怎么用?Python locale.resetlocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类locale
的用法示例。
在下文中一共展示了locale.resetlocale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_main_resets_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def test_main_resets_locale(self):
"""
Reporter entry point should reset encoding to utf-8, as libapt-pkg
encodes description with system encoding and python-apt decodes
them as utf-8 (LP: #1827857).
"""
self._add_package_to_deb_dir(
self.repository_dir, "gosa", description=u"GOsa\u00B2")
self.facade.reload_channels()
# Set the only non-utf8 locale which we're sure exists.
# It behaves slightly differently than the bug, but fails on the
# same condition.
locale.setlocale(locale.LC_CTYPE, (None, None))
self.addCleanup(locale.resetlocale)
with mock.patch("landscape.client.package.reporter.run_task_handler"):
main([])
# With the actual package, the failure will occur looking up the
# description translation.
pkg = self.facade.get_packages_by_name("gosa")[0]
skel = self.facade.get_package_skeleton(pkg, with_info=True)
self.assertEqual(u"GOsa\u00B2", skel.description)
示例2: test_build_skeleton_with_unicode_and_non_ascii
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def test_build_skeleton_with_unicode_and_non_ascii(self):
"""
If with_unicode and with_info are passed to build_skeleton_apt,
the description is decoded.
"""
# Py2 used to convert to lossy ascii (thus LC_ in Makefile)
# Py3 doesn't, and python3-apt assumes UTF8 (LP: #1827857).
# If you revisit this test, also check reporter.main(), which
# should set this globally to the reporter process.
locale.setlocale(locale.LC_CTYPE, "C.UTF-8")
self.addCleanup(locale.resetlocale)
self._add_package_to_deb_dir(
self.skeleton_repository_dir, "pkg", description=u"T\xe9st")
self.facade._cache.update(None)
self.facade._cache.open(None)
pkg = self.get_package("pkg")
skeleton = build_skeleton_apt(pkg, with_unicode=True, with_info=True)
self.assertEqual(u"T\u00E9st", skeleton.description)
示例3: test_float_rejects_point_for_comma_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def test_float_rejects_point_for_comma_locale():
locale.setlocale(locale.LC_ALL, "de_DE")
IMPORTSTRUCT = {"RFCFLOAT": "1.2"}
try:
output = client.call("STFC_STRUCTURE", IMPORTSTRUCT=IMPORTSTRUCT)
except Exception as ex:
assert type(ex) is ExternalRuntimeError
assert ex.code == 22
assert ex.key == "RFC_CONVERSION_FAILURE"
assert (
ex.message
== "Cannot convert string value 1.2 at position 1 for the field RFCFLOAT to type RFCTYPE_FLOAT"
)
locale.resetlocale(locale.LC_ALL)
示例4: test_float_accepts_comma_for_comma_locale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def test_float_accepts_comma_for_comma_locale():
locale.setlocale(locale.LC_ALL, "de_DE")
IMPORTSTRUCT = {"RFCFLOAT": "1,2"}
output = client.call("STFC_STRUCTURE", IMPORTSTRUCT=IMPORTSTRUCT)["ECHOSTRUCT"]
assert output["RFCFLOAT"] == 1.2
locale.resetlocale(locale.LC_ALL)
示例5: reader_status
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def reader_status(status_fd, update):
# try to get nicer number formating
try:
locale.resetlocale(locale.LC_NUMERIC)
except Exception:
pass
count = 0
while True:
update('{0:n} lines read'.format(count))
data = os.read(status_fd, 8)
if not data:
break
count = struct.unpack("=Q", data)[0]
示例6: script
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def script():
import locale
locale.resetlocale()
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--database', metavar='DB', help='database connection string')
parser.add_argument('-v', '--verbose', action='store_true', help='be more verbose')
parser.add_argument('-o', '--outfile', help='write output to given file instead of stdout')
subparsers = parser.add_subparsers(title='Commands')
parserBrowse = subparsers.add_parser('browse', help='browse and plot results')
browse.initParser(parserBrowse)
parserCodes = subparsers.add_parser('code', help='code toolkit')
code.initParser(parserCodes)
args = parser.parse_args()
args.func(args)
示例7: resetlocale
# 需要导入模块: import locale [as 别名]
# 或者: from locale import resetlocale [as 别名]
def resetlocale():
# locale.resetlocale is bugged with some locales.
for ln in get_locales():
try:
ln = ln[0:ln.index('.')]
return locale.setlocale(locale.LC_ALL, ln)
except locale.Error:
continue