Skip to content

Commit eec121c

Browse files
committed
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
1 parent b0715ca commit eec121c

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pppd.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from subprocess import Popen, PIPE, STDOUT
88

9-
__version__ = '1.0.3'
9+
__version__ = '1.0.4'
1010

1111
PPPD_RETURNCODES = {
1212
1: 'Fatal error occured',
@@ -43,7 +43,7 @@ def __str__(self):
4343

4444
class PPPConnection:
4545
def __init__(self, *args, **kwargs):
46-
self.output = ''
46+
self.output = b''
4747
self._laddr = None
4848
self._raddr = None
4949

@@ -70,7 +70,6 @@ def __init__(self, *args, **kwargs):
7070
self.proc = Popen(commands,
7171
stdout=PIPE,
7272
stderr=STDOUT,
73-
universal_newlines=True,
7473
preexec_fn=os.setsid)
7574

7675
# set stdout to non-blocking
@@ -85,7 +84,7 @@ def __init__(self, *args, **kwargs):
8584
if e.errno != 11:
8685
raise
8786
time.sleep(1)
88-
if 'ip-up finished' in self.output:
87+
if b'ip-up finished' in self.output:
8988
return
9089
elif self.proc.poll():
9190
raise PPPConnectionError(self.proc.returncode, self.output)
@@ -98,7 +97,7 @@ def laddr(self):
9897
except IOError as e:
9998
if e.errno != 11:
10099
raise
101-
result = re.search(r'local IP address ([\d\.]+)', self.output)
100+
result = re.search(b'local IP address ([\d\.]+)', self.output)
102101
if result:
103102
self._laddr = result.group(1)
104103

@@ -112,7 +111,7 @@ def raddr(self):
112111
except IOError as e:
113112
if e.errno != 11:
114113
raise
115-
result = re.search(r'remote IP address ([\d\.]+)', self.output)
114+
result = re.search(b'remote IP address ([\d\.]+)', self.output)
116115
if result:
117116
self._raddr = result.group(1)
118117

@@ -128,7 +127,7 @@ def connected(self):
128127
if self.proc.returncode not in [0, 5]:
129128
raise PPPConnectionError(proc.returncode, self.output)
130129
return False
131-
elif 'ip-up finished' in self.output:
130+
elif b'ip-up finished' in self.output:
132131
return True
133132

134133
return False

0 commit comments

Comments
 (0)