From 47f5e2ffb4253b57271e76444e465da425752239 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 26 Dec 2021 10:31:04 +0100 Subject: [PATCH] Remove python2 urllib imports Fix for "javascript:" script links in identifier --- cps/db.py | 3 +++ cps/helper.py | 5 +---- cps/kobo.py | 6 +----- cps/redirect.py | 6 ++---- cps/services/SyncToken.py | 7 ++----- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/cps/db.py b/cps/db.py index 9c5b5657..470ecc1c 100644 --- a/cps/db.py +++ b/cps/db.py @@ -23,6 +23,7 @@ import re import ast import json from datetime import datetime +from urllib.parse import quote from sqlalchemy import create_engine from sqlalchemy import Table, Column, ForeignKey, CheckConstraint @@ -166,6 +167,8 @@ class Identifiers(Base): return u"https://portal.issn.org/resource/ISSN/{0}".format(self.val) elif format_type == "isfdb": return u"http://www.isfdb.org/cgi-bin/pl.cgi?{0}".format(self.val) + elif self.val.lower().startswith("javascript:"): + return quote(self.val) else: return u"{0}".format(self.val) diff --git a/cps/helper.py b/cps/helper.py index b8499a12..e8a0b738 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -38,11 +38,8 @@ from sqlalchemy.sql.expression import true, false, and_, text, func from werkzeug.datastructures import Headers from werkzeug.security import generate_password_hash from markupsafe import escape +from urllib.parse import quote -try: - from urllib.parse import quote -except ImportError: - from urllib import quote try: import unidecode diff --git a/cps/kobo.py b/cps/kobo.py index e0395855..b5ff000e 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -23,11 +23,7 @@ import os import uuid from time import gmtime, strftime import json - -try: - from urllib import unquote -except ImportError: - from urllib.parse import unquote +from urllib.parse import unquote from flask import ( Blueprint, diff --git a/cps/redirect.py b/cps/redirect.py index d491b353..8bd68109 100644 --- a/cps/redirect.py +++ b/cps/redirect.py @@ -27,10 +27,8 @@ # http://flask.pocoo.org/snippets/62/ -try: - from urllib.parse import urlparse, urljoin -except ImportError: - from urlparse import urlparse, urljoin +from urllib.parse import urlparse, urljoin + from flask import request, url_for, redirect diff --git a/cps/services/SyncToken.py b/cps/services/SyncToken.py index 85ed5032..2e23efe2 100644 --- a/cps/services/SyncToken.py +++ b/cps/services/SyncToken.py @@ -21,11 +21,8 @@ import sys from base64 import b64decode, b64encode from jsonschema import validate, exceptions, __version__ from datetime import datetime -try: - # pylint: disable=unused-import - from urllib import unquote -except ImportError: - from urllib.parse import unquote + +from urllib.parse import unquote from flask import json from .. import logger