Greg Albrecht 1 year ago
parent
commit
cdb4c90bfb
16 changed files with 132 additions and 102 deletions
  1. 5 2
      Makefile
  2. 6 0
      README.rst
  3. 6 6
      examples/socket_read.py
  4. 3 3
      kiss/__init__.py
  5. 17 12
      kiss/classes.py
  6. 5 4
      kiss/constants.py
  7. 3 3
      kiss/exceptions.py
  8. 3 3
      kiss/util.py
  9. 0 1
      requirements.txt
  10. 9 7
      setup.py
  11. 4 0
      tests/__init__.py
  12. 15 7
      tests/constants.py
  13. 5 5
      tests/context.py
  14. 16 18
      tests/test_kiss_util.py
  15. 13 13
      tests/test_serialkiss.py
  16. 22 18
      tests/test_tcpkiss.py

+ 5 - 2
Makefile

@ -50,8 +50,11 @@ flake8: pep8
50 50
51 51
lint: remember
52 52
	pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
53
		-r n kiss/*.py tests/*.py || exit 0
53
		-r n --ignore-imports=y kiss/*.py tests/*.py || exit 0
54 54
55 55
pylint: lint
56 56
57
test: lint pep8 nosetests
57
coverage:
58
	coverage report -m
59
	
60
test: lint pep8 nosetests coverage

+ 6 - 0
README.rst

@ -4,6 +4,12 @@ kiss - Python KISS Module
4 4
kiss is a Python Module that implementations the `KISS Protocol <https://en.wikipedia.org/wiki/KISS_(TNC)>`_ for
5 5
communicating with KISS-enabled devices (such as Serial or TCP TNCs).
6 6
7
Versions
8
========
9
10
- 6.5.x branch will be the last version of this Module that supports Python 2.7.x
11
- 7.x.x branch and-on will be Python 3.x ONLY.
12
7 13
Installation
8 14
============
9 15
Install from pypi using pip: ``pip install kiss``

+ 6 - 6
examples/socket_read.py

@ -53,17 +53,17 @@ def main2():
53 53
                            [0xF0, 0xCF]):
54 54
55 55
                        text = frame[frame_slice + 3:]
56
                        print("Text=%s" % text)
56
                        print('Text={}'.format(text))
57 57
58 58
                        dest = aprs.Callsign(frame)
59 59
                        dest2 = aprs.Callsign2(frame, True)
60
                        print(dest)
61
                        print(dest2.callsign)
60
                        print('{}'.format(dest))
61
                        print("{}".format(dest2.callsign))
62 62
63 63
                        src = aprs.Callsign(frame[7:])
64 64
                        src2 = aprs.Callsign2(frame[7:], True)
65
                        print(src)
66
                        print(src2.callsign)
65
                        print("{}".format(src))
66
                        print("{}".format(src2.callsign))
67 67
                        path = []
68 68
                        for x in range(2, 1):
69 69
                            path_call = aprs.Callsign(frame[x * 7:])
@ -73,7 +73,7 @@ def main2():
73 73
                                    path_call.digi = True
74 74
75 75
                            path.append(path_call)
76
                        print(path)
76
                        print("{}".format(path))
77 77
78 78
def test():
79 79
    # http://www.tapr.org/pdf/AX25.2.2.pdf

+ 3 - 3
kiss/__init__.py

@ -31,6 +31,6 @@ from .util import (escape_special_codes, recover_special_codes, extract_ui,  # N
31 31
from .classes import KISS, TCPKISS, SerialKISS  # NOQA
32 32
33 33
34
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
35
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
36
__license__ = 'Apache License, Version 2.0'
34
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
35
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
36
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801

+ 17 - 12
kiss/classes.py

@ -10,23 +10,23 @@ import serial
10 10
11 11
import kiss
12 12
13
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
14
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
15
__license__ = 'Apache License, Version 2.0'
13
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
14
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
15
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
16 16
17 17
18 18
class KISS(object):
19 19
20 20
    """KISS Object Class."""
21 21
22
    _logger = logging.getLogger(__name__)
23
    if not _logger.handlers:
24
        _logger.setLevel(kiss.LOG_LEVEL)
25
        _console_handler = logging.StreamHandler()
26
        _console_handler.setLevel(kiss.LOG_LEVEL)
27
        _console_handler.setFormatter(kiss.LOG_FORMAT)
28
        _logger.addHandler(_console_handler)
29
        _logger.propagate = False
22
    _logger = logging.getLogger(__name__)  # pylint: disable=R0801
23
    if not _logger.handlers:  # pylint: disable=R0801
24
        _logger.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
25
        _console_handler = logging.StreamHandler()  # pylint: disable=R0801
26
        _console_handler.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
27
        _console_handler.setFormatter(kiss.LOG_FORMAT)  # pylint: disable=R0801
28
        _logger.addHandler(_console_handler)  # pylint: disable=R0801
29
        _logger.propagate = False  # pylint: disable=R0801
30 30
31 31
    def __init__(self, strip_df_start=False):
32 32
        self.strip_df_start = strip_df_start
@ -244,7 +244,12 @@ class SerialKISS(KISS):
244 244
        read_bytes = read_bytes or kiss.READ_BYTES
245 245
        read_data = self.interface.read(read_bytes)
246 246
        self._logger.debug('len(read_data)=%s', len(read_data))
247
        waiting_data = self.interface.in_waiting
247
248
        try:
249
            waiting_data = self.interface.in_waiting
250
        except AttributeError:
251
            waiting_data = self.interface.outWaiting()
252
248 253
        if waiting_data:
249 254
            self._logger.debug('len(waiting_data)=%s', len(waiting_data))
250 255
            read_data = ''.join([

+ 5 - 4
kiss/constants.py

@ -6,13 +6,14 @@
6 6
import logging
7 7
import os
8 8
9
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
10
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
11
__license__ = 'Apache License, Version 2.0'
9
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
10
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
11
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
12 12
13 13
14
if bool(os.environ.get('DEBUG_KISS')) or bool(os.environ.get('DEBUG_ALL')):
14
if bool(os.environ.get('DEBUG')):
15 15
    LOG_LEVEL = logging.DEBUG
16
    logging.debug('Debugging Enabled via DEBUG Environment Variable.')
16 17
else:
17 18
    LOG_LEVEL = logging.INFO
18 19

+ 3 - 3
kiss/exceptions.py

@ -3,9 +3,9 @@
3 3
4 4
"""Python KISS Module Exception Definitions."""
5 5
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
8
__license__ = 'Apache License, Version 2.0'
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
8
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
9 9
10 10
11 11
class SocketClosetError(Exception):

+ 3 - 3
kiss/util.py

@ -5,9 +5,9 @@
5 5
6 6
import kiss
7 7
8
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
9
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
10
__license__ = 'Apache License, Version 2.0'
8
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
9
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
10
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
11 11
12 12
13 13
def escape_special_codes(raw_codes):

+ 0 - 1
requirements.txt

@ -8,5 +8,4 @@
8 8
9 9
flake8
10 10
pylint
11
aprs
12 11
twine

+ 9 - 7
setup.py

@ -12,10 +12,10 @@ import setuptools
12 12
import sys
13 13
14 14
__title__ = 'kiss'
15
__version__ = '7.0.0b1'
16
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
17
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
18
__license__ = 'Apache License, Version 2.0'
15
__version__ = '6.5.0b1'
16
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
17
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
18
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
19 19
20 20
21 21
def publish():
@ -43,11 +43,13 @@ setuptools.setup(
43 43
    url='https://github.com/ampledata/kiss',
44 44
    zip_safe=False,
45 45
    setup_requires=[
46
        'coverage >= 3.7.1',
46
        'coverage >= 4.4.1',
47 47
        'nose >= 1.3.7',
48
        'dummyserial'
48
        'dummyserial >= 1.0.0',
49
        'aprs < 7.0.0',
50
        'mocket >= 1.8.2'
49 51
    ],
50
    install_requires=['pyserial >= 3.0'],
52
    install_requires=['pyserial >= 3.4'],
51 53
    classifiers=[
52 54
        'Topic :: Communications :: Ham Radio',
53 55
        'Programming Language :: Python',

+ 4 - 0
tests/__init__.py

@ -1 +1,5 @@
1 1
"""Tests for KISS Python Module."""
2
3
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
4
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
5
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801

+ 15 - 7
tests/constants.py

@ -1,16 +1,24 @@
1 1
#!/usr/bin/env python
2 2
# -*- coding: utf-8 -*-
3 3
4
"""Constants for KISS Module Tests."""
4
"""Python KISS Module Test Constants."""
5 5
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
8
__license__ = 'Apache License, Version 2.0'
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
8
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
9 9
10 10
11
TEST_FRAMES = 'tests/test_frames.log'
11
PANGRAM = 'the quick brown fox jumps over the lazy dog'
12
ALPHABET = PANGRAM.replace(' ', '')
12 13
13
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
14
NUMBERS = '0123456789'
14
NUMBERS = ''.join([str(x) for x in range(0, 10)])
15 15
POSITIVE_NUMBERS = NUMBERS[1:]
16 16
ALPHANUM = ''.join([ALPHABET, NUMBERS])
17
18
TEST_FRAMES = 'tests/test_frames.log'
19
20
TEST_FRAME = (
21
    '82a0a4b0646860ae648e9a88406cae92888a62406303f021333734352e3735'
22
    '4e4931323232382e303557235732474d442d3620496e6e65722053756e73657'
23
    '42c2053462069476174652f4469676970656174657220687474703a2f2f7732'
24
    '676d642e6f7267')

+ 5 - 5
tests/context.py

@ -8,9 +8,9 @@ import sys
8 8
9 9
sys.path.insert(0, os.path.abspath('..'))
10 10
11
import kiss  # NOQA pylint: disable=W0611
12
import kiss.constants  # NOQA pylint: disable=W0611
11
import kiss  # NOQA pylint: disable=W0611,C0413
12
import kiss.constants  # NOQA pylint: disable=W0611,C0413
13 13
14
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
15
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
16
__license__ = 'Apache License, Version 2.0'
14
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
15
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
16
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801

+ 16 - 18
tests/test_kiss_util.py

@ -3,32 +3,30 @@
3 3
4 4
"""Tests for KISS Util Module."""
5 5
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
8
__license__ = 'Apache License, Version 2.0'
6
import logging  # pylint: disable=R0801
7
import unittest  # pylint: disable=R0801
9 8
9
from .context import kiss  # pylint: disable=R0801
10 10
11
import logging
12
import unittest
11
from . import constants  # pylint: disable=R0801
13 12
14
from .context import kiss
13
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
14
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
15
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
15 16
16
from . import constants
17 17
18
19
# pylint: disable=R0904,C0103
20
class KISSUtilTestCase(unittest.TestCase):
18
class KISSUtilTestCase(unittest.TestCase):  # pylint: disable=R0904,C0103
21 19
22 20
    """Test class for KISS Python Module."""
23 21
24
    _logger = logging.getLogger(__name__)
25
    if not _logger.handlers:
26
        _logger.setLevel(kiss.LOG_LEVEL)
27
        _console_handler = logging.StreamHandler()
28
        _console_handler.setLevel(kiss.LOG_LEVEL)
29
        _console_handler.setFormatter(kiss.LOG_FORMAT)
30
        _logger.addHandler(_console_handler)
31
        _logger.propagate = False
22
    _logger = logging.getLogger(__name__)  # pylint: disable=R0801
23
    if not _logger.handlers:  # pylint: disable=R0801
24
        _logger.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
25
        _console_handler = logging.StreamHandler()  # pylint: disable=R0801
26
        _console_handler.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
27
        _console_handler.setFormatter(kiss.LOG_FORMAT)  # pylint: disable=R0801
28
        _logger.addHandler(_console_handler)  # pylint: disable=R0801
29
        _logger.propagate = False  # pylint: disable=R0801
32 30
33 31
    def setUp(self):
34 32
        """Setup."""

+ 13 - 13
tests/test_serialkiss.py

@ -3,9 +3,9 @@
3 3
4 4
"""Tests for KISS Classes."""
5 5
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
8
__license__ = 'Apache License, Version 2.0'
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
8
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
9 9
10 10
11 11
import logging
@ -24,14 +24,14 @@ class SerialKISSTestCase(unittest.TestCase):
24 24
25 25
    """Test class for KISS Python Module."""
26 26
27
    _logger = logging.getLogger(__name__)
28
    if not _logger.handlers:
29
        _logger.setLevel(kiss.LOG_LEVEL)
30
        _console_handler = logging.StreamHandler()
31
        _console_handler.setLevel(kiss.LOG_LEVEL)
32
        _console_handler.setFormatter(kiss.LOG_FORMAT)
33
        _logger.addHandler(_console_handler)
34
        _logger.propagate = False
27
    _logger = logging.getLogger(__name__)  # pylint: disable=R0801
28
    if not _logger.handlers:  # pylint: disable=R0801
29
        _logger.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
30
        _console_handler = logging.StreamHandler()  # pylint: disable=R0801
31
        _console_handler.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
32
        _console_handler.setFormatter(kiss.LOG_FORMAT)  # pylint: disable=R0801
33
        _logger.addHandler(_console_handler)  # pylint: disable=R0801
34
        _logger.propagate = False  # pylint: disable=R0801
35 35
36 36
    def setUp(self):
37 37
        """Setup."""
@ -63,7 +63,7 @@ class SerialKISSTestCase(unittest.TestCase):
63 63
64 64
    @classmethod
65 65
    def print_frame(cls, frame):
66
        print((aprs.Frame(frame)))
66
        print(aprs.Frame(frame))
67 67
68 68
    def test_write(self):
69 69
        ks = kiss.SerialKISS(port=self.random_serial_port, speed='9600')
@ -128,7 +128,7 @@ class SerialKISSTestCase(unittest.TestCase):
128 128
        ks.write(frame_encoded)
129 129
130 130
        read_data = ks._read_handler(len(frame_kiss))
131
        #self.assertEqual(read_data, frame_kiss)
131
        # self.assertEqual(read_data, frame_kiss)
132 132
133 133
    def test_config_xastir(self):
134 134
        """Tests writing Xastir config to KISS TNC."""

+ 22 - 18
tests/test_tcpkiss.py

@ -3,9 +3,9 @@
3 3
4 4
"""Tests for TCPKISS Class."""
5 5
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'
8
__license__ = 'Apache License, Version 2.0'
6
__author__ = 'Greg Albrecht W2GMD <oss@undef.net>'  # NOQA pylint: disable=R0801
7
__copyright__ = 'Copyright 2017 Greg Albrecht and Contributors'  # NOQA pylint: disable=R0801
8
__license__ = 'Apache License, Version 2.0'  # NOQA pylint: disable=R0801
9 9
10 10
11 11
import logging
@ -14,27 +14,28 @@ import unittest
14 14
15 15
import aprs
16 16
17
from mocket.mocket import Mocket, MocketEntry, MocketSocket, mocketize, create_connection
17
from mocket.mocket import (Mocket, MocketEntry, MocketSocket, mocketize,
18
    create_connection)
18 19
19 20
from .context import kiss
20 21
21 22
from . import constants
22 23
23
import kiss   # FIXME
24
#import kiss   # FIXME
24 25
25 26
26 27
class TCPKISSTestCase(unittest.TestCase):
27 28
28 29
    """Test class for KISS Python Module."""
29 30
30
    _logger = logging.getLogger(__name__)
31
    if not _logger.handlers:
32
        _logger.setLevel(kiss.LOG_LEVEL)
33
        _console_handler = logging.StreamHandler()
34
        _console_handler.setLevel(kiss.LOG_LEVEL)
35
        _console_handler.setFormatter(kiss.LOG_FORMAT)
36
        _logger.addHandler(_console_handler)
37
        _logger.propagate = False
31
    _logger = logging.getLogger(__name__)  # pylint: disable=R0801
32
    if not _logger.handlers:  # pylint: disable=R0801
33
        _logger.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
34
        _console_handler = logging.StreamHandler()  # pylint: disable=R0801
35
        _console_handler.setLevel(kiss.LOG_LEVEL)  # pylint: disable=R0801
36
        _console_handler.setFormatter(kiss.LOG_FORMAT)  # pylint: disable=R0801
37
        _logger.addHandler(_console_handler)  # pylint: disable=R0801
38
        _logger.propagate = False  # pylint: disable=R0801
38 39
39 40
    def setUp(self):
40 41
        """Setup."""
@ -66,7 +67,7 @@ class TCPKISSTestCase(unittest.TestCase):
66 67
67 68
    @classmethod
68 69
    def print_frame(cls, frame):
69
        print((aprs.Frame(frame)))
70
        print('{}'.format(aprs.Frame(frame)))
70 71
71 72
    @mocketize
72 73
    def _test_write(self):
@ -89,7 +90,9 @@ class TCPKISSTestCase(unittest.TestCase):
89 90
90 91
        ks.interface = create_connection(a)
91 92
        ks._write_handler = ks.interface.sendall
93
92 94
        def _pass(): pass
95
93 96
        ks.stop = _pass
94 97
95 98
        ks.write(kiss_frame)
@ -127,12 +130,13 @@ class TCPKISSTestCase(unittest.TestCase):
127 130
        self._logger.info(
128 131
            '_read_data(%s)="%s"', len(_read_data), _read_data)
129 132
130
        #read_data = _read_data[0]
131
        #self._logger.debug(
133
        # read_data = _read_data[0]
134
        # self._logger.debug(
132 135
        #    'frame_kiss(%s)="%s"', len(frame_kiss), frame_kiss)
133
        #self._logger.debug(
136
        # self._logger.debug(
134 137
        #    'read_data(%s)="%s"', len(read_data), read_data)
135
        #self.assertEqual(read_data, frame_kiss.split(kiss.FEND)[1])
138
        # self.assertEqual(read_data, frame_kiss.split(kiss.FEND)[1])
139
136 140
137 141
if __name__ == '__main__':
138 142
    unittest.main()