From 6129b92277a5332deead086616abf5363ce9d7a2 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 15 Sep 2021 15:01:36 +0200 Subject: [PATCH] avoid duplicate method --- csdr/module.py | 28 ++++++++++++++-------------- owrx/aprs/module.py | 14 -------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/csdr/module.py b/csdr/module.py index 97cb131..7ade431 100644 --- a/csdr/module.py +++ b/csdr/module.py @@ -47,6 +47,20 @@ class AutoStartModule(Module, metaclass=ABCMeta): def start(self): pass + def pump(self, read, write): + def copy(): + while True: + data = None + try: + data = read() + except ValueError: + pass + if data is None or isinstance(data, bytes) and len(data) == 0: + break + write(data) + + return copy + class ThreadModule(AutoStartModule, Thread, metaclass=ABCMeta): def __init__(self): @@ -113,17 +127,3 @@ class PopenModule(AutoStartModule, metaclass=ABCMeta): self.process.wait() self.process = None self.reader.stop() - - def pump(self, read, write): - def copy(): - while True: - data = None - try: - data = read() - except ValueError: - pass - if data is None or isinstance(data, bytes) and len(data) == 0: - break - write(data) - - return copy diff --git a/owrx/aprs/module.py b/owrx/aprs/module.py index ddbbde6..22eac4a 100644 --- a/owrx/aprs/module.py +++ b/owrx/aprs/module.py @@ -74,17 +74,3 @@ class DirewolfModule(AutoStartModule): self.process.wait() self.process = None self.reader.stop() - - def pump(self, read, write): - def copy(): - while True: - data = None - try: - data = read() - except ValueError: - pass - if data is None or isinstance(data, bytes) and len(data) == 0: - break - write(data) - - return copy