diff --git a/bin/euscan b/bin/euscan index ecf9c51..6c3502e 100755 --- a/bin/euscan +++ b/bin/euscan @@ -29,8 +29,8 @@ from portage.exception import AmbiguousPackageName from portage.output import green, turquoise, white, yellow from euscan import CONFIG, output -from euscan.out import progress_bar from euscan._version import __version__ +from euscan.out import progress_bar # Globals isatty = os.environ.get("TERM") != "dumb" and sys.stdout.isatty() @@ -75,7 +75,7 @@ def print_usage(_error=None, help=None): if _error: out = sys.stderr - if not _error in ( + if _error not in ( "global-options", "packages", ): @@ -284,7 +284,7 @@ def parse_args(): # apply getopts to command line, show partial help on failure try: opts, args = getopt.getopt(sys.argv[1:], short_opts, long_opts) - except: + except getopt.GetoptError: raise ParseArgsException(opts_mode + "-options") # set options accordingly diff --git a/bin/euscan_patch_metadata b/bin/euscan_patch_metadata index cd67f76..21cd3de 100755 --- a/bin/euscan_patch_metadata +++ b/bin/euscan_patch_metadata @@ -127,7 +127,7 @@ def get_deb_url(name): if not deb_url: logger.error(" Cannot get package from %s" % url) - name = raw_input(" Package name in Debian: ") + name = input(" Package name in Debian: ") return deb_url, deb_type diff --git a/src/euscan/__init__.py b/src/euscan/__init__.py index 7b9ac92..3fcdf2b 100644 --- a/src/euscan/__init__.py +++ b/src/euscan/__init__.py @@ -84,6 +84,6 @@ ROBOTS_TXT_BLACKLIST_DOMAINS = [ "(.*)festvox\.org(.*)", ] -from euscan.out import EuscanOutput +from euscan.out import EuscanOutput # noqa: E402 output = EuscanOutput(CONFIG) diff --git a/src/euscan/handlers/cpan.py b/src/euscan/handlers/cpan.py index fbd82b6..42dfc28 100644 --- a/src/euscan/handlers/cpan.py +++ b/src/euscan/handlers/cpan.py @@ -27,8 +27,10 @@ def guess_package(cp, url): if match: pkg = match.group(1) try: + # Output is None if input is invalid, therefore TypeError when + # this None is attempted to be unpacked into three variables. cp, ver, rev = portage.pkgsplit("fake/" + pkg) - except: + except TypeError: pass cat, pkg = cp.split("/") @@ -92,7 +94,7 @@ def cpan_mangle_version(pv): def cpan_vercmp(cp, a, b): try: return float(a) - float(b) - except: + except OverflowError: return helpers.simple_vercmp(a, b) @@ -113,7 +115,7 @@ def scan_pkg(pkg, options): options["versionmangle"] = ["cpan", "gentoo"] url = "http://search.cpan.org/api/dist/%s" % remote_pkg - cp, ver, rev = pkg.cp, pkg.version, pkg.revision + cp, ver = pkg.cp, pkg.version m_ver = cpan_mangle_version(ver) output.einfo("Using CPAN API: " + url) diff --git a/src/euscan/handlers/php.py b/src/euscan/handlers/php.py index e931375..4546b13 100644 --- a/src/euscan/handlers/php.py +++ b/src/euscan/handlers/php.py @@ -4,8 +4,6 @@ import urllib.parse import urllib.request import xml.dom.minidom -import portage - from euscan import helpers, mangling, output HANDLER_NAME = "php" @@ -35,7 +33,7 @@ def scan_url(pkg, url, options): def scan_pkg(pkg, options): - cp, ver, rev = pkg.cp, pkg.version, pkg.revision + cp, ver = pkg.cp, pkg.version package = options["data"] channel = options["type"] diff --git a/src/euscan/helpers.py b/src/euscan/helpers.py index 8339d51..ab6e374 100644 --- a/src/euscan/helpers.py +++ b/src/euscan/helpers.py @@ -1,20 +1,16 @@ import errno import os import re +import urllib import urllib.error import urllib.parse import urllib.request +import urllib.robotparser from xml.dom.minidom import Document import portage from portage import dep -try: - from urllib import robotparser, urlparse -except ImportError: - import urllib.robotparser - import urllib.parse - import euscan from euscan import BLACKLIST_VERSIONS, CONFIG, ROBOTS_TXT_BLACKLIST_DOMAINS from euscan.version import parse_version @@ -188,7 +184,9 @@ def join_version(components): version += str(components[i]) if i >= len(components) - 1: break - if type(components[i]) != str and type(components[i + 1]) != str: + if not isinstance(components[i], str) and not isinstance( + components[i + 1], str + ): version += "." return version @@ -200,10 +198,10 @@ def increment_version(components, level): raise Exception for i in range(n, level + 1, -1): - if type(components[i - 1]) == int: + if isinstance(components[i - 1], int): components[i - 1] = 0 - if type(components[level]) == int: + if isinstance(components[level], int): components[level] += 1 return components @@ -278,7 +276,7 @@ def urlallowed(url): try: rp.read() rpcache[baseurl] = rp - except: + except IOError: rp = None setdefaulttimeout(timeout) diff --git a/src/euscan/out.py b/src/euscan/out.py index bb40346..32ed3d0 100644 --- a/src/euscan/out.py +++ b/src/euscan/out.py @@ -69,7 +69,7 @@ def progress_bar(): def clean_colors(string): - if type(string) is str: + if isinstance(string, str): string = re.sub("\033\[[0-9;]+m", "", string) string = re.sub(r"\\u001b\[[0-9;]+m", "", string) string = re.sub(r"\x1b\[[0-9;]+m", "", string)