From 109315d93dcd7137b27970b93b88ccdf84a28faa Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 26 Sep 2019 11:10:52 +0300 Subject: [PATCH] Remove Python 2 warnings, apply lint updates --- .pre-commit-config.yaml | 1 + setup.py | 27 --------------------------- src/pylast/__init__.py | 37 ++++--------------------------------- tests/unicode_test.py | 1 - 4 files changed, 5 insertions(+), 61 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ffb89cb..648afd7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: v1.24.0 hooks: - id: pyupgrade + args: ["--py3-plus"] - repo: https://github.com/psf/black rev: 19.3b0 diff --git a/setup.py b/setup.py index c718213..37d38d2 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -import sys - from setuptools import find_packages, setup version_dict = {} @@ -9,31 +7,6 @@ with open("src/pylast/version.py") as f: version = version_dict["__version__"] -if sys.version_info < (3, 5): - error = """pylast 3.0 and above are no longer compatible with Python 2. - -This is pylast {} and you are using Python {}. -Make sure you have pip >= 9.0 and setuptools >= 24.2 and retry: - - $ pip install --upgrade pip setuptools - -Other choices: - -- Upgrade to Python 3. - -- Install an older version of pylast: - -$ pip install 'pylast<3.0' - -For more information: - -https://github.com/pylast/pylast/issues/265 -""".format( - version, ".".join([str(v) for v in sys.version_info[:3]]) - ) - print(error, file=sys.stderr) - sys.exit(1) - with open("README.md") as f: long_description = f.read() diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 1d3f0ff..18fe9a6 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # pylast - # A Python interface to Last.fm and Libre.fm @@ -26,12 +25,12 @@ import html.entities import logging import shelve import ssl -import sys import tempfile import time import warnings import xml.dom from http.client import HTTPSConnection +from urllib.parse import quote_plus from xml.dom import Node, minidom from . import version @@ -44,34 +43,6 @@ __license__ = "apache2" __email__ = "amr.hassan@gmail.com" __version__ = version.__version__ -if sys.version_info < (3,): - raise ImportError( - """pylast 3.0 and above are no longer compatible with Python 2. - -This is pylast {} and you are using Python {}. -Make sure you have pip >= 9.0 and setuptools >= 24.2 and retry: - - $ pip install --upgrade pip setuptools - -Other choices: - -- Upgrade to Python 3. - -- Install an older version of pylast: - -$ pip install 'pylast<3.0' - -For more information: - -https://github.com/pylast/pylast/issues/265 -""".format( - version, ".".join([str(v) for v in sys.version_info[:3]]) - ) - ) -else: - # Keep importable on Python 2 for a while to show ImportError - from urllib.parse import quote_plus as url_quote_plus - # 1 : This error does not exist STATUS_INVALID_SERVICE = 2 @@ -896,7 +867,7 @@ class _Request: keys = list(self.params.keys()) keys.sort() - cache_key = str() + cache_key = "" for key in keys: if key != "api_sig" and key != "api_key" and key != "sk": @@ -926,7 +897,7 @@ class _Request: data = [] for name in self.params.keys(): - data.append("=".join((name, url_quote_plus(_string(self.params[name]))))) + data.append("=".join((name, quote_plus(_string(self.params[name]))))) data = "&".join(data) headers = { @@ -2932,7 +2903,7 @@ def _extract_tracks(doc, network): def _url_safe(text): """Does all kinds of tricks on a text to make it safe to use in a URL.""" - return url_quote_plus(url_quote_plus(_string(text))).lower() + return quote_plus(quote_plus(_string(text))).lower() def _number(string): diff --git a/tests/unicode_test.py b/tests/unicode_test.py index 11e7ff7..416014e 100644 --- a/tests/unicode_test.py +++ b/tests/unicode_test.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import mock import pylast import pytest