From 2e043ecf5bb992c1bb39999b62d12a2c8029a8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 18 Feb 2020 15:57:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Explicitly=20document=20LineProc?= =?UTF-8?q?essorStream=20behaviour=20under=20py3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make absolutely clear that processLine will be called with a byte & not a unicode string. See #3454 --- src/octoprint/filemanager/util.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/octoprint/filemanager/util.py b/src/octoprint/filemanager/util.py index 4a247e62b..00f3aa215 100644 --- a/src/octoprint/filemanager/util.py +++ b/src/octoprint/filemanager/util.py @@ -107,7 +107,7 @@ class MultiStream(io.RawIOBase): their contents in the order they are provided to the constructor. Arguments: - *streams (io.IOBase): One or more streams to concatenate. + *streams (io.RawIOBase): One or more streams to concatenate. """ def __init__(self, *streams): io.RawIOBase.__init__(self) @@ -159,10 +159,12 @@ class LineProcessorStream(io.RawIOBase): While reading from this stream the provided `input_stream` is read line by line, calling the (overridable) method :meth:`.process_line` for each read line. - Sub classes can thus modify the contents of the `input_stream` in line, while it is being read. + Sub classes can thus modify the contents of the `input_stream` in line, while it is being read. Keep in mind that + ``process_line`` will receive the line as a byte stream - if underlying code needs to operate on unicode you'll need + to do the decoding yourself. Arguments: - input_stream (io.IOBase): The stream to process on the fly. + input_stream (io.RawIOBase): The stream to process on the fly. """ def __init__(self, input_stream): @@ -220,10 +222,11 @@ class LineProcessorStream(io.RawIOBase): wrapper `input_stream`. Arguments: - line (str): The line as read from `self.input_stream` + line (bytes): The line as read from `self.input_stream` in byte representation (str under Python 2 and + bytes under Python 3) Returns: - str or None: The processed version of the line (might also be multiple lines), or None if the line is to be + bytes or None: The processed version of the line (might also be multiple lines), or None if the line is to be stripped from the processed stream. """ return line