Converted a large part of utils/ folder to google code docstrings as per #709.
This commit is contained in:
parent
fc4beed9ca
commit
eb2bd8d44c
17 changed files with 1107 additions and 406 deletions
|
|
@ -82,8 +82,16 @@ class TextToHTMLparser(object):
|
|||
|
||||
def re_color(self, text):
|
||||
"""
|
||||
Replace ansi colors with html color class names.
|
||||
Let the client choose how it will display colors, if it wishes to. """
|
||||
Replace ansi colors with html color class names. Let the
|
||||
client choose how it will display colors, if it wishes to.
|
||||
|
||||
Args:
|
||||
text (str): the string with color to replace.
|
||||
|
||||
Returns:
|
||||
text (str): Re-colored text.
|
||||
|
||||
"""
|
||||
for colorname, regex in self.re_fgs:
|
||||
text = regex.sub(r'''<span class="%s">\1</span>''' % colorname, text)
|
||||
for bgname, regex in self.re_bgs:
|
||||
|
|
@ -91,19 +99,56 @@ class TextToHTMLparser(object):
|
|||
return self.re_normal.sub("", text)
|
||||
|
||||
def re_bold(self, text):
|
||||
"Clean out superfluous hilights rather than set <strong>to make it match the look of telnet."
|
||||
"""
|
||||
Clean out superfluous hilights rather than set <strong>to make
|
||||
it match the look of telnet.
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
return self.re_hilite.sub(r'<strong>\1</strong>', text)
|
||||
|
||||
def re_underline(self, text):
|
||||
"Replace ansi underline with html underline class name."
|
||||
"""
|
||||
Replace ansi underline with html underline class name.
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
return self.re_uline.sub(r'<span class="underline">\1</span>', text)
|
||||
|
||||
def remove_bells(self, text):
|
||||
"Remove ansi specials"
|
||||
"""
|
||||
Remove ansi specials
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
return text.replace('\07', '')
|
||||
|
||||
def remove_backspaces(self, text):
|
||||
"Removes special escape sequences"
|
||||
"""
|
||||
Removes special escape sequences
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
backspace_or_eol = r'(.\010)|(\033\[K)'
|
||||
n = 1
|
||||
while n > 0:
|
||||
|
|
@ -111,11 +156,29 @@ class TextToHTMLparser(object):
|
|||
return text
|
||||
|
||||
def convert_linebreaks(self, text):
|
||||
"Extra method for cleaning linebreaks"
|
||||
"""
|
||||
Extra method for cleaning linebreaks
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
return text.replace(r'\n', r'<br>')
|
||||
|
||||
def convert_urls(self, text):
|
||||
"Replace urls (http://...) by valid HTML"
|
||||
"""
|
||||
Replace urls (http://...) by valid HTML.
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
regexp = r"((ftp|www|http)(\W+\S+[^).,:;?\]\}(\<span\>) \r\n$\"\']+))"
|
||||
# -> added target to output prevent the web browser from attempting to
|
||||
# change pages (and losing our webclient session).
|
||||
|
|
@ -123,14 +186,31 @@ class TextToHTMLparser(object):
|
|||
|
||||
def convert_links(self, text):
|
||||
"""
|
||||
Replaces links with HTML code
|
||||
Replaces links with HTML code.
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
html = "<a href='#' onclick='websocket.send(\"CMD\\1\"); return false;'>\\2</a>"
|
||||
repl = self.re_link.sub(html, text)
|
||||
return repl
|
||||
|
||||
def do_sub(self, m):
|
||||
"Helper method to be passed to re.sub."
|
||||
def do_sub(self, match):
|
||||
"""
|
||||
Helper method to be passed to re.sub,
|
||||
for handling all substitutions.
|
||||
|
||||
Args:
|
||||
match (re.Matchobject): Match for substitution.
|
||||
|
||||
Returns:
|
||||
text (str): Processed text.
|
||||
|
||||
"""
|
||||
c = m.groupdict()
|
||||
if c['htmlchars']:
|
||||
return cgi.escape(c['htmlchars'])
|
||||
|
|
@ -145,8 +225,15 @@ class TextToHTMLparser(object):
|
|||
|
||||
def parse(self, text, strip_ansi=False):
|
||||
"""
|
||||
Main access function, converts a text containing
|
||||
ANSI codes into html statements.
|
||||
Main access function, converts a text containing ANSI codes
|
||||
into html statements.
|
||||
|
||||
Args:
|
||||
text (str): Text to process.
|
||||
strip_ansi (bool, optional):
|
||||
|
||||
Returns:
|
||||
text (str): Parsed text.
|
||||
"""
|
||||
# parse everything to ansi first
|
||||
text = parse_ansi(text, strip_ansi=strip_ansi, xterm256=False, mxp=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue