diff options
| author | Julian Andres Klode <jak@debian.org> | 2010-03-08 15:04:39 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2010-03-08 15:04:39 +0100 |
| commit | 7ebf48f29064579cf4752aa5bf9c4663b49c2792 (patch) | |
| tree | 47b5d8b69dea5092457cab88b36168ee62845b71 /apt | |
| parent | 4b434cde19d25e2acc238699834f1a2a72540ca2 (diff) | |
| download | python-apt-7ebf48f29064579cf4752aa5bf9c4663b49c2792.tar.gz | |
apt/package.py: Always return unicode strings in Package.get_changelog (Closes: #572998).
Diffstat (limited to 'apt')
| -rw-r--r-- | apt/package.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/apt/package.py b/apt/package.py index 7c739aab..0c026504 100644 --- a/apt/package.py +++ b/apt/package.py @@ -981,7 +981,7 @@ class Package(object): which if set, prevents the download. """ # Return a cached changelog if available - if self._changelog != "": + if self._changelog != u"": return self._changelog if uri is None: @@ -996,7 +996,8 @@ class Package(object): "/%(src_section)s/%(prefix)s/%(src_pkg)s" \ "/%(src_pkg)s_%(src_ver)s/changelog" else: - return _("The list of changes is not available") + res = _("The list of changes is not available") + return res if isinstance(res, unicode) else res.decode("utf-8") # get the src package name src_pkg = self.candidate.source_name @@ -1066,15 +1067,15 @@ class Package(object): # Check if the download was canceled if cancel_lock and cancel_lock.isSet(): - return "" + return u"" changelog_file = urllib2.urlopen(uri) # do only get the lines that are new - changelog = "" + changelog = u"" regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg)) while True: # Check if the download was canceled if cancel_lock and cancel_lock.isSet(): - return "" + return u"" # Read changelog line by line line_raw = changelog_file.readline() if line_raw == "": @@ -1094,6 +1095,7 @@ class Package(object): changelog_ver = match.group(1) if changelog_ver and ":" in changelog_ver: changelog_ver = changelog_ver.split(":", 1)[1] + if (installed and apt_pkg.version_compare( changelog_ver, installed) <= 0): break @@ -1103,17 +1105,21 @@ class Package(object): # Print an error if we failed to extract a changelog if len(changelog) == 0: changelog = _("The list of changes is not available") + if not isinstance(changelog, unicode): + changelog = changelog.decode("utf-8") self._changelog = changelog except urllib2.HTTPError: - return _("The list of changes is not available yet.\n\n" + res = _("The list of changes is not available yet.\n\n" "Please use http://launchpad.net/ubuntu/+source/%s/" "%s/+changelog\n" "until the changes become available or try again " "later.") % (src_pkg, src_ver) + return res if isinstance(res, unicode) else res.decode("utf-8") except (IOError, httplib.BadStatusLine): - return _("Failed to download the list of changes. \nPlease " + res = _("Failed to download the list of changes. \nPlease " "check your Internet connection.") + return res if isinstance(res, unicode) else res.decode("utf-8") finally: socket.setdefaulttimeout(timeout) return self._changelog |
