From efceaa5a5d14994e30c9539e719edd8cddc68366 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 26 Jan 2009 09:08:15 +0100 Subject: apt/package.py: compatibility with python2.4 (pep 341 missing) --- apt/package.py | 105 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/apt/package.py b/apt/package.py index 5a7da1f3..10b55dc6 100644 --- a/apt/package.py +++ b/apt/package.py @@ -594,62 +594,65 @@ class Package(object): "src_ver": src_ver} timeout = socket.getdefaultimeout() + + # FIXME: when python2.4 vanishes from the archive, + # merge this into a single try..finally block (pep 341) try: - # Set a timeout for the changelog download - socket.setdefaulttimeout(2) - - # Check if the download was canceled - if cancel_lock and cancel_lock.isSet(): - return "" - changelog_file = urllib2.urlopen(uri) - # do only get the lines that are new - changelog = "" - regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg)) - - while True: + try: + # Set a timeout for the changelog download + socket.setdefaulttimeout(2) + # Check if the download was canceled if cancel_lock and cancel_lock.isSet(): return "" - # Read changelog line by line - line_raw = changelog_file.readline() - if line_raw == "": - break - # The changelog is encoded in utf-8, but since there isn't any - # http header, urllib2 seems to treat it as ascii - line = line_raw.decode("utf-8") - - #print line.encode('utf-8') - match = re.match(regexp, line) - if match: - # strip epoch from installed version - # and from changelog too - installed = self.installedVersion - if installed and ":" in installed: - installed = installed.split(":", 1)[1] - changelog_ver = match.group(1) - if changelog_ver and ":" in changelog_ver: - changelog_ver = changelog_ver.split(":", 1)[1] - if installed and \ - apt_pkg.VersionCompare(changelog_ver, installed) <= 0: + changelog_file = urllib2.urlopen(uri) + # do only get the lines that are new + changelog = "" + regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg)) + + while True: + # Check if the download was canceled + if cancel_lock and cancel_lock.isSet(): + return "" + # Read changelog line by line + line_raw = changelog_file.readline() + if line_raw == "": break - # EOF (shouldn't really happen) - changelog += line - - # Print an error if we failed to extract a changelog - if len(changelog) == 0: - changelog = _("The list of changes is not available") - self._changelog = changelog - - # FIXME: Ubuntu-specific part. - except urllib2.HTTPError: - return _("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) - except (IOError, httplib.BadStatusLine): - return _("Failed to download the list of changes. \nPlease " - "check your Internet connection.") + # The changelog is encoded in utf-8, but since there isn't any + # http header, urllib2 seems to treat it as ascii + line = line_raw.decode("utf-8") + + #print line.encode('utf-8') + match = re.match(regexp, line) + if match: + # strip epoch from installed version + # and from changelog too + installed = self.installedVersion + if installed and ":" in installed: + installed = installed.split(":", 1)[1] + changelog_ver = match.group(1) + if changelog_ver and ":" in changelog_ver: + changelog_ver = changelog_ver.split(":", 1)[1] + if (installed and + apt_pkg.VersionCompare(changelog_ver, installed) <= 0): + break + # EOF (shouldn't really happen) + changelog += line + + # Print an error if we failed to extract a changelog + if len(changelog) == 0: + changelog = _("The list of changes is not available") + self._changelog = changelog + + except urllib2.HTTPError: + return _("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) + except (IOError, httplib.BadStatusLine): + return _("Failed to download the list of changes. \nPlease " + "check your Internet connection.") finally: socket.setdefaulttimeout(timeout) return self._changelog -- cgit v1.2.3