Commit 32635b7d authored by Andreas Jung's avatar Andreas Jung

replace string module calls by string methods

parent ae630f47
import string
""" Pretty-Print an Interface object as structured text (Yum) """ """ Pretty-Print an Interface object as structured text (Yum) """
import string
def trim_doc_string(text): def trim_doc_string(text):
""" """
Trims a doc string to make it format Trims a doc string to make it format
correctly with structured text. correctly with structured text.
""" """
text=string.strip(text) text=text.strip()
text=string.replace(text, '\r\n', '\n') text=text.replace('\r\n', '\n')
lines=string.split(text, '\n') lines=text.split('\n')
nlines=[lines[0]] nlines=[lines[0]]
if len(lines) > 1: if len(lines) > 1:
min_indent=None min_indent=None
for line in lines[1:]: for line in lines[1:]:
indent=len(line) - len(string.lstrip(line)) indent=len(line) - len(line.lstrip())
if indent < min_indent or min_indent is None: if indent < min_indent or min_indent is None:
min_indent=indent min_indent=indent
for line in lines[1:]: for line in lines[1:]:
nlines.append(line[min_indent:]) nlines.append(line[min_indent:])
return string.join(nlines, '\n') return '\n'.join(nlines, '\n')
...@@ -31,25 +31,25 @@ def justify_and_indent(text, level, munge=0, width=72): ...@@ -31,25 +31,25 @@ def justify_and_indent(text, level, munge=0, width=72):
if munge: if munge:
line = " " * level line = " " * level
text = string.split(string.strip(string.translate(text, string.maketrans("\r\n", " ")))) text = (string.translate(text, string.maketrans("\r\n", " "))).strip.split()
for word in text: for word in text:
line = string.join([line, word]) line = ''.join([line, word])
if len(line) > width: if len(line) > width:
lines.append(line) lines.append(line)
line = " " * level line = " " * level
else: else:
lines.append(line) lines.append(line)
return string.join(lines, "\n") return '\n'.join(lines)
else: else:
text = string.split(string.replace(text,"\r\n", "\n"), "\n") text = text.replace("\r\n", "\n").split( "\n")
for line in text: for line in text:
lines.append( (" " * level) + line) lines.append( (" " * level) + line)
return string.join(lines, "\n") return '\n'.join(lines)
def interface_as_stx(I, munge=0): def interface_as_stx(I, munge=0):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment