diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2002-08-29 22:05:45 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2002-08-29 22:05:45 +0000 |
commit | 295d74479397d40ced9a0616c76e49cd67ed9461 (patch) | |
tree | c8ed86b054767f36fbd4ba658cafc9549c23c945 | |
parent | 1bb1bb285f9d690ddadf4abcee901c43beb3bf41 (diff) | |
download | pyserial-git-295d74479397d40ced9a0616c76e49cd67ed9461.tar.gz |
EOL character for lines can be chosen
idea by John Florian
-rw-r--r-- | pyserial/serial/serialutil.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pyserial/serial/serialutil.py b/pyserial/serial/serialutil.py index 55ced9f..e3a4bdb 100644 --- a/pyserial/serial/serialutil.py +++ b/pyserial/serial/serialutil.py @@ -19,14 +19,15 @@ class FileLike: def read(self, size): raise NotImplementedError def write(self, s): raise NotImplementedError - def readline(self, size=None): - """read a line which is terminated with '\n' or until timeout""" + def readline(self, size=None, eol='\n'): + """read a line which is terminated with end-of-line (eol) character + ('\n' by default) or until timeout""" line = '' while 1: c = self.read(1) if c: line += c #not very efficient but lines are usually not that long - if c == '\n': + if c == eol: break if size is not None and len(line) >= size: break @@ -34,17 +35,17 @@ class FileLike: break return line - def readlines(self, sizehint=None): + def readlines(self, sizehint=None, eol='\n'): """read a list of lines, until timeout sizehint is ignored""" if self.timeout is None: raise ValueError, "Serial port MUST have enabled timeout for this function!" lines = [] while 1: - line = self.readline() + line = self.readline(eol=eol) if line: lines.append(line) - if line[-1] != '\n': #was the line received with a timeout? + if line[-1] != eol: #was the line received with a timeout? break else: break |