From 94c3eeba4962895a0d89dfcdd75abd36527ba351 Mon Sep 17 00:00:00 2001 From: Bernard Cafarelli Date: Thu, 5 Dec 2019 17:46:19 +0100 Subject: [PATCH] Initial python3 compatibility --- .gitignore | 1 + bin/euscan | 8 ++++---- pym/euscan/__init__.py | 6 +++--- pym/euscan/handlers/__init__.py | 4 ++-- pym/euscan/handlers/berlios.py | 4 ++-- pym/euscan/handlers/cpan.py | 6 +++--- pym/euscan/handlers/deb.py | 4 ++-- pym/euscan/handlers/freecode.py | 8 ++++---- pym/euscan/handlers/generic.py | 10 +++++----- pym/euscan/handlers/github.py | 4 ++-- pym/euscan/handlers/gnome.py | 4 ++-- pym/euscan/handlers/php.py | 4 ++-- pym/euscan/handlers/pypi.py | 4 ++-- pym/euscan/handlers/rubygems.py | 4 ++-- pym/euscan/handlers/url.py | 6 +++--- pym/euscan/helpers.py | 30 +++++++++++++++--------------- pym/euscan/mangling.py | 2 +- pym/euscan/out.py | 8 ++++---- pym/euscan/scan.py | 2 +- setup.py | 4 ++-- 20 files changed, 62 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index 8662176..59b0f67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.*.swp *~ *.py[co] *.egg-info diff --git a/bin/euscan b/bin/euscan index e1c5e8c..6514d0f 100755 --- a/bin/euscan +++ b/bin/euscan @@ -4,7 +4,7 @@ Distributed under the terms of the GNU General Public License v2 """ -from __future__ import print_function + import os # Meta @@ -21,7 +21,7 @@ __description__ = "A tool to detect new upstream releases." import sys import getopt from errno import EINTR, EINVAL -from httplib import HTTPConnection +from http.client import HTTPConnection from portage import settings from portage.output import white, yellow, turquoise, green @@ -270,7 +270,7 @@ def main(): on_progress = None if CONFIG['progress']: on_progress_gen = progress_bar() - on_progress = on_progress_gen.next() + on_progress = next(on_progress_gen) on_progress(maxval=len(queries) * 100, increment=0, label="Working...") # Importing stuff here for performance reasons @@ -322,7 +322,7 @@ def main(): print("") if CONFIG['progress']: - on_progress_gen.next() + next(on_progress_gen) print("\n", file=sys.stderr) output.set_query(None) diff --git a/pym/euscan/__init__.py b/pym/euscan/__init__.py index 2e9deac..95a6a18 100644 --- a/pym/euscan/__init__.py +++ b/pym/euscan/__init__.py @@ -5,7 +5,7 @@ __version__ = "git" -import ConfigParser +import configparser import os from ast import literal_eval @@ -33,7 +33,7 @@ CONFIG = { 'handlers-exclude': [], } -config = ConfigParser.ConfigParser() +config = configparser.ConfigParser() config.read(['/etc/euscan.conf', os.path.expanduser('~/.euscan.conf')]) if config.has_section("euscan"): for key, value in config.items("euscan"): @@ -88,5 +88,5 @@ ROBOTS_TXT_BLACKLIST_DOMAINS = [ '(.*)festvox\.org(.*)', ] -from out import EuscanOutput +from euscan.out import EuscanOutput output = EuscanOutput(CONFIG) diff --git a/pym/euscan/handlers/__init__.py b/pym/euscan/handlers/__init__.py index e89a0fc..bdae6f8 100644 --- a/pym/euscan/handlers/__init__.py +++ b/pym/euscan/handlers/__init__.py @@ -68,7 +68,7 @@ def get_metadata(pkg): output.einfo('Using custom metadata: %s' % meta_override) if not pkg_metadata: pkg_metadata = pkg.metadata - except Exception, e: + except Exception as e: output.ewarn('Error when fetching metadata: %s' % str(e)) if not pkg_metadata: @@ -183,7 +183,7 @@ def scan(pkg, urls, on_progress=None): metadata = get_metadata(pkg) versions = [] - pkg_handlers = find_handlers('package', metadata.keys()) + pkg_handlers = find_handlers('package', list(metadata.keys())) if not pkg_handlers: pkg_handler = find_best_handler('package', pkg) if pkg_handler: diff --git a/pym/euscan/handlers/berlios.py b/pym/euscan/handlers/berlios.py index 11471e4..89c0f0d 100644 --- a/pym/euscan/handlers/berlios.py +++ b/pym/euscan/handlers/berlios.py @@ -1,5 +1,5 @@ import re -import urllib +import urllib.request, urllib.parse, urllib.error import portage @@ -34,7 +34,7 @@ def scan_url(pkg, url, options): project, filename = re.search(berlios_regex, url).groups() project_page = "http://developer.berlios.de/projects/%s" % project - content = urllib.urlopen(project_page).read() + content = urllib.request.urlopen(project_page).read() project_id = re.search( r"/project/filelist.php\?group_id=(\d+)", diff --git a/pym/euscan/handlers/cpan.py b/pym/euscan/handlers/cpan.py index 740ecf8..0456ee6 100644 --- a/pym/euscan/handlers/cpan.py +++ b/pym/euscan/handlers/cpan.py @@ -1,6 +1,6 @@ import re import portage -import urllib2 +import urllib.request, urllib.error, urllib.parse import json from euscan import helpers, output, mangling @@ -52,7 +52,7 @@ def mangle_version(up_pv): if len(splitted) == 2: # Split second part is sub-groups part = splitted.pop() - for i in xrange(0, len(part), 3): + for i in range(0, len(part), 3): splitted.append(part[i:i + 3]) if len(splitted) == 2: # add last group if it's missing @@ -117,7 +117,7 @@ def scan_pkg(pkg, options): try: fp = helpers.urlopen(url) - except urllib2.URLError: + except urllib.error.URLError: return [] except IOError: return [] diff --git a/pym/euscan/handlers/deb.py b/pym/euscan/handlers/deb.py index b559263..f0e3d4b 100644 --- a/pym/euscan/handlers/deb.py +++ b/pym/euscan/handlers/deb.py @@ -1,4 +1,4 @@ -import urllib +import urllib.request, urllib.parse, urllib.error import re import bz2 import zlib @@ -23,7 +23,7 @@ def scan_pkg(pkg, options): output.einfo("Using Debian Packages: " + packages_url) - fp = urllib.urlopen(packages_url) + fp = urllib.request.urlopen(packages_url) content = fp.read() # Support for .gz and .bz2 Packages file diff --git a/pym/euscan/handlers/freecode.py b/pym/euscan/handlers/freecode.py index b811e32..b6f5a70 100644 --- a/pym/euscan/handlers/freecode.py +++ b/pym/euscan/handlers/freecode.py @@ -1,4 +1,4 @@ -import urllib +import urllib.request, urllib.parse, urllib.error import re import portage @@ -21,7 +21,7 @@ def scan_pkg(pkg, options): output.einfo("Using FreeCode handler: " + package) - fp = urllib.urlopen("http://freecode.com/projects/%s/releases" % package) + fp = urllib.request.urlopen("http://freecode.com/projects/%s/releases" % package) content = fp.read() result = re.findall( @@ -34,11 +34,11 @@ def scan_pkg(pkg, options): pv = mangling.mangle_version(up_pv, options) if helpers.version_filtered(cp, ver, pv): continue - fp = urllib.urlopen("http://freecode.com/projects/%s/releases/%s" % + fp = urllib.request.urlopen("http://freecode.com/projects/%s/releases/%s" % (package, release_id)) content = fp.read() download_page = re.findall(r'