From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Simek Date: Fri, 5 Oct 2018 10:08:56 +0200 Subject: [U-Boot] [PATCH v2 04/17] test/py: Fix unicode handling for log filtering In-Reply-To: <20181002031247.93384-5-sjg@chromium.org> References: <20181002031247.93384-1-sjg@chromium.org> <20181002031247.93384-5-sjg@chromium.org> Message-ID: <0d29af35-c85a-d5e9-6abe-544829b28165@monstr.eu> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 2.10.2018 05:12, Simon Glass wrote: > At present the unicode filtering seems to get confused at times with > this error: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position > 32: ordinal not in range(128) > > It seems to be due to self._nonprint being interpreted as UTF-8. Fix it > by using ordinals instead of characters, changing the string to set. > > Signed-off-by: Simon Glass > Reviewed-by: Stephen Warren > --- > > Changes in v2: None > > test/py/multiplexed_log.py | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py > index f23d5dec68c..637a3bd257b 100644 > --- a/test/py/multiplexed_log.py > +++ b/test/py/multiplexed_log.py > @@ -314,8 +314,9 @@ $(document).ready(function () { > > # The set of characters that should be represented as hexadecimal codes in > # the log file. > - _nonprint = ('%' + ''.join(chr(c) for c in range(0, 32) if c not in (9, 10)) + > - ''.join(chr(c) for c in range(127, 256))) > + _nonprint = {ord('%')} > + _nonprint.update({c for c in range(0, 32) if c not in (9, 10)}) > + _nonprint.update({c for c in range(127, 256)}) > > def _escape(self, data): > """Render data format suitable for inclusion in an HTML document. > @@ -331,7 +332,7 @@ $(document).ready(function () { > """ > > data = data.replace(chr(13), '') > - data = ''.join((c in self._nonprint) and ('%%%02x' % ord(c)) or > + data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or > c for c in data) > data = cgi.escape(data) > return data > Tested-by: Michal Simek Thanks, Michal -- Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91 w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP SoCs