From nobody Fri Apr 26 12:34:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=famz@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by mx.zohomail.com with SMTPS id 1519700462228797.2066047361947; Mon, 26 Feb 2018 19:01:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 172D3818534B for ; Tue, 27 Feb 2018 03:01:01 +0000 (UTC) Received: from localhost (ovpn-12-53.pek2.redhat.com [10.72.12.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6519F1C733 for ; Tue, 27 Feb 2018 03:01:00 +0000 (UTC) Received: by 10.103.98.66 with SMTP id w63csp3595232vsb; Mon, 26 Feb 2018 03:27:24 -0800 (PST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id 21si8073295qkk.313.2018.02.26.03.27.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 03:27:24 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40A4340A0971 for ; Mon, 26 Feb 2018 11:27:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3B89F2026E04; Mon, 26 Feb 2018 11:27:24 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-126.ams2.redhat.com [10.36.117.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C4602026DFD; Mon, 26 Feb 2018 11:27:23 +0000 (UTC) Resent-From: Fam Zheng Resent-Date: Tue, 27 Feb 2018 11:00:58 +0800 Resent-Message-ID: <20180227030058.GO21035@lemon.usersys.redhat.com> Resent-To: importer@patchew.org X-Google-Smtp-Source: AG47ELvoRPPNhyp/clX1Y4Zm4R4ttMA3nvfDTBAW7dkBHDfQeT/epUPUt7+hd5ZIsKX7zF27d6Zh X-Received: by 10.55.19.35 with SMTP id d35mr15989659qkh.292.1519644444537; Mon, 26 Feb 2018 03:27:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519644444; cv=none; d=google.com; s=arc-20160816; b=MyUsyP5bo2sJMP2ODaSsFJ2Vc7+qqxGq+zMhMZafSEmoA4l3w4S+IwLIsTsjCE9MNZ kefex3CLGRRVLbYoVfyhSrseeeK+00kmHXkrJYGIlV0yjoDErJYajTlw905aOevPVxbb eKcIKvCWvwbDFY4N5JxaSwjN+DiXQtNJlO8zzzACvuQ0SRyeNNB6uOD8SwhlxzCa6DwZ VSk3MH8Pd+nOuoUlDAGIV6Gjo564Z/uqcJ//CrERt3G9nZUbKJdJL0i5J2y7AR9vTl6Q o8OrqYKRVq9qsLSARQh+HJM64asZU7c4QWp2okG7RPHrXhtICYvazy7fymsCGaUtKB9Z kiTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:arc-authentication-results; bh=BB8K0F1p2Ao8/JppTV3zUzt1jxkFj9j1T6kEhJCDmm0=; b=H3cK8AkifesdpmMqtg37OSi8xRS9hEn0URKatvv0JJpEy5xVDnnLmgZde8pxCDQ/VN +BFdYFiSjCts6kwI6/NAkddRy2iu96zzHCD4xwJXXa40xsFGshajr/+93a1LkCKU+cca pvr/wxkouycQVIA3u1LF8H9lD2BhOZkImKG8PLJTe9ChavkSVRxD6Q6irBR1w2m5VUdk iNfmFPRNoxw/110YBxLJu/Oc3iVtw0/fvOIveZdC9xvummj2HCFgaO8ZaFJy5Rk1yfXx Ex2vrqo30k97jsMPZZ1q2cYtAf5s973XAXL9M0eU4OflGO3IyUbnN/GkpMi+6jONhucd MYtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) smtp.mailfrom=pbonzini@redhat.com Received-SPF: pass (zoho.com: domain of redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; envelope-from=famz@redhat.com; helo=mx1.redhat.com; Received-SPF: pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) Authentication-Results: mx.google.com; spf=pass (google.com: domain gapps.redhat.com configured 66.187.233.73 as internal address) smtp.mailfrom=pbonzini@redhat.com From: Paolo Bonzini To: patchew-devel@freelists.org Cc: famz@redhat.com Subject: [PATCH 1/9] ansi2html: stub implementation Date: Mon, 26 Feb 2018 12:27:14 +0100 Message-Id: <20180226112722.19488-2-pbonzini@redhat.com> In-Reply-To: <20180226112722.19488-1-pbonzini@redhat.com> References: <20180226112722.19488-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 26 Feb 2018 11:27:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 26 Feb 2018 11:27:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-TUID: Uw6rarqiZXQh X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 27 Feb 2018 03:01:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 27 Feb 2018 03:01:01 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Define the interface, without actually doing much of a conversion. Signed-off-by: Paolo Bonzini Reviewed-by: Fam Zheng --- patchew/logviewer.py | 50 +++++++++++++++++++++++++++++++++++++++++++++= ++-- tests/test_ansi2html.py | 30 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/test_ansi2html.py diff --git a/patchew/logviewer.py b/patchew/logviewer.py index 53bf238..4438fa4 100644 --- a/patchew/logviewer.py +++ b/patchew/logviewer.py @@ -1,10 +1,41 @@ +# Convert ANSI sequences to HTML for Patchew +# +# Copyright (C) 2018 Red Hat, Inc. +# +# Author: Paolo Bonzini + import abc +import sys =20 from django.views import View from django.http import HttpResponse, StreamingHttpResponse from django.utils.html import format_html from django.utils.safestring import mark_safe =20 +class ANSI2HTMLConverter(object): + def __init__(self, white_bg=3DFalse): + self.prefix =3D '
'
+
+    def _write_prefix(self):
+        if self.prefix !=3D '':
+            yield self.prefix
+            self.prefix =3D ''
+
+    def convert(self, input):
+        yield from self._write_prefix()
+        yield format_html('{}', input)
+
+    def finish(self):
+        yield from self._write_prefix()
+        yield '
' + self.prefix =3D '
'
+
+def ansi2html(input, white_bg=3DFalse):
+    c =3D ANSI2HTMLConverter(white_bg=3Dwhite_bg)
+    yield from c.convert(input)
+    yield from c.finish()
+
+
 class LogView(View, metaclass=3Dabc.ABCMeta):
     @abc.abstractmethod
     def content(request, **kwargs):
@@ -16,6 +47,9 @@ class LogView(View, metaclass=3Dabc.ABCMeta):
     # prolog includes Bootstrap's pre formatting (for consistency with
     # the parent window's 
 tags) and and a script to close the
     # colorbox on Esc.
+    # Putting this in a template would be nice, but it would also
+    # consume more memory because we would not be able to just
+    # "yield from" into the StreamingHttpResponse.
     HTML_PROLOG =3D mark_safe("""