Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scheme(self): # covers issue 36, too
sample = '\x1b[33mYELLOW/BROWN'
# ansi2html scheme is brown #aa5500
html = Ansi2HTMLConverter(inline=True).convert(sample, full=False, ensure_trailing_newline=False)
expected = six.u('<span style="color: #aa5500">YELLOW/BROWN</span>')
self.assertEqual(expected, html)
# xterm scheme is yellow #cdcd00
html = Ansi2HTMLConverter(inline=True, scheme='xterm').convert(sample, full=False, ensure_trailing_newline=False)
expected = six.u('<span style="color: #cdcd00">YELLOW/BROWN</span>')
self.assertEqual(expected, html)
def test_partial(self):
rainbow = '\x1b[1m\x1b[40m\x1b[31mr\x1b[32ma\x1b[33mi\x1b[34mn\x1b[35mb\x1b[36mo\x1b[37mw\x1b[0m\n'
html = Ansi2HTMLConverter().convert(rainbow, full=False).strip()
expected = (six.u('<span class="ansi1"></span>') +
six.u('<span class="ansi1 ansi40"></span>') +
six.u('<span class="ansi1 ansi31 ansi40">r</span>') +
six.u('<span class="ansi1 ansi32 ansi40">a</span>') +
six.u('<span class="ansi1 ansi33 ansi40">i</span>') +
six.u('<span class="ansi1 ansi34 ansi40">n</span>') +
six.u('<span class="ansi1 ansi35 ansi40">b</span>') +
six.u('<span class="ansi1 ansi36 ansi40">o</span>') +
six.u('<span class="ansi1 ansi37 ansi40">w</span>'))
self.assertEqual(expected, html)
def test_no_markup_lines(self):
test = " wat \n "
expected = test
html = Ansi2HTMLConverter().convert(test, full=False)
self.assertEqual(expected, html)
def test_hidden_text(self):
sample = '\x1b[%dmHIDDEN\x1b[%dmVISIBLE\x1b[0m' % (ANSI_VISIBILITY_OFF, ANSI_VISIBILITY_ON)
html = Ansi2HTMLConverter(inline=True).convert(sample, full=False)
expected = six.u('<span style="visibility: hidden">HIDDEN</span>VISIBLE')
self.assertEqual(expected, html)
def test_latex_linkify(self):
ansi = 'http://python.org/'
target = '\\url{%s}' % ansi
latex = Ansi2HTMLConverter(latex=True, inline=True, linkify=True).convert(ansi)
assert(target in latex)
from itertools import islice
from collections import deque
import matplotlib
#import umap ##only necessary for weird experiments
import matplotlib.pyplot as plt
#import seaborn as sns ##only necessary for weird experiments
from mpl_toolkits.mplot3d import proj3d
import matplotlib.cm as cm
from torch.nn import CosineSimilarity
from sty import fg, bg, ef, rs, RgbFg
from sklearn.preprocessing import MinMaxScaler
import syntok.segmenter as segmenter
from ansi2html import Ansi2HTMLConverter
import text_graph
conv = Ansi2HTMLConverter()
document = Document() ## Create a python-docx document
cos = CosineSimilarity(dim=1, eps=1e-6)
class bcolors: #For converting the ANSI string to HTML - Sty is not supported well :(
HIGHLIGHT = '\33[43m'
END = '\033[0m'
granularity_level = "Sent" #"Word" "Sent" "Paragraph"
dynamic = False ##Controls if we highlight the more important words more or not
graph = False ###ONLY WORKS WITH "Word" granularity_level
word_doc = True
html = True
def htmlize(ansi):
conv = Ansi2HTMLConverter(inline=True, dark_bg=True)
return conv.convert(ansi, full=False)
q = q + "".join(packet_align(s_raw))
s = "After reassembly:\n"
s_gb = s + "Decoded by GB2312:" + "\n" + s_gb
s_utf8 = s + "Decoded by UTF8:" + "\n" + s_utf8
s_raw = s + "Raw bytes:" + "\n" + q
if ('\033[') in s_gb:
"""Add a new tab showing ANSI Escape Code.
Detect the data may contain ANSI Escape Code.
Using `ansi2html` library to parse it to css and show.
"""
a = QtWidgets.QTextBrowser()
a.setFrameStyle(QFrame.NoFrame)
conv = Ansi2HTMLConverter()
html = conv.convert(s_gb)
html = str.replace(html, "\n", "")
#somehow QyQt has different between html in memory and file
f = open("temp.html", "w")
f.write(html)
f.close()
with open('temp.html', 'r') as content_file:
content = content_file.read()
a.setHtml(content)
content_file.close()
os.remove('temp.html')
self.tabWidget_2.addTab(
a, 'Console Type(Parsing ANSI Escape Code)')
self.CreateNewTab(self.tabWidget_2, "TCP reassemble Hex", s_raw)
self.CreateNewTab(self.tabWidget_2, "TCP reassemble UTF-8", s_utf8)
def job_rendered(request, jid, minion_id):
# Retrieve job from database.
job = SaltReturns.objects.get(jid=jid, id=minion_id)
# Use different output.
if job.fun in ["state.apply", "state.highstate"]:
formatted = highstate_output.output({minion_id: job.loaded_ret()["return"]})
else:
formatted = nested_output.output({minion_id: job.loaded_ret()["return"]})
# Convert it to html.
conv = Ansi2HTMLConverter(inline=False, scheme="xterm")
html_detail = conv.convert(formatted, ensure_trailing_newline=True)
return Response(html_detail)
def ansi_text_to_html(text):
conv = Ansi2HTMLConverter(scheme='osx', dark_bg=False)
html = conv.convert(text)
html = html.replace(
'.body_background { background-color: #AAAAAA; }',
'.body_background { background-color: #FFFFFF; }')
return html