# Path: src/apex/buffers.py
# class NonrepeatingBuffer(object):
#     def __init__(self, base_tnc, base_name, base_port=None, echo_packets=True, buffer_size=10000, buffer_time=30):
#         self.packet_cache = cachetools.TTLCache(buffer_size, buffer_time)
#         self.lock = threading.Lock()
#         self.base_tnc = base_tnc
#         self.base_port = base_port
#         self.base_name = base_name
#         self.echo_packets = echo_packets
# 
#     @property
#     def port(self):
#         return self.base_port
# 
#     @property
#     def name(self):
#         return self.base_name
# 
#     def connect(self, *args, **kwargs):
#         self.base_tnc.connect(*args, **kwargs)
# 
#     def close(self, *args, **kwargs):
#         self.base_tnc.close(*args, **kwargs)
# 
#     def write(self, frame, *args, **kwargs):
#         with self.lock:
#             frame_hash = str(aprs_util.hash_frame(frame))
#             if frame_hash not in self.packet_cache:
#                 self.packet_cache[frame_hash] = frame
#                 if self.base_port:
#                     self.base_tnc.write(frame, self.base_port)
#                 else:
#                     self.base_tnc.write(frame)
# 
#                 if self.echo_packets:
#                     echo_colorized_frame(frame, self.base_name, False)
# 
#     def read(self, *args, **kwargs):
#         with self.lock:
#             frame = self.base_tnc.read(*args, **kwargs)
#             if not frame:
#                 return frame
#             frame_hash = str(aprs_util.hash_frame(frame))
#             if frame_hash not in self.packet_cache:
#                 self.packet_cache[frame_hash] = frame
#                 if self.echo_packets:
#                     echo_colorized_frame(frame, self.base_name, True)
#                 return frame
#             else:
#                 return None
# 
# Path: src/apex/util.py
# def echo_colorized_error(text):
#     click.echo(click.style('Error: ', fg='red', bold=True, blink=True) + click.style(text, bold=True))
# 
# Path: src/apex/util.py
# def echo_colorized_warning(text):
#     click.echo(click.style('Warning: ', fg='yellow') + click.style(text))


import os
import signal
import sys
import threading
import time
import click
import six
import apex.aprs
import apex.buffers
    import ConfigParser  # noqa: F401
    import configparser
from apex.kiss import constants as kissConstants
from apex.plugin_loader import get_plugins
from apex.plugin_loader import load_plugin
from .buffers import NonrepeatingBuffer
from .util import echo_colorized_error
from .util import echo_colorized_warning
                tcp_port = config.get(section, 'tcp_port')
                kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.AprsKiss(apex.kiss.KissTcp(host=tcp_host, tcp_port=tcp_port)))
            else:
                echo_colorized_error("""Invalid configuration, must have both com_port and baud set or tcp_host and
                           tcp_port set in TNC sections of configuration file""")
                return False

            if not config.has_option(section, 'kiss_init'):
                echo_colorized_error('Invalid configuration, must have kiss_init set in TNC sections of configuration file')
                return False
            kiss_init_string = config.get(section, 'kiss_init')
            if kiss_init_string == 'MODE_INIT_W8DED':
                kiss_tnc.connect(kissConstants.MODE_INIT_W8DED)
            elif kiss_init_string == 'MODE_INIT_KENWOOD_D710':
                kiss_tnc.connect(kissConstants.MODE_INIT_KENWOOD_D710)
            elif kiss_init_string == 'NONE':
                kiss_tnc.connect()
            else:
                echo_colorized_error('Invalid configuration, value assigned to kiss_init was not recognized: %s'
                                     % kiss_init_string)
                return False

            for port in range(1, 1 + int(config.get(section, 'port_count'))):
                port_name = tnc_name + '-' + str(port)
                port_section = 'PORT ' + port_name
                port_identifier = config.get(port_section, 'identifier')
                port_net = config.get(port_section, 'net')
                tnc_port = int(config.get(port_section, 'tnc_port'))
                port_map[port_name] = {'identifier': port_identifier,
                                       'net': port_net,

# Path: src/apex/buffers.py
# class NonrepeatingBuffer(object):
#     def __init__(self, base_tnc, base_name, base_port=None, echo_packets=True, buffer_size=10000, buffer_time=30):
#         self.packet_cache = cachetools.TTLCache(buffer_size, buffer_time)
#         self.lock = threading.Lock()
#         self.base_tnc = base_tnc
#         self.base_port = base_port
#         self.base_name = base_name
#         self.echo_packets = echo_packets
# 
#     @property
#     def port(self):
#         return self.base_port
# 
#     @property
#     def name(self):
#         return self.base_name
# 
#     def connect(self, *args, **kwargs):
#         self.base_tnc.connect(*args, **kwargs)
# 
#     def close(self, *args, **kwargs):
#         self.base_tnc.close(*args, **kwargs)
# 
#     def write(self, frame, *args, **kwargs):
#         with self.lock:
#             frame_hash = str(aprs_util.hash_frame(frame))
#             if frame_hash not in self.packet_cache:
#                 self.packet_cache[frame_hash] = frame
#                 if self.base_port:
#                     self.base_tnc.write(frame, self.base_port)
#                 else:
#                     self.base_tnc.write(frame)
# 
#                 if self.echo_packets:
#                     echo_colorized_frame(frame, self.base_name, False)
# 
#     def read(self, *args, **kwargs):
#         with self.lock:
#             frame = self.base_tnc.read(*args, **kwargs)
#             if not frame:
#                 return frame
#             frame_hash = str(aprs_util.hash_frame(frame))
#             if frame_hash not in self.packet_cache:
#                 self.packet_cache[frame_hash] = frame
#                 if self.echo_packets:
#                     echo_colorized_frame(frame, self.base_name, True)
#                 return frame
#             else:
#                 return None
# 
# Path: src/apex/util.py
# def echo_colorized_error(text):
#     click.echo(click.style('Error: ', fg='red', bold=True, blink=True) + click.style(text, bold=True))
# 
# Path: src/apex/util.py
# def echo_colorized_warning(text):
#     click.echo(click.style('Warning: ', fg='yellow') + click.style(text))


# Path: src/apex/cli.py
import os
import signal
import sys
import threading
import time
import click
import six
import apex.aprs
import apex.buffers
    import ConfigParser  # noqa: F401
    import configparser
from apex.kiss import constants as kissConstants
from apex.plugin_loader import get_plugins
from apex.plugin_loader import load_plugin
from .buffers import NonrepeatingBuffer
from .util import echo_colorized_error
from .util import echo_colorized_warning

                tcp_port = config.get(section, 'tcp_port')
                kiss_tnc = apex.buffers.ReconnectingPacketBuffer(apex.aprs.AprsKiss(apex.kiss.KissTcp(host=tcp_host, tcp_port=tcp_port)))
            else:
                echo_colorized_error("""Invalid configuration, must have both com_port and baud set or tcp_host and
                           tcp_port set in TNC sections of configuration file""")
                return False

            if not config.has_option(section, 'kiss_init'):
                echo_colorized_error('Invalid configuration, must have kiss_init set in TNC sections of configuration file')
                return False
            kiss_init_string = config.get(section, 'kiss_init')
            if kiss_init_string == 'MODE_INIT_W8DED':
                kiss_tnc.connect(kissConstants.MODE_INIT_W8DED)
            elif kiss_init_string == 'MODE_INIT_KENWOOD_D710':
                kiss_tnc.connect(kissConstants.MODE_INIT_KENWOOD_D710)
            elif kiss_init_string == 'NONE':
                kiss_tnc.connect()
            else:
                echo_colorized_error('Invalid configuration, value assigned to kiss_init was not recognized: %s'
                                     % kiss_init_string)
                return False

            for port in range(1, 1 + int(config.get(section, 'port_count'))):
                port_name = tnc_name + '-' + str(port)
                port_section = 'PORT ' + port_name
                port_identifier = config.get(port_section, 'identifier')
                port_net = config.get(port_section, 'net')
                tnc_port = int(config.get(port_section, 'tnc_port'))
                port_map[port_name] = {'identifier': port_identifier,
                                       'net': port_net,

                                       'tnc': NonrepeatingBuffer(kiss_tnc, port_name, tnc_port),