Commit cdb2ae91 authored by Andreas Jung's avatar Andreas Jung

string module free zone

parent 6b1aa57d
...@@ -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, rstrip
from STletters import letters, digits, literal_punc, under_punc,\ from STletters import letters, digits, literal_punc, under_punc,\
strongem_punc, phrase_delimiters,dbl_quoted_punc strongem_punc, phrase_delimiters,dbl_quoted_punc
...@@ -36,7 +35,7 @@ class StructuredTextExample(ST.StructuredTextParagraph): ...@@ -36,7 +35,7 @@ class StructuredTextExample(ST.StructuredTextParagraph):
for s in subs: for s in subs:
flatten(s, a) flatten(s, a)
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 ()
...@@ -473,12 +472,12 @@ class DocumentClass: ...@@ -473,12 +472,12 @@ class DocumentClass:
col = re.compile('\|').search col = re.compile('\|').search
innertable = re.compile('\|([-]+|[=]+)\|').search innertable = re.compile('\|([-]+|[=]+)\|').search
text = strip(text) text = text.strip()
rows = split(text,'\n') rows = text.split('\n')
foo = "" foo = ""
for row in range(len(rows)): for row in range(len(rows)):
rows[row] = strip(rows[row]) rows[row] = rows[row].strip()
# have indexes store if a row is a divider # have indexes store if a row is a divider
# or a cell part # or a cell part
...@@ -496,14 +495,14 @@ class DocumentClass: ...@@ -496,14 +495,14 @@ class DocumentClass:
ignore = [] # reset ignore ignore = [] # reset ignore
#continue # skip dividers #continue # skip dividers
tmp = strip(rows[index]) # clean the row up tmp = rows[index].strip() # clean the row up
tmp = tmp[1:len(tmp)-1] # remove leading + trailing | tmp = tmp[1:len(tmp)-1] # remove leading + trailing |
offset = 0 offset = 0
# find the start and end of inner # find the start and end of inner
# tables. ignore everything between # tables. ignore everything between
if innertable(tmp): if innertable(tmp):
tmpstr = strip(tmp) tmpstr = tmp.strip()
while innertable(tmpstr): while innertable(tmpstr):
start,end = innertable(tmpstr).span() start,end = innertable(tmpstr).span()
if not (start,end-1) in ignore: if not (start,end-1) in ignore:
...@@ -640,30 +639,30 @@ class DocumentClass: ...@@ -640,30 +639,30 @@ class DocumentClass:
left = [] left = []
right = [] right = []
text = row[index][0] text = row[index][0]
text = split(text,'\n') text = text.split('\n')
text = text[:len(text)-1] text = text[:len(text)-1]
align = "" align = ""
valign = "" valign = ""
for t in text: for t in text:
t = strip(t) t = t.strip()
if not t: if not t:
topindent = topindent + 1 topindent = topindent + 1
else: else:
break break
text.reverse() text.reverse()
for t in text: for t in text:
t = strip(t) t = t.strip()
if not t: if not t:
bottomindent = bottomindent + 1 bottomindent = bottomindent + 1
else: else:
break break
text.reverse() text.reverse()
tmp = join(text[topindent:len(text)-bottomindent],"\n") tmp = '\n'.join(text[topindent:len(text)-bottomindent])
pars = re.compile("\n\s*\n").split(tmp) pars = re.compile("\n\s*\n").split(tmp)
for par in pars: for par in pars:
if index > 0: if index > 0:
par = par[1:] par = par[1:]
par = split(par, ' ') par = par.split(' ')
for p in par: for p in par:
if not p: if not p:
leftindent = leftindent+1 leftindent = leftindent+1
...@@ -756,7 +755,7 @@ class DocumentClass: ...@@ -756,7 +755,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:]
...@@ -775,17 +774,17 @@ class DocumentClass: ...@@ -775,17 +774,17 @@ 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
# copy attrs when returning a paragraph # copy attrs when returning a paragraph
kw = {} kw = {}
atts = getattr(paragraph, '_attributes', []) atts = getattr(paragraph, '_attributes', [])
for att in atts: kw[att] = getattr(paragraph, att) for att in atts: kw[att] = getattr(paragraph, att)
return apply(ST.StructuredTextParagraph, (top[:-1], [subs]), kw) return apply(ST.StructuredTextParagraph, (top[:-1], [subs]), kw)
if find(top,'\n') >= 0: return None if top.find('\n') >= 0: return None
return StructuredTextSection(top, subs, indent=paragraph.indent) return StructuredTextSection(top, subs, indent=paragraph.indent)
def doc_literal( def doc_literal(
...@@ -908,7 +907,7 @@ class DocumentClass: ...@@ -908,7 +907,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]):
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
# #
############################################################################## ##############################################################################
from string import join, split, find
import re, sys, ST
from HTMLClass import HTMLClass from HTMLClass import HTMLClass
...@@ -46,10 +44,3 @@ class HTMLWithImages(HTMLClass): ...@@ -46,10 +44,3 @@ class HTMLWithImages(HTMLClass):
def xref(self, doc, level, output): def xref(self, doc, level, output):
val = doc.getNodeValue() val = doc.getNodeValue()
output('<a href="#ref%s">[%s]</a>' % (val, val) ) output('<a href="#ref%s">[%s]</a>' % (val, val) )
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
############################################################################## ##############################################################################
import re, STDOM import re, STDOM
from string import split, join, replace, expandtabs, strip, find
##################################################################### #####################################################################
# Updated functions # # Updated functions #
...@@ -123,10 +122,10 @@ def StructuredText(paragraphs, delimiter=re.compile(para_delim)): ...@@ -123,10 +122,10 @@ def StructuredText(paragraphs, delimiter=re.compile(para_delim)):
struct = [] # the structure to be returned struct = [] # the structure to be returned
run = struct run = struct
paragraphs = expandtabs(paragraphs) paragraphs = paragraphs.expandtabs()
paragraphs = '%s%s%s' % ('\n\n', paragraphs, '\n\n') paragraphs = '%s%s%s' % ('\n\n', paragraphs, '\n\n')
paragraphs = delimiter.split(paragraphs) paragraphs = delimiter.split(paragraphs)
paragraphs = filter(strip, paragraphs) paragraphs = [ x for x in paragraphs if x.strip() ]
if not paragraphs: return StructuredTextDocument() if not paragraphs: return StructuredTextDocument()
...@@ -226,7 +225,7 @@ class StructuredTextParagraph(STDOM.Element): ...@@ -226,7 +225,7 @@ class StructuredTextParagraph(STDOM.Element):
) )
for p in self._subs: a(`p`) for p in self._subs: a(`p`)
a((' '*(self.indent or 0))+'])') a((' '*(self.indent or 0))+'])')
return join(r,'\n') return '\n'.join(r)
""" """
create aliases for all above functions in the pythony way. create aliases for all above functions in the pythony way.
...@@ -282,7 +281,7 @@ class StructuredTextDocument(StructuredTextParagraph): ...@@ -282,7 +281,7 @@ class StructuredTextDocument(StructuredTextParagraph):
a('%s([' % self.__class__.__name__) a('%s([' % self.__class__.__name__)
for p in self._subs: a(`p`+',') for p in self._subs: a(`p`+',')
a('])') a('])')
return join(r,'\n') return '\n'.join(r)
""" """
create aliases for all above functions in the pythony way. create aliases for all above functions in the pythony way.
......
...@@ -15,8 +15,6 @@ DOM implementation in StructuredText : Read-Only methods ...@@ -15,8 +15,6 @@ DOM implementation in StructuredText : Read-Only methods
All standard Zope objects support DOM to a limited extent. All standard Zope objects support DOM to a limited extent.
""" """
import string
# Node type codes # Node type codes
# --------------- # ---------------
...@@ -415,7 +413,7 @@ class Element(Node): ...@@ -415,7 +413,7 @@ class Element(Node):
if type(c) is not st: if type(c) is not st:
c=c.getNodeValue() c=c.getNodeValue()
r.append(c) r.append(c)
return string.join(r,'') return ''.join(r)
def getParentNode(self): def getParentNode(self):
""" """
......
...@@ -19,7 +19,7 @@ import HTMLClass, DocumentClass, ClassicDocumentClass ...@@ -19,7 +19,7 @@ import HTMLClass, DocumentClass, ClassicDocumentClass
import DocumentWithImages, HTMLWithImages import DocumentWithImages, HTMLWithImages
from ST import Basic from ST import Basic
import re, string,sys import re, sys
from STletters import letters from STletters import letters
Document = DocumentClass.DocumentClass() Document = DocumentClass.DocumentClass()
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
############################################################################## ##############################################################################
from Html import HTML from Html import HTML
from string import split
from ST import DOC from ST import DOC
import re import re
......
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