[Zope-Checkins] CVS: Zope2 - StructuredText.py:1.34.8.2
Andreas Jung
andreas@dhcp165.digicool.com
Thu, 19 Apr 2001 08:49:54 -0400
Update of /cvs-repository/Zope2/lib/python/StructuredText
In directory yetix:/work/sandboxes/ajung-2_4-ts_regex-exterminiation-branch/lib/python/StructuredText
Modified Files:
Tag: ajung-2_4-ts_regex-exterminiation-branch
StructuredText.py
Log Message:
more regex free
--- Updated File StructuredText.py in package Zope2 --
--- StructuredText.py 2001/04/19 12:18:28 1.34.8.1
+++ StructuredText.py 2001/04/19 12:49:53 1.34.8.2
@@ -210,7 +210,7 @@
from string import split, join, strip, find
import re
-def untabify_new(aString,
+def untabify(aString,
indent_tab=ts_regex.compile('\(\n\|^\)\( *\)\t').search_group,
):
'''\
@@ -230,26 +230,6 @@
else:
return result+rest
-def untabify_old(aString,
- indent_tab=ts_regex.compile('\(\n\|^\)\( *\)\t').search_group,
- ):
- '''\
- Convert indentation tabs to spaces.
- '''
- result=''
- rest=aString
- while 1:
- ts_results = indent_tab(rest, (1,2))
- if ts_results:
- start, grps = ts_results
- lnl=len(grps[0])
- indent=len(grps[1])
- result=result+rest[:start]
- rest="\n%s%s" % (' ' * ((indent/8+1)*8),
- rest[start+indent+1+lnl:])
- else:
- return result+rest
-
def indent(aString, indent=2):
"""Indent a string the given number of spaces"""
r=split(untabify(aString),'\n')
@@ -411,6 +391,7 @@
self.level=level
paragraphs=ts_regex.split(untabify(aStructuredString),
paragraph_divider)
+
paragraphs=map(indent_level,paragraphs)
self.structure=structure(paragraphs)
@@ -505,49 +486,53 @@
def _str(self,structure,level,
# Static
- bullet=ts_regex.compile('[ \t\n]*[o*-][ \t\n]+\([^\0]*\)'
- ).match_group,
- example=ts_regex.compile('[\0- ]examples?:[\0- ]*$'
+ bullet=re.compile('[ \t\n]*[o*-][ \t\n]+([^\0]*)'
+ ),
+ example=re.compile('[\0- ]examples?:[\0- ]*$'
).search,
- dl=ts_regex.compile('\([^\n]+\)[ \t]+--[ \t\n]+\([^\0]*\)'
- ).match_group,
- nl=ts_regex.compile('\n').search,
- ol=ts_regex.compile(
- '[ \t]*\(\([0-9]+\|[a-zA-Z]+\)[.)]\)+[ \t\n]+\([^\0]*\|$\)'
- ).match_group,
- olp=ts_regex.compile('[ \t]*([0-9]+)[ \t\n]+\([^\0]*\|$\)'
- ).match_group,
+ dl=re.compile('([^\n]+)[ \t]+--[ \t\n]+([^\0]*)'
+ ),
+ nl=re.compile('\n').search,
+ ol=re.compile(
+ '[ \t]*(([0-9]+\|[a-zA-Z]+)[.)])+[ \t\n]+([^\0]*\|$)'
+ ),
+ olp=re.compile('[ \t]*([0-9]+)[ \t\n]+([^\0]*\|$)'
+ ),
):
r=''
for s in structure:
- ts_results = bullet(s[0], (1,))
- if ts_results:
- p = ts_results[1]
+ mo = bullet.match(s[0])
+ if mo is not None:
+ p = mo.group(0)
if s[0][-2:]=='::' and s[1]: ps=self.pre(s[1])
else: ps=self._str(s[1],level)
r=self.ul(r,p,ps)
continue
- ts_results = ol(s[0], (3,))
- if ts_results:
- p = ts_results[1]
+
+ mo = ol.match(s[0])
+ if mo is not None:
+ p = mo.group(2)
if s[0][-2:]=='::' and s[1]: ps=self.pre(s[1])
else: ps=self._str(s[1],level)
r=self.ol(r,p,ps)
continue
- ts_results = olp(s[0], (1,))
- if ts_results:
- p = ts_results[1]
+
+ mo = opl.match(s[0])
+ if mo is not None:
+ p = mo.group(0)
if s[0][-2:]=='::' and s[1]: ps=self.pre(s[1])
else: ps=self._str(s[1],level)
r=self.ol(r,p,ps)
continue
- ts_results = dl(s[0], (1,2))
- if ts_results:
- t,d = ts_results[1]
+
+ mo = dl.match(s[0])
+ if mo is not None:
+ t,d = mo.group(0,1)
r=self.dl(r,t,d,self._str(s[1],level))
continue
- if example(s[0]) >= 0 and s[1]:
+
+ if example(s[0]) is not None and s[1]:
# Introduce an example, using pre tags:
r=self.normal(r,s[0],self.pre(s[1]))
continue
@@ -561,7 +546,7 @@
continue
else:
- if nl(s[0]) < 0 and s[1] and s[0][-1:] != ':':
+ if nl(s[0]) is None and s[1] and s[0][-1:] != ':':
# Treat as a heading
t=s[0]
r=self.head(r,t,level,