本文整理匯總了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