From eec121cee30c1993283fd1651fccbc0e2c77b092 Mon Sep 17 00:00:00 2001 From: Michael de Villiers Date: Fri, 4 Jun 2021 12:55:38 +0200 Subject: [PATCH] fixed issue with universal_newlines and Python 3.7 non-blocking IO with universal_newlines causes a can't concat NoneType to bytes issue, modified code to use byte strings instead --- pppd.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pppd.py b/pppd.py index 72e7db6..96b3b91 100644 --- a/pppd.py +++ b/pppd.py @@ -6,7 +6,7 @@ from subprocess import Popen, PIPE, STDOUT -__version__ = '1.0.3' +__version__ = '1.0.4' PPPD_RETURNCODES = { 1: 'Fatal error occured', @@ -43,7 +43,7 @@ def __str__(self): class PPPConnection: def __init__(self, *args, **kwargs): - self.output = '' + self.output = b'' self._laddr = None self._raddr = None @@ -70,7 +70,6 @@ def __init__(self, *args, **kwargs): self.proc = Popen(commands, stdout=PIPE, stderr=STDOUT, - universal_newlines=True, preexec_fn=os.setsid) # set stdout to non-blocking @@ -85,7 +84,7 @@ def __init__(self, *args, **kwargs): if e.errno != 11: raise time.sleep(1) - if 'ip-up finished' in self.output: + if b'ip-up finished' in self.output: return elif self.proc.poll(): raise PPPConnectionError(self.proc.returncode, self.output) @@ -98,7 +97,7 @@ def laddr(self): except IOError as e: if e.errno != 11: raise - result = re.search(r'local IP address ([\d\.]+)', self.output) + result = re.search(b'local IP address ([\d\.]+)', self.output) if result: self._laddr = result.group(1) @@ -112,7 +111,7 @@ def raddr(self): except IOError as e: if e.errno != 11: raise - result = re.search(r'remote IP address ([\d\.]+)', self.output) + result = re.search(b'remote IP address ([\d\.]+)', self.output) if result: self._raddr = result.group(1) @@ -128,7 +127,7 @@ def connected(self): if self.proc.returncode not in [0, 5]: raise PPPConnectionError(proc.returncode, self.output) return False - elif 'ip-up finished' in self.output: + elif b'ip-up finished' in self.output: return True return False