Skip to content

Commit

Permalink
fixed issue with universal_newlines and Python 3.7
Browse files Browse the repository at this point in the history
non-blocking IO with universal_newlines causes a can't concat NoneType
to bytes issue, modified code to use byte strings instead
  • Loading branch information
COUR4G3 committed Jun 4, 2021
1 parent b0715ca commit eec121c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pppd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from subprocess import Popen, PIPE, STDOUT

__version__ = '1.0.3'
__version__ = '1.0.4'

PPPD_RETURNCODES = {
1: 'Fatal error occured',
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit eec121c

Please sign in to comment.