Continue to support Python 2.x modules. Thanks to @gaionim (IU2HDS) for this patch. Fixes issue #50.

pull/51/head
Christian T. Jacobs 2017-02-07 14:17:14 +00:00
rodzic 4124c4c040
commit a65e34db65
8 zmienionych plików z 66 dodań i 35 usunięć

Wyświetl plik

@ -19,7 +19,10 @@
from gi.repository import Gtk, GdkPixbuf from gi.repository import Gtk, GdkPixbuf
import argparse import argparse
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
import os import os
import os.path import os.path
import sys import sys
@ -56,11 +59,13 @@ class PyQSO(Gtk.Window):
Gtk.Window.__init__(self, title="PyQSO") Gtk.Window.__init__(self, title="PyQSO")
# Check that the directory for holding PyQSO configuration files exists. If it doesn't, create it now. # Check that the directory for holding PyQSO configuration files exists. If it doesn't, create it now.
try: config_directory = os.path.expanduser('~/.config/pyqso')
os.makedirs(os.path.expanduser('~/.config/pyqso'), exist_ok=True) if not os.path.exists(config_directory):
except Exception as e: try:
logging.error("An error occurred whilst creating a directory for PyQSO configuration files. Try creating the directory '~/.config/pyqso' manually.") os.makedirs(config_directory)
logging.exception(e) 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 # Get any application-specific preferences from the configuration file
config = configparser.ConfigParser() config = configparser.ConfigParser()

Wyświetl plik

@ -22,7 +22,10 @@ import logging
import unittest import unittest
from datetime import datetime from datetime import datetime
import calendar import calendar
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
from os.path import expanduser from os.path import expanduser
# ADIF field names and their associated data types available in PyQSO. # ADIF field names and their associated data types available in PyQSO.

Wyświetl plik

@ -19,8 +19,14 @@
import logging import logging
import unittest import unittest
import unittest.mock try:
import http.client 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 xml.dom import minidom
from pyqso.auxiliary_dialogs import * from pyqso.auxiliary_dialogs import *
@ -50,7 +56,7 @@ class CallsignLookupQRZ():
""" """
logging.debug("Connecting to the qrz.com server...") logging.debug("Connecting to the qrz.com server...")
try: 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) request = '/xml/current/?username=%s;password=%s;agent=pyqso' % (username, password)
self.connection.request('GET', request) self.connection.request('GET', request)
response = self.connection.getresponse() response = self.connection.getresponse()
@ -176,7 +182,7 @@ class CallsignLookupHamQTH():
logging.debug("Connecting to the hamqth.com server...") logging.debug("Connecting to the hamqth.com server...")
try: 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) request = '/xml.php?u=%s&p=%s' % (username, password)
self.connection.request('GET', request) self.connection.request('GET', request)
response = self.connection.getresponse() response = self.connection.getresponse()
@ -347,10 +353,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_qrz_connect(self): def test_qrz_connect(self):
""" Check the example response from the qrz.com server, and make sure the session key has been correctly extracted. """ """ 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.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse) http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
connection = http.client.HTTPConnection() connection = http_client.HTTPConnection()
response = http.client.HTTPResponse() response = http_client.HTTPResponse()
response.read.return_value = b'<?xml version="1.0" encoding="utf-8" ?>\n<QRZDatabase version="1.33" xmlns="http://xmldata.qrz.com">\n<Session>\n<Key>3b1fd1d3ba495189984f93ff67bd45b6</Key>\n<Count>61</Count>\n<SubExp>non-subscriber</SubExp>\n<GMTime>Sun Nov 22 21:25:34 2015</GMTime>\n<Remark>cpu: 0.147s</Remark>\n</Session>\n</QRZDatabase>\n' response.read.return_value = b'<?xml version="1.0" encoding="utf-8" ?>\n<QRZDatabase version="1.33" xmlns="http://xmldata.qrz.com">\n<Session>\n<Key>3b1fd1d3ba495189984f93ff67bd45b6</Key>\n<Count>61</Count>\n<SubExp>non-subscriber</SubExp>\n<GMTime>Sun Nov 22 21:25:34 2015</GMTime>\n<Remark>cpu: 0.147s</Remark>\n</Session>\n</QRZDatabase>\n'
connection.getresponse.return_value = response connection.getresponse.return_value = response
@ -362,10 +368,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_qrz_lookup(self): 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. """ """ 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.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse) http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
connection = http.client.HTTPConnection() connection = http_client.HTTPConnection()
response = http.client.HTTPResponse() response = http_client.HTTPResponse()
response.read.return_value = b'<?xml version="1.0" encoding="utf-8" ?>\n<QRZDatabase version="1.33" xmlns="http://xmldata.qrz.com">\n<Callsign>\n<call>MYCALL</call>\n<fname>FIRSTNAME</fname>\n<name>LASTNAME</name>\n<addr2>ADDRESS2</addr2>\n<country>COUNTRY</country>\n</Callsign>\n<Session>\n<Key>3b1fd1d3ba495189984f93ff67bd45b6</Key>\n<Count>61</Count>\n<SubExp>non-subscriber</SubExp>\n<Message>A subscription is required to access the complete record.</Message>\n<GMTime>Sun Nov 22 21:34:46 2015</GMTime>\n<Remark>cpu: 0.026s</Remark>\n</Session>\n</QRZDatabase>\n' response.read.return_value = b'<?xml version="1.0" encoding="utf-8" ?>\n<QRZDatabase version="1.33" xmlns="http://xmldata.qrz.com">\n<Callsign>\n<call>MYCALL</call>\n<fname>FIRSTNAME</fname>\n<name>LASTNAME</name>\n<addr2>ADDRESS2</addr2>\n<country>COUNTRY</country>\n</Callsign>\n<Session>\n<Key>3b1fd1d3ba495189984f93ff67bd45b6</Key>\n<Count>61</Count>\n<SubExp>non-subscriber</SubExp>\n<Message>A subscription is required to access the complete record.</Message>\n<GMTime>Sun Nov 22 21:34:46 2015</GMTime>\n<Remark>cpu: 0.026s</Remark>\n</Session>\n</QRZDatabase>\n'
connection.getresponse.return_value = response connection.getresponse.return_value = response
@ -380,10 +386,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_hamqth_connect(self): def test_hamqth_connect(self):
""" Check the example response from the hamqth.com server, and make sure the session ID has been correctly extracted. """ """ 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.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse) http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
connection = http.client.HTTPConnection() connection = http_client.HTTPConnection()
response = http.client.HTTPResponse() response = http_client.HTTPResponse()
response.read.return_value = b'<?xml version="1.0"?>\n<HamQTH version="2.6" xmlns="https://www.hamqth.com">\n<session>\n<session_id>09b0ae90050be03c452ad235a1f2915ad684393c</session_id>\n</session>\n</HamQTH>\n' response.read.return_value = b'<?xml version="1.0"?>\n<HamQTH version="2.6" xmlns="https://www.hamqth.com">\n<session>\n<session_id>09b0ae90050be03c452ad235a1f2915ad684393c</session_id>\n</session>\n</HamQTH>\n'
connection.getresponse.return_value = response connection.getresponse.return_value = response
@ -395,10 +401,10 @@ class TestCallsignLookup(unittest.TestCase):
def test_hamqth_lookup(self): 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. """ """ 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.HTTPConnection = mock.Mock(spec=http_client.HTTPConnection)
http.client.HTTPResponse = unittest.mock.Mock(spec=http.client.HTTPResponse) http_client.HTTPResponse = mock.Mock(spec=http_client.HTTPResponse)
connection = http.client.HTTPConnection() connection = http_client.HTTPConnection()
response = http.client.HTTPResponse() response = http_client.HTTPResponse()
response.read.return_value = b'<?xml version="1.0"?>\n<HamQTH version="2.6" xmlns="https://www.hamqth.com">\n<search>\n<callsign>MYCALL</callsign>\n<nick>NAME</nick>\n<country>COUNTRY</country>\n<itu>ITU</itu>\n<cq>CQ</cq>\n<grid>GRID</grid>\n<adr_street1>ADDRESS</adr_street1>\n</search>\n</HamQTH>\n' response.read.return_value = b'<?xml version="1.0"?>\n<HamQTH version="2.6" xmlns="https://www.hamqth.com">\n<search>\n<callsign>MYCALL</callsign>\n<nick>NAME</nick>\n<country>COUNTRY</country>\n<itu>ITU</itu>\n<cq>CQ</cq>\n<grid>GRID</grid>\n<adr_street1>ADDRESS</adr_street1>\n</search>\n</HamQTH>\n'
connection.getresponse.return_value = response connection.getresponse.return_value = response

Wyświetl plik

@ -21,8 +21,14 @@ from gi.repository import Gtk, GObject
import logging import logging
import telnetlib import telnetlib
import unittest import unittest
import unittest.mock try:
import configparser import unittest.mock as mock
except ImportError:
import mock
try:
import configparser
except ImportError:
import ConfigParser as configparser
import os.path import os.path
from pyqso.telnet_connection_dialog import * from pyqso.telnet_connection_dialog import *
@ -343,7 +349,7 @@ class TestDXCluster(unittest.TestCase):
def test_on_telnet_io(self): def test_on_telnet_io(self):
""" Check that the response from the Telnet server can be correctly decoded. """ """ 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 = telnetlib.Telnet("hello", "world")
connection.read_very_eager.return_value = b"Test message from the Telnet server." connection.read_very_eager.return_value = b"Test message from the Telnet server."
self.dxcluster.connection = connection self.dxcluster.connection = connection

Wyświetl plik

@ -22,8 +22,10 @@ import logging
import sqlite3 as sqlite import sqlite3 as sqlite
from os.path import basename, getmtime, expanduser from os.path import basename, getmtime, expanduser
from datetime import datetime, date from datetime import datetime, date
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
try: try:
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
from matplotlib.figure import Figure from matplotlib.figure import Figure

Wyświetl plik

@ -19,7 +19,10 @@
from gi.repository import Gtk from gi.repository import Gtk
import logging import logging
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
import os.path import os.path

Wyświetl plik

@ -19,7 +19,10 @@
from gi.repository import Gtk from gi.repository import Gtk
import logging import logging
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
import os.path import os.path
import base64 import base64
try: try:

Wyświetl plik

@ -19,7 +19,10 @@
from gi.repository import Gtk from gi.repository import Gtk
import logging import logging
import configparser try:
import configparser
except ImportError:
import ConfigParser as configparser
from datetime import datetime from datetime import datetime
from os.path import expanduser from os.path import expanduser
import base64 import base64