diff --git a/bin/pyqso b/bin/pyqso
index 88d553a..644b709 100755
--- a/bin/pyqso
+++ b/bin/pyqso
@@ -19,7 +19,10 @@
from gi.repository import Gtk, GdkPixbuf
import argparse
-import configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
import os
import os.path
import sys
@@ -56,11 +59,13 @@ class PyQSO(Gtk.Window):
Gtk.Window.__init__(self, title="PyQSO")
# Check that the directory for holding PyQSO configuration files exists. If it doesn't, create it now.
- try:
- os.makedirs(os.path.expanduser('~/.config/pyqso'), exist_ok=True)
- except Exception as e:
- logging.error("An error occurred whilst creating a directory for PyQSO configuration files. Try creating the directory '~/.config/pyqso' manually.")
- logging.exception(e)
+ config_directory = os.path.expanduser('~/.config/pyqso')
+ if not os.path.exists(config_directory):
+ try:
+ os.makedirs(config_directory)
+ except Exception as e:
+ logging.error("An error occurred whilst creating a directory for PyQSO configuration files. Try creating the directory '~/.config/pyqso' manually.")
+ logging.exception(e)
# Get any application-specific preferences from the configuration file
config = configparser.ConfigParser()
diff --git a/pyqso/adif.py b/pyqso/adif.py
index da139ab..ee14c89 100644
--- a/pyqso/adif.py
+++ b/pyqso/adif.py
@@ -22,7 +22,10 @@ import logging
import unittest
from datetime import datetime
import calendar
-import configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
from os.path import expanduser
# ADIF field names and their associated data types available in PyQSO.
diff --git a/pyqso/callsign_lookup.py b/pyqso/callsign_lookup.py
index 1c45983..870f924 100644
--- a/pyqso/callsign_lookup.py
+++ b/pyqso/callsign_lookup.py
@@ -19,8 +19,14 @@
import logging
import unittest
-import unittest.mock
-import http.client
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
+try:
+ import http.client as http_client
+except ImportError:
+ import httplib as http_client
from xml.dom import minidom
from pyqso.auxiliary_dialogs import *
@@ -50,7 +56,7 @@ class CallsignLookupQRZ():
"""
logging.debug("Connecting to the qrz.com server...")
try:
- self.connection = http.client.HTTPConnection('xmldata.qrz.com')
+ self.connection = http_client.HTTPConnection('xmldata.qrz.com')
request = '/xml/current/?username=%s;password=%s;agent=pyqso' % (username, password)
self.connection.request('GET', request)
response = self.connection.getresponse()
@@ -176,7 +182,7 @@ class CallsignLookupHamQTH():
logging.debug("Connecting to the hamqth.com server...")
try:
- self.connection = http.client.HTTPConnection('www.hamqth.com')
+ self.connection = http_client.HTTPConnection('www.hamqth.com')
request = '/xml.php?u=%s&p=%s' % (username, password)
self.connection.request('GET', request)
response = self.connection.getresponse()
@@ -347,10 +353,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_qrz_connect(self):
""" Check the example response from the qrz.com server, and make sure the session key has been correctly extracted. """
- http.client.HTTPConnection = unittest.mock.Mock(spec=http.client.HTTPConnection)
- http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse)
- connection = http.client.HTTPConnection()
- response = http.client.HTTPResponse()
+ http_client.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
+ http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
+ connection = http_client.HTTPConnection()
+ response = http_client.HTTPResponse()
response.read.return_value = b'\n\n\n3b1fd1d3ba495189984f93ff67bd45b6\n61\nnon-subscriber\nSun Nov 22 21:25:34 2015\ncpu: 0.147s\n\n\n'
connection.getresponse.return_value = response
@@ -362,10 +368,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_qrz_lookup(self):
""" Check the example callsign lookup response from the qrz.com server, and make sure the callsign information has been correctly extracted. """
- http.client.HTTPConnection = unittest.mock.Mock(spec=http.client.HTTPConnection)
- http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse)
- connection = http.client.HTTPConnection()
- response = http.client.HTTPResponse()
+ http_client.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
+ http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
+ connection = http_client.HTTPConnection()
+ response = http_client.HTTPResponse()
response.read.return_value = b'\n\n\nMYCALL\nFIRSTNAME\nLASTNAME\nADDRESS2\nCOUNTRY\n\n\n3b1fd1d3ba495189984f93ff67bd45b6\n61\nnon-subscriber\nA subscription is required to access the complete record.\nSun Nov 22 21:34:46 2015\ncpu: 0.026s\n\n\n'
connection.getresponse.return_value = response
@@ -380,10 +386,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_hamqth_connect(self):
""" Check the example response from the hamqth.com server, and make sure the session ID has been correctly extracted. """
- http.client.HTTPConnection = unittest.mock.Mock(spec=http.client.HTTPConnection)
- http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse)
- connection = http.client.HTTPConnection()
- response = http.client.HTTPResponse()
+ http_client.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
+ http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
+ connection = http_client.HTTPConnection()
+ response = http_client.HTTPResponse()
response.read.return_value = b'\n\n\n09b0ae90050be03c452ad235a1f2915ad684393c\n\n\n'
connection.getresponse.return_value = response
@@ -395,10 +401,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_hamqth_lookup(self):
""" Check the example callsign lookup response from the hamqth.com server, and make sure the callsign information has been correctly extracted. """
- http.client.HTTPConnection = unittest.mock.Mock(spec=http.client.HTTPConnection)
- http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse)
- connection = http.client.HTTPConnection()
- response = http.client.HTTPResponse()
+ http_client.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
+ http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
+ connection = http_client.HTTPConnection()
+ response = http_client.HTTPResponse()
response.read.return_value = b'\n\n\nMYCALL\nNAME\nCOUNTRY\nITU\nCQ\nGRID\nADDRESS\n\n\n'
connection.getresponse.return_value = response
diff --git a/pyqso/dx_cluster.py b/pyqso/dx_cluster.py
index df14bc4..3a34a2b 100644
--- a/pyqso/dx_cluster.py
+++ b/pyqso/dx_cluster.py
@@ -21,8 +21,14 @@ from gi.repository import Gtk, GObject
import logging
import telnetlib
import unittest
-import unittest.mock
-import configparser
+try:
+ import unittest.mock as mock
+except ImportError:
+ import mock
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
import os.path
from pyqso.telnet_connection_dialog import *
@@ -343,7 +349,7 @@ class TestDXCluster(unittest.TestCase):
def test_on_telnet_io(self):
""" Check that the response from the Telnet server can be correctly decoded. """
- telnetlib.Telnet = unittest.mock.Mock(spec=telnetlib.Telnet)
+ telnetlib.Telnet = mock.Mock(spec=telnetlib.Telnet)
connection = telnetlib.Telnet("hello", "world")
connection.read_very_eager.return_value = b"Test message from the Telnet server."
self.dxcluster.connection = connection
diff --git a/pyqso/logbook.py b/pyqso/logbook.py
index d3f22dd..8616b87 100644
--- a/pyqso/logbook.py
+++ b/pyqso/logbook.py
@@ -22,8 +22,10 @@ import logging
import sqlite3 as sqlite
from os.path import basename, getmtime, expanduser
from datetime import datetime, date
-import configparser
-
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
try:
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
from matplotlib.figure import Figure
diff --git a/pyqso/menu.py b/pyqso/menu.py
index 4c8b078..fe1e0dd 100644
--- a/pyqso/menu.py
+++ b/pyqso/menu.py
@@ -19,7 +19,10 @@
from gi.repository import Gtk
import logging
-import configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
import os.path
diff --git a/pyqso/preferences_dialog.py b/pyqso/preferences_dialog.py
index 60c4b13..aa432ba 100644
--- a/pyqso/preferences_dialog.py
+++ b/pyqso/preferences_dialog.py
@@ -19,7 +19,10 @@
from gi.repository import Gtk
import logging
-import configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
import os.path
import base64
try:
diff --git a/pyqso/record_dialog.py b/pyqso/record_dialog.py
index 4b934a3..2391369 100644
--- a/pyqso/record_dialog.py
+++ b/pyqso/record_dialog.py
@@ -19,7 +19,10 @@
from gi.repository import Gtk
import logging
-import configparser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
from datetime import datetime
from os.path import expanduser
import base64