From 032c4091c3ff4df67c56abf44073bd7f65c45dfc Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 15 Jul 2014 18:40:47 +0200 Subject: [PATCH] Some easy python3 compatibility changes. --- Makefile | 2 +- linkcheck/plugins/parsepdf.py | 2 +- linkcheck/robotparser2.py | 2 +- setup.py | 10 +++++++--- tests/__init__.py | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 99c94668..8deb0888 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PYVER:=2.7 PYTHON?=python$(PYVER) VERSION:=$(shell $(PYTHON) setup.py --version) -PLATFORM:=$(shell $(PYTHON) -c "from distutils.util import get_platform; print get_platform()") +PLATFORM:=$(shell $(PYTHON) -c "from __future__ import print_function; from distutils.util import get_platform; print(get_platform())") APPNAME:=$(shell $(PYTHON) setup.py --name) AUTHOR:=$(shell $(PYTHON) setup.py --author) MAINTAINER:=$(shell $(PYTHON) setup.py --maintainer) diff --git a/linkcheck/plugins/parsepdf.py b/linkcheck/plugins/parsepdf.py index d33c800a..94a1d144 100755 --- a/linkcheck/plugins/parsepdf.py +++ b/linkcheck/plugins/parsepdf.py @@ -86,7 +86,7 @@ class PdfParser(_ParserPlugin): search_url(page.attrs["Contents"], url_data, pageno, set()) if "Annots" in page.attrs: search_url(page.attrs["Annots"], url_data, pageno, set()) - except PSException, msg: + except PSException as msg: if not msg.args: # at least show the class name msg = repr(msg) diff --git a/linkcheck/robotparser2.py b/linkcheck/robotparser2.py index c3da7179..e8f2fdf7 100644 --- a/linkcheck/robotparser2.py +++ b/linkcheck/robotparser2.py @@ -99,7 +99,7 @@ class RobotFileParser (object): else: log.debug(LOG_CHECK, "%r allow all (no text content)", self.url) self.allow_all = True - except requests.HTTPError, x: + except requests.HTTPError as x: if x.response.status_code in (401, 403): self.disallow_all = True log.debug(LOG_CHECK, "%r disallow all (code %d)", self.url, x.response.status_code) diff --git a/setup.py b/setup.py index f28a9db3..b42ed8ca 100755 --- a/setup.py +++ b/setup.py @@ -45,6 +45,10 @@ import subprocess import stat import glob import shutil +try: + unicode +except NameError: + unicode = lambda x: x # if a frozen Unix application should be built with cx_Freeze do_freeze = int(os.environ.get('LINKCHECKER_FREEZE', '0')) @@ -291,7 +295,7 @@ def sign_the_code (dist_dir): print("*** signing the application code ***") try: subprocess.check_call(args) - except subprocess.CalledProcessError, msg: + except subprocess.CalledProcessError as msg: print("WARN: codesigning failed", msg) @@ -416,8 +420,8 @@ class MyInstallData (install_data, object): for path in self.get_outputs(): mode = os.stat(path)[stat.ST_MODE] if stat.S_ISDIR(mode): - mode |= 011 - mode |= 044 + mode |= 0o11 + mode |= 0o44 os.chmod(path, mode) diff --git a/tests/__init__.py b/tests/__init__.py index 41d3e10f..7dcfd5d2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -280,7 +280,7 @@ def limit_time (seconds, skip=False): try: with _limit_time(seconds): return func(*args, **kwargs) - except LinkCheckerInterrupt, msg: + except LinkCheckerInterrupt as msg: if skip: pytest.skip("time limit of %d seconds exceeded" % seconds) assert False, msg