Python locale.resetlocale() Examples

The following are 7 code examples of locale.resetlocale(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module locale , or try the search function .
Example #1
Source File: test_reporter.py    From landscape-client with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #2
Source File: test_skeleton.py    From landscape-client with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #3
Source File: test_datatypes.py    From PyRFC with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: test_datatypes.py    From PyRFC with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: a_csvimport.py    From accelerator with Apache License 2.0 5 votes vote down vote up
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] 
Example #6
Source File: __init__.py    From lpdec with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #7
Source File: translate.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
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