[Git][reproducible-builds/diffoscope][master] 2 commits: Factor out a method for stripping ANSI escapes.
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Fri Aug 16 10:26:52 UTC 2024
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
d16faf7c by Chris Lamb at 2024-08-16T11:25:52+01:00
Factor out a method for stripping ANSI escapes.
- - - - -
12e34398 by Chris Lamb at 2024-08-16T11:26:15+01:00
Strip ANSI escapes from the output of Procyon. Thanks, Aman Sharma.
- - - - -
3 changed files:
- diffoscope/comparators/image.py
- diffoscope/comparators/java.py
- diffoscope/comparators/utils/command.py
Changes:
=====================================
diffoscope/comparators/image.py
=====================================
@@ -27,9 +27,7 @@ from diffoscope.tempfiles import get_named_temporary_file
from diffoscope.difference import Difference, VisualDifference
from .utils.file import File
-from .utils.command import Command, our_check_output
-
-re_ansi_escapes = re.compile(r"\x1b[^m]*m")
+from .utils.command import Command, our_check_output, strip_ansi_escapes
logger = logging.getLogger(__name__)
@@ -40,8 +38,7 @@ class Img2Txt(Command):
return ["img2txt", "--width", "60", "--format", "utf8", self.path]
def filter(self, line):
- # Strip ANSI escapes
- return re_ansi_escapes.sub("", line.decode("utf-8")).encode("utf-8")
+ return strip_ansi_escapes(line)
class Identify(Command):
=====================================
diffoscope/comparators/java.py
=====================================
@@ -27,7 +27,7 @@ from diffoscope.difference import Difference
from diffoscope.exc import RequiredToolNotFound
from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, strip_ansi_escapes
logger = logging.getLogger(__name__)
@@ -44,7 +44,7 @@ class ProcyonDecompiler(Command):
def filter(self, line):
if re.match(r"^(//)", line.decode("utf-8")):
return b""
- return line
+ return strip_ansi_escapes(line)
class Javap(Command):
=====================================
diffoscope/comparators/utils/command.py
=====================================
@@ -19,11 +19,14 @@
import abc
import signal
import logging
+import re
import subprocess
from .operation import Operation
from ...utils import format_cmdline
+re_ansi_escapes = re.compile(rb"\x1b[^m]*m")
+
logger = logging.getLogger(__name__)
@@ -115,3 +118,7 @@ def our_check_output(cmd, *args, **kwargs):
logger.debug("Calling external command: %s", " ".join(cmd))
return subprocess.check_output(cmd, *args, **kwargs)
+
+
+def strip_ansi_escapes(val):
+ return re_ansi_escapes.sub(b"", val)
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/a38cdad57753b12f529c688bf919aa88481e59da...12e34398cf72c46eb0eb1d3883a9b215f1aec06b
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/a38cdad57753b12f529c688bf919aa88481e59da...12e34398cf72c46eb0eb1d3883a9b215f1aec06b
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20240816/1aa4b21f/attachment.htm>
More information about the rb-commits
mailing list