Commit a06f8164 authored by Andreas Jung's avatar Andreas Jung

string module free zone

parent 8aa66f99
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
############################################################################## ##############################################################################
import re, ST, STDOM import re, ST, STDOM
from string import split, join, replace, expandtabs, strip, find
from STletters import letters from STletters import letters
StringType=type('') StringType=type('')
...@@ -25,7 +24,7 @@ class StructuredTextExample(ST.StructuredTextParagraph): ...@@ -25,7 +24,7 @@ class StructuredTextExample(ST.StructuredTextParagraph):
t=[]; a=t.append t=[]; a=t.append
for s in subs: a(s.getNodeValue()) for s in subs: a(s.getNodeValue())
apply(ST.StructuredTextParagraph.__init__, apply(ST.StructuredTextParagraph.__init__,
(self, join(t,'\n\n'), ()), (self, '\n\n'.join(t), ()),
kw) kw)
def getColorizableTexts(self): return () def getColorizableTexts(self): return ()
...@@ -374,15 +373,15 @@ class DocumentClass: ...@@ -374,15 +373,15 @@ class DocumentClass:
rows = [] rows = []
# initial split # initial split
for row in split(text,"\n"): for row in text.split("\n"):
rows.append(row) rows.append(row)
# clean up the rows # clean up the rows
for index in range(len(rows)): for index in range(len(rows)):
tmp = [] tmp = []
rows[index] = strip(rows[index]) rows[index] = rows[index].strip()
l = len(rows[index])-2 l = len(rows[index])-2
result = split(rows[index][:l],"||") result = rows[index][:l].split("||")
for text in result: for text in result:
if text: if text:
tmp.append(text) tmp.append(text)
...@@ -462,7 +461,7 @@ class DocumentClass: ...@@ -462,7 +461,7 @@ class DocumentClass:
if not d: return None if not d: return None
start, end = d.span() start, end = d.span()
title=top[:start] title=top[:start]
if find(title, '\n') >= 0: return None if title.find('\n') >= 0: return None
if not nb(title): return None if not nb(title): return None
d=top[start:end] d=top[start:end]
top=top[end:] top=top[end:]
...@@ -483,16 +482,16 @@ class DocumentClass: ...@@ -483,16 +482,16 @@ class DocumentClass:
subs=paragraph.getSubparagraphs() subs=paragraph.getSubparagraphs()
if not subs: return None if not subs: return None
top=paragraph.getColorizableTexts()[0] top=paragraph.getColorizableTexts()[0]
if not strip(top): return None if not top.strip(): return None
if top[-2:]=='::': if top[-2:]=='::':
subs=StructuredTextExample(subs) subs=StructuredTextExample(subs)
if strip(top)=='::': return subs if top.strip()=='::': return subs
return ST.StructuredTextParagraph(top[:-1], return ST.StructuredTextParagraph(top[:-1],
[subs], [subs],
indent=paragraph.indent, indent=paragraph.indent,
level=paragraph.level) level=paragraph.level)
if find(top,'\n') >= 0: return None if top.find('\n') >= 0: return None
return StructuredTextSection(top, subs, indent=paragraph.indent, level=paragraph.level) return StructuredTextSection(top, subs, indent=paragraph.indent, level=paragraph.level)
def doc_literal( def doc_literal(
...@@ -602,7 +601,7 @@ class DocumentClass: ...@@ -602,7 +601,7 @@ class DocumentClass:
start,e = r.span(1) start,e = r.span(1)
name = s[start:e] name = s[start:e]
name = replace(name,'"','',2) name = name.replace('"','',2)
#start = start + 1 #start = start + 1
st,end = r.span(3) st,end = r.span(3)
if punctuation(s[end-1:end]): if punctuation(s[end-1:end]):
......
...@@ -136,7 +136,6 @@ Special symbology is used to indicate special constructs: ...@@ -136,7 +136,6 @@ Special symbology is used to indicate special constructs:
import ts_regex import ts_regex
import regex import regex
from ts_regex import gsub from ts_regex import gsub
from string import split, join, strip, find
import string,re import string,re
...@@ -162,11 +161,11 @@ def untabify(aString, ...@@ -162,11 +161,11 @@ def untabify(aString,
def indent(aString, indent=2): def indent(aString, indent=2):
"""Indent a string the given number of spaces""" """Indent a string the given number of spaces"""
r=split(untabify(aString),'\n') r=untabify(aString).split('\n')
if not r: return '' if not r: return ''
if not r[-1]: del r[-1] if not r[-1]: del r[-1]
tab=' '*indent tab=' '*indent
return "%s%s\n" % (tab,join(r,'\n'+tab)) return "%s%s\n" % (tab,('\n'+tab).join(r))
def reindent(aString, indent=2, already_untabified=0): def reindent(aString, indent=2, already_untabified=0):
"reindent a block of text, so that the minimum indent is as given" "reindent a block of text, so that the minimum indent is as given"
...@@ -182,12 +181,12 @@ def reindent(aString, indent=2, already_untabified=0): ...@@ -182,12 +181,12 @@ def reindent(aString, indent=2, already_untabified=0):
if indent > l: if indent > l:
tab=' ' * (indent-l) tab=' ' * (indent-l)
for s in split(aString,'\n'): append(tab+s) for s in aString.split('\n'): append(tab+s)
else: else:
l=l-indent l=l-indent
for s in split(aString,'\n'): append(s[l:]) for s in aString.split('\n'): append(s[l:])
return join(r,'\n') return '\n'.join(r)
def indent_level(aString, def indent_level(aString,
indent_space=ts_regex.compile('\n\( *\)').search_group, indent_space=ts_regex.compile('\n\( *\)').search_group,
...@@ -242,7 +241,7 @@ class Table: ...@@ -242,7 +241,7 @@ class Table:
'''parses a table and returns nested list representing the '''parses a table and returns nested list representing the
table''' table'''
self.table=[] self.table=[]
text=filter(None,split(aPar,'\n')) text=filter(None,aPar.split('\n'))
for line in text: for line in text:
row=[] row=[]
while 1: while 1:
...@@ -268,8 +267,8 @@ class Table: ...@@ -268,8 +267,8 @@ class Table:
else: else:
htmlrow.append(self.CELL%(colspan,cell)) htmlrow.append(self.CELL%(colspan,cell))
colspan=1 colspan=1
htmltable.append(self.ROW%join(htmlrow,'')) htmltable.append(self.ROW % ''.join(htmlrow))
return self.TABLE%join(htmltable,'') return self.TABLE % ''.join(htmltable)
table=Table() table=Table()
...@@ -312,7 +311,7 @@ class StructuredText: ...@@ -312,7 +311,7 @@ class StructuredText:
aStructuredString = p_reg.sub(r'<a href="\2">\1</a>\3 ' , aStructuredString) aStructuredString = p_reg.sub(r'<a href="\2">\1</a>\3 ' , aStructuredString)
protoless = find(aStructuredString, '<a href=":') protoless = aStructuredString.find('<a href=":')
if protoless != -1: if protoless != -1:
aStructuredString = re.sub('<a href=":', '<a href="', aStructuredString = re.sub('<a href=":', '<a href="',
aStructuredString) aStructuredString)
...@@ -373,12 +372,12 @@ class HTML(StructuredText): ...@@ -373,12 +372,12 @@ class HTML(StructuredText):
return s return s
def ul(self, before, p, after): def ul(self, before, p, after):
if p: p="<p>%s</p>" % strip(ctag(p)) if p: p="<p>%s</p>" % ctag(p).strip()
return ('%s<ul><li>%s\n%s\n</li></ul>\n' return ('%s<ul><li>%s\n%s\n</li></ul>\n'
% (before,p,after)) % (before,p,after))
def ol(self, before, p, after): def ol(self, before, p, after):
if p: p="<p>%s</p>" % strip(ctag(p)) if p: p="<p>%s</p>" % ctag(p).strip()
return ('%s<ol><li>%s\n%s\n</li></ol>\n' return ('%s<ol><li>%s\n%s\n</li></ol>\n'
% (before,p,after)) % (before,p,after))
...@@ -389,9 +388,9 @@ class HTML(StructuredText): ...@@ -389,9 +388,9 @@ class HTML(StructuredText):
def head(self, before, t, level, d): def head(self, before, t, level, d):
if level > 0 and level < 6: if level > 0 and level < 6:
return ('%s<h%d>%s</h%d>\n%s\n' return ('%s<h%d>%s</h%d>\n%s\n'
% (before,level,strip(ctag(t)),level,d)) % (before,level,ctag(t).strip(),level,d))
t="<p><strong>%s</strong></p>" % strip(ctag(t)) t="<p><strong>%s</strong></p>" % ctag(t).strip()
return ('%s<dl><dt>%s\n</dt><dd>%s\n</dd></dl>\n' return ('%s<dl><dt>%s\n</dt><dd>%s\n</dd></dl>\n'
% (before,t,d)) % (before,t,d))
...@@ -540,7 +539,7 @@ def main(): ...@@ -540,7 +539,7 @@ def main():
s=str(html_with_references(s)) s=str(html_with_references(s))
if s[:4]=='<h1>': if s[:4]=='<h1>':
t=s[4:find(s,'</h1>')] t=s[4: s.find('</h1>')]
s='''<html><head><title>%s</title> s='''<html><head><title>%s</title>
</head><body> </head><body>
%s %s
......
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