removed support for python 2.7

This commit is contained in:
Tobias Wellnitz, DH1TW 2023-12-28 20:42:20 +01:00
parent 0368988366
commit e6228a1b0b
9 changed files with 29 additions and 104 deletions

View file

@ -12,19 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
from pyhamtools.version import __version__, __release__
sys.path.insert(0,"/Users/user/projects/pyhamtools/pyhamtools")
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
@ -52,7 +41,7 @@ master_doc = 'index'
# General information about the project.
project = u'pyhamtools'
copyright = u'2019, Tobias Wellnitz, DH1TW'
copyright = u'2024, Tobias Wellnitz, DH1TW'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the

View file

@ -1,18 +1,11 @@
import re
import logging
from datetime import datetime, timezone
import sys
from pyhamtools.consts import LookupConventions as const
from pyhamtools.callsign_exceptions import callsign_exceptions
if sys.version_info < (2, 7, ):
class NullHandler(logging.Handler):
def emit(self, record):
pass
class Callinfo(object):
"""
The purpose of this class is to return data (country, latitude, longitude, CQ Zone...etc) for an
@ -33,10 +26,7 @@ class Callinfo(object):
self._logger = logger
else:
self._logger = logging.getLogger(__name__)
if sys.version_info[:2] == (2, 6):
self._logger.addHandler(NullHandler())
else:
self._logger.addHandler(logging.NullHandler())
self._logger.addHandler(logging.NullHandler())
self._lookuplib = lookuplib
self._callsign_info = None

View file

@ -8,8 +8,6 @@ import xml.etree.ElementTree as ET
import urllib
import json
import copy
import sys
import unicodedata
import requests
from requests.exceptions import ConnectionError, HTTPError, Timeout
@ -21,14 +19,6 @@ from .exceptions import APIKeyMissingError
REDIS_LUA_DEL_SCRIPT = "local keys = redis.call('keys', ARGV[1]) \n for i=1,#keys,20000 do \n redis.call('del', unpack(keys, i, math.min(i+19999, #keys))) \n end \n return keys"
if sys.version_info < (2, 7,):
class NullHandler(logging.Handler):
def emit(self, record):
pass
if sys.version_info.major == 3:
unicode = str
class LookupLib(object):
"""
@ -76,10 +66,7 @@ class LookupLib(object):
self._logger = logger
else:
self._logger = logging.getLogger(__name__)
if sys.version_info[:2] == (2, 6):
self._logger.addHandler(NullHandler())
else:
self._logger.addHandler(logging.NullHandler())
self._logger.addHandler(logging.NullHandler())
self._apikey = apikey
self._apiv = apiv
@ -127,10 +114,7 @@ class LookupLib(object):
"agent" : agent
}
if sys.version_info.major == 3:
encodeurl = url + "?" + urllib.parse.urlencode(params)
else:
encodeurl = url + "?" + urllib.urlencode(params)
encodeurl = url + "?" + urllib.parse.urlencode(params)
response = requests.get(encodeurl, timeout=10)
doc = BeautifulSoup(response.text, "xml")
session_key = None
@ -700,10 +684,7 @@ class LookupLib(object):
if timestamp is None:
timestamp = datetime.now(timezone.utc)
if sys.version_info.major == 3:
encodeurl = url + "?" + urllib.parse.urlencode(params)
else:
encodeurl = url + "?" + urllib.urlencode(params)
encodeurl = url + "?" + urllib.parse.urlencode(params)
response = requests.get(encodeurl, timeout=5)
if not self._check_html_response(response):
@ -734,10 +715,7 @@ class LookupLib(object):
"callsign" : callsign,
}
if sys.version_info.major == 3:
encodeurl = url + "?" + urllib.parse.urlencode(params)
else:
encodeurl = url + "?" + urllib.urlencode(params)
encodeurl = url + "?" + urllib.parse.urlencode(params)
response = requests.get(encodeurl, timeout=5)
return response
@ -750,10 +728,7 @@ class LookupLib(object):
"dxcc" : str(dxcc_or_callsign),
}
if sys.version_info.major == 3:
encodeurl = url + "?" + urllib.parse.urlencode(params)
else:
encodeurl = url + "?" + urllib.urlencode(params)
encodeurl = url + "?" + urllib.parse.urlencode(params)
response = requests.get(encodeurl, timeout=5)
return response
@ -965,10 +940,6 @@ class LookupLib(object):
if root.Callsign.geoloc:
lookup[const.GEOLOC] = root.Callsign.geoloc.text
# if sys.version_info >= (2,):
# for item in lookup:
# if isinstance(lookup[item], unicode):
# print item, repr(lookup[item])
return lookup
def _load_clublogXML(self,
@ -1209,10 +1180,10 @@ class LookupLib(object):
entity = {}
for item in cty_entity:
if item.tag == "name":
entity[const.COUNTRY] = unicode(item.text)
self._logger.debug(unicode(item.text))
entity[const.COUNTRY] = str(item.text)
self._logger.debug(str(item.text))
elif item.tag == "prefix":
entity[const.PREFIX] = unicode(item.text)
entity[const.PREFIX] = str(item.text)
elif item.tag == "deleted":
if item.text == "TRUE":
entity[const.DELETED] = True
@ -1221,7 +1192,7 @@ class LookupLib(object):
elif item.tag == "cqz":
entity[const.CQZ] = int(item.text)
elif item.tag == "cont":
entity[const.CONTINENT] = unicode(item.text)
entity[const.CONTINENT] = str(item.text)
elif item.tag == "long":
entity[const.LONGITUDE] = float(item.text)
elif item.tag == "lat":
@ -1263,13 +1234,13 @@ class LookupLib(object):
else:
call_exceptions_index[call] = [int(cty_exception.attrib["record"])]
elif item.tag == "entity":
call_exception[const.COUNTRY] = unicode(item.text)
call_exception[const.COUNTRY] = str(item.text)
elif item.tag == "adif":
call_exception[const.ADIF] = int(item.text)
elif item.tag == "cqz":
call_exception[const.CQZ] = int(item.text)
elif item.tag == "cont":
call_exception[const.CONTINENT] = unicode(item.text)
call_exception[const.CONTINENT] = str(item.text)
elif item.tag == "long":
call_exception[const.LONGITUDE] = float(item.text)
elif item.tag == "lat":
@ -1304,13 +1275,13 @@ class LookupLib(object):
else:
prefixes_index[call] = [int(cty_prefix.attrib["record"])]
if item.tag == "entity":
prefix[const.COUNTRY] = unicode(item.text)
prefix[const.COUNTRY] = str(item.text)
elif item.tag == "adif":
prefix[const.ADIF] = int(item.text)
elif item.tag == "cqz":
prefix[const.CQZ] = int(item.text)
elif item.tag == "cont":
prefix[const.CONTINENT] = unicode(item.text)
prefix[const.CONTINENT] = str(item.text)
elif item.tag == "long":
prefix[const.LONGITUDE] = float(item.text)
elif item.tag == "lat":
@ -1431,12 +1402,12 @@ class LookupLib(object):
for item in cty_list:
entry = {}
call = str(item)
entry[const.COUNTRY] = unicode(cty_list[item]["Country"])
entry[const.COUNTRY] = str(cty_list[item]["Country"])
if mapping:
entry[const.ADIF] = int(mapping[cty_list[item]["Country"]])
entry[const.CQZ] = int(cty_list[item]["CQZone"])
entry[const.ITUZ] = int(cty_list[item]["ITUZone"])
entry[const.CONTINENT] = unicode(cty_list[item]["Continent"])
entry[const.CONTINENT] = str(cty_list[item]["Continent"])
entry[const.LATITUDE] = float(cty_list[item]["Latitude"])
entry[const.LONGITUDE] = float(cty_list[item]["Longitude"])*(-1)
@ -1538,7 +1509,7 @@ class LookupLib(object):
elif item == const.WHITELIST:
my_dict[item] = self._str_to_bool(my_dict[item])
else:
my_dict[item] = unicode(my_dict[item])
my_dict[item] = str(my_dict[item])
return my_dict

View file

@ -1,5 +1,4 @@
#!/usr/bin/env python
import sys
import os
from distutils.core import setup

View file

@ -1,14 +1,9 @@
import os
import sys
import datetime
import pytest
from pyhamtools.qsl import get_clublog_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
@ -26,7 +21,7 @@ class Test_clublog_methods:
data = get_clublog_users()
assert isinstance(data, dict)
for key, value in data.items():
assert isinstance(key, unicode)
assert isinstance(key, str)
assert isinstance(value, dict)
def test_with_invalid_url(self):

View file

@ -1,15 +1,10 @@
from .execfile import execfile
import os
import sys
import datetime
import pytest
from pyhamtools.qsl import get_eqsl_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
class Test_eqsl_methods:
@ -26,7 +21,7 @@ class Test_eqsl_methods:
data = get_eqsl_users()
assert isinstance(data, list)
for el in data:
assert isinstance(el, unicode)
assert isinstance(el, str)
assert len(data) > 1000
def test_with_invalid_url(self):

View file

@ -1,12 +1,8 @@
import pytest
import sys
from pyhamtools.lookuplib import LookupLib
from pyhamtools.exceptions import APIKeyMissingError
if sys.version_info.major == 3:
unicode = str
@pytest.fixture(scope="function", params=[5, -5, "", "foo bar", 11.5, {}, [], None, ("foo", "bar")])
def fixAnyValue(request):
return request.param
@ -40,5 +36,5 @@ class TestlookupLibHelper:
with pytest.raises(TypeError):
fixClublogApi._generate_random_word()
assert type(fixClublogApi._generate_random_word(5)) is unicode
assert type(fixClublogApi._generate_random_word(5)) is str
assert len(fixClublogApi._generate_random_word(5)) == 5

View file

@ -1,10 +1,4 @@
import pytest
import tempfile
import os
import sys
if sys.version_info.major == 3:
unicode = str
from datetime import datetime
@ -57,13 +51,13 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
count = 0
for attr in entity:
if attr == "country":
assert type(entity[attr] is unicode)
assert type(entity[attr] is str)
count +=1
if attr == "continent":
assert type(entity[attr] is unicode)
assert type(entity[attr] is str)
count +=1
if attr == "prefix":
assert type(entity[attr] is unicode)
assert type(entity[attr] is str)
count +=1
if attr == "deleted":
assert type(entity[attr] is bool)
@ -113,10 +107,10 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
assert type(ex[attr]) is float
count +=1
elif attr == "country":
assert type(ex[attr]) is unicode
assert type(ex[attr]) is str
count +=1
elif attr == "continent":
assert type(ex[attr]) is unicode
assert type(ex[attr]) is str
count +=1
elif attr == "cqz":
assert type(ex[attr]) is int
@ -149,7 +143,7 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
count = 0
for attr in prefix:
if attr == "country":
assert type(prefix[attr]) is unicode
assert type(prefix[attr]) is str
count +=1
elif attr == "adif":
assert type(prefix[attr]) is int
@ -161,7 +155,7 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
assert type(prefix[attr]) is int
count +=1
elif attr == "continent":
assert type(prefix[attr]) is unicode
assert type(prefix[attr]) is str
count +=1
elif attr == "latitude":
assert type(prefix[attr]) is float

View file

@ -1,5 +1,4 @@
import os
import sys
import datetime
from .execfile import execfile
@ -18,9 +17,6 @@ def execfile(filepath, globals=None, locals=None):
from pyhamtools.qsl import get_lotw_users
if sys.version_info.major == 3:
unicode = str
test_dir = os.path.dirname(os.path.abspath(__file__))
fix_dir = os.path.join(test_dir, 'fixtures')
@ -38,7 +34,7 @@ class Test_lotw_methods:
data = get_lotw_users()
assert isinstance(data, dict)
for key, value in data.items():
assert isinstance(key, unicode)
assert isinstance(key, str)
assert isinstance(value, datetime.datetime )
assert len(data) > 1000