Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert fix for (LP: #1827857) #251

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion landscape/client/monitor/packagemonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _reset(self):
Remove all tasks *except* the resynchronize task. This is
because if we clear all tasks, then add the resynchronize,
it's possible that the reporter may be running a task at this
time and when it finishes, it will unknowningly remove the
time and when it finishes, it will unknowingly remove the
resynchronize task because sqlite resets its serial primary
keys when you delete an entire table. This problem is avoided
by adding the task first and removing them all *except* the
Expand Down
5 changes: 0 additions & 5 deletions landscape/client/package/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
except ImportError:
import urllib.parse as urlparse

import locale
import logging
import time
import os
Expand Down Expand Up @@ -940,10 +939,6 @@ def send_pending_messages(self):


def main(args):
# Force UTF-8 encoding only for the reporter, thus allowing libapt-pkg to
# return unmangled descriptions.
locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))

if "FAKE_GLOBAL_PACKAGE_STORE" in os.environ:
return run_task_handler(FakeGlobalReporter, args)
elif "FAKE_PACKAGE_STORE" in os.environ:
Expand Down
29 changes: 0 additions & 29 deletions landscape/client/package/tests/test_reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import locale
import logging
import os
import shutil
Expand Down Expand Up @@ -1443,34 +1442,6 @@ def test_main(self):
self.assertEqual("RESULT", main(["ARGS"]))
m.assert_called_once_with(PackageReporter, ["ARGS"])

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="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("GOsa\u00B2", skel.description)

def test_find_reporter_command_with_bindir(self):
self.config.bindir = "/spam/eggs"
command = find_reporter_command(self.config)
Expand Down
12 changes: 2 additions & 10 deletions landscape/lib/apt/package/tests/test_skeleton.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import locale
import unittest

from twisted.python.compat import unicode
Expand Down Expand Up @@ -193,15 +192,8 @@ def test_build_skeleton_with_unicode_and_extra_info(self):
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.
the description is decoded and non-ascii chars replaced.
"""
# 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",
Expand All @@ -211,7 +203,7 @@ def test_build_skeleton_with_unicode_and_non_ascii(self):
self.facade._cache.open(None)
pkg = self.get_package("pkg")
skeleton = build_skeleton_apt(pkg, with_unicode=True, with_info=True)
self.assertEqual("T\u00E9st", skeleton.description)
self.assertEqual("T?st", skeleton.description)

def test_build_skeleton_minimal(self):
"""
Expand Down
Loading