diff options
| -rw-r--r-- | apt/auth.py | 2 | ||||
| -rw-r--r-- | apt/debfile.py | 4 | ||||
| -rw-r--r-- | apt/package.py | 26 | ||||
| -rw-r--r-- | apt/progress/base.py | 3 | ||||
| -rw-r--r-- | apt/progress/text.py | 15 | ||||
| -rw-r--r-- | setup.py | 8 |
6 files changed, 33 insertions, 25 deletions
diff --git a/apt/auth.py b/apt/auth.py index 814cf1dc..6fe7c01a 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -81,7 +81,7 @@ def _call_apt_key_script(*args, **kwargs): content = kwargs.get("stdin", None) # py2 needs this encoded, py3.3 will crash if it is - if isinstance(content, unicode) and sys.version_info[:2] < (3, 3): + if sys.version_info.major < 3 and isinstance(content, unicode): content = content.encode("utf-8") output, stderr = proc.communicate(content) diff --git a/apt/debfile.py b/apt/debfile.py index 1dd1a372..ca38fdc0 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -27,7 +27,7 @@ import os import sys from apt_pkg import gettext as _ -from StringIO import StringIO +from io import StringIO class NoDebArchiveException(IOError): @@ -637,7 +637,7 @@ class DebPackage(object): data += gz.read() # auto-convert to hex try: - data = unicode(data, "utf-8") + data = data.decode("utf-8") except Exception: new_data = _("Automatically converted to printable ascii:\n") new_data += self.to_strish(data) diff --git a/apt/package.py b/apt/package.py index f7f07680..34c1b91e 100644 --- a/apt/package.py +++ b/apt/package.py @@ -21,13 +21,20 @@ """Functionality related to packages.""" from __future__ import print_function -import httplib + import os import sys import re import socket import subprocess -import urllib2 + +try: + from http.client import BadStatusLine + from urllib.error import HTTPError + from urllib.request import urlopen +except ImportError: + from httplib import BadStatusLine + from urllib2 import HTTPError, urlopen from collections import Mapping, Sequence @@ -38,6 +45,9 @@ from apt_pkg import gettext as _ __all__ = ('BaseDependency', 'Dependency', 'Origin', 'Package', 'Record', 'Version', 'VersionList') +if sys.version_info.major >= 3: + unicode = str + def _file_is_same(path, size, md5): """Return ``True`` if the file is the same.""" @@ -325,14 +335,14 @@ class Version(object): try: if not isinstance(dsc, unicode): # Only convert where needed (i.e. Python 2.X) - dsc = unicode(dsc, "utf-8") + dsc = dsc.decode("utf-8") except UnicodeDecodeError as err: return _("Invalid unicode in description for '%s' (%s). " "Please report.") % (self.package.name, err) lines = iter(dsc.split("\n")) # Skip the first line, since its a duplication of the summary - lines.next() + next(lines) for raw_line in lines: if raw_line.strip() == ".": # The line is just line break @@ -517,7 +527,7 @@ class Version(object): .. versionadded:: 0.7.10 """ try: - return iter(self._uris()).next() + return next(iter(self._uris())) except StopIteration: return None @@ -970,7 +980,7 @@ class Package(object): if cancel_lock and cancel_lock.isSet(): return u"" # FIXME: python3.2: Should be closed manually - changelog_file = urllib2.urlopen(uri) + changelog_file = urlopen(uri) # do only get the lines that are new changelog = u"" regexp = "^%s \((.*)\)(.*)$" % (re.escape(src_pkg)) @@ -1011,14 +1021,14 @@ class Package(object): changelog = changelog.decode("utf-8") self._changelog = changelog - except urllib2.HTTPError: + except HTTPError: 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): + except (IOError, BadStatusLine): res = _("Failed to download the list of changes. \nPlease " "check your Internet connection.") return res if isinstance(res, unicode) else res.decode("utf-8") diff --git a/apt/progress/base.py b/apt/progress/base.py index 66d56173..95eca9ec 100644 --- a/apt/progress/base.py +++ b/apt/progress/base.py @@ -271,7 +271,8 @@ class InstallProgress(object): try: select.select([self.status_stream], [], [], self.select_timeout) - except select.error as (errno_, _errstr): + except select.error as error: + (errno_, _errstr) = error.args if errno_ != errno.EINTR: raise diff --git a/apt/progress/text.py b/apt/progress/text.py index 880a112c..d1f87539 100644 --- a/apt/progress/text.py +++ b/apt/progress/text.py @@ -25,6 +25,11 @@ from apt.progress import base __all__ = ['AcquireProgress', 'CdromProgress', 'OpProgress'] +if sys.version_info.major < 3: + input = raw_input +else: + long = int + def _(msg): """Translate the message, also try apt if translation is missing.""" @@ -93,7 +98,7 @@ class AcquireProgress(base.AcquireProgress, TextProgress): base.AcquireProgress.__init__(self) self._signal = None self._width = 80 - self._id = 1 + self._id = long(1) def start(self): """Start an Acquire progress. @@ -106,7 +111,7 @@ class AcquireProgress(base.AcquireProgress, TextProgress): self._signal = signal.signal(signal.SIGWINCH, self._winch) # Get the window size. self._winch() - self._id = 1L + self._id = long(1) def _winch(self, *dummy): """Signal handler for window resize signals.""" @@ -217,7 +222,7 @@ class AcquireProgress(base.AcquireProgress, TextProgress): self._write(_("Media change: please insert the disc labeled\n" " '%s'\n" "in the drive '%s' and press enter\n") % (medium, drive)) - return raw_input() not in ('c', 'C') + return input() not in ('c', 'C') def stop(self): """Invoked when the Acquire process stops running.""" @@ -242,7 +247,7 @@ class CdromProgress(base.CdromProgress, TextProgress): self._write(_("Please provide a name for this Disc, such as " "'Debian 2.1r1 Disk 1'"), False) try: - return raw_input(":") + return input(":") except KeyboardInterrupt: return @@ -258,6 +263,6 @@ class CdromProgress(base.CdromProgress, TextProgress): self._write(_("Please insert a Disc in the drive and press enter"), False) try: - return (raw_input() == '') + return (input() == '') except KeyboardInterrupt: return False @@ -23,14 +23,6 @@ try: except ImportError: print('W: [python%s] Sphinx import error.' % sys.version[:3]) -if sys.version_info[0] == 3: - from distutils.command.build_py import build_py_2to3 - from lib2to3.refactor import get_fixers_from_package - cmdclass['build_py'] = build_py_2to3 - cmdclass['build_py'].fixer_names = sorted( - set(get_fixers_from_package("lib2to3.fixes")) - - set(["lib2to3.fixes.fix_future"])) - # The apt_pkg module. files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'configuration.cc', 'depcache.cc', 'generic.cc', 'hashes.cc', |
