[Docstring-checkins] CVS: dps/dps nodes.py,1.6,1.7
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2001-09-07 02:08:44
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv32160/dps/dps Modified Files: nodes.py Log Message: - _Node's always true. - Changed .pprint() to .pformat(). - Added slice support to elements. - Added .findclass() & .findnonclass() methods. - Added support for auto-numbered footnotes. Index: nodes.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/nodes.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** nodes.py 2001/08/30 04:28:58 1.6 --- nodes.py 2001/09/07 02:08:41 1.7 *************** *** 12,20 **** import sys import xml.dom.minidom ! from types import StringType from UserString import MutableString class _Node: def asdom(self, dom=xml.dom.minidom): return self._dom_node(dom) --- 12,24 ---- import sys import xml.dom.minidom ! from types import IntType, SliceType, StringType, TupleType from UserString import MutableString class _Node: + def __nonzero__(self): + """_Node instances are always true.""" + return 1 + def asdom(self, dom=xml.dom.minidom): return self._dom_node(dom) *************** *** 52,56 **** return self.data ! def pprint(self, indent=' ', level=0): result = [] indent = indent * level --- 56,60 ---- return self.data ! def pformat(self, indent=' ', level=0): result = [] indent = indent * level *************** *** 155,172 **** if isinstance(key, StringType): return self.attributes[key] ! else: return self.children[key] def __setitem__(self, key, item): if isinstance(key, StringType): self.attributes[key] = item ! else: self.children[key] = item def __delitem__(self, key): if isinstance(key, StringType): del self.attributes[key] ! else: del self.children[key] def __add__(self, other): --- 159,194 ---- if isinstance(key, StringType): return self.attributes[key] ! elif isinstance(key, IntType): return self.children[key] + elif isinstance(key, SliceType): + assert key.step is None, 'cannot handle slice with stride' + return self.children[key.start:key.stop] + else: + raise TypeError, ('element index must be an integer, a slice, or ' + 'an attribute name string') def __setitem__(self, key, item): if isinstance(key, StringType): self.attributes[key] = item ! elif isinstance(key, IntType): self.children[key] = item + elif isinstance(key, SliceType): + assert key.step is None, 'cannot handle slice with stride' + self.children[key.start:key.stop] = item + else: + raise TypeError, ('element index must be an integer, a slice, or ' + 'an attribute name string') def __delitem__(self, key): if isinstance(key, StringType): del self.attributes[key] ! elif isinstance(key, IntType): del self.children[key] + elif isinstance(key, SliceType): + assert key.step is None, 'cannot handle slice with stride' + del self.children[key.start:key.stop] + else: + raise TypeError, ('element index must be an integer, a simple ' + 'slice, or an attribute name string') def __add__(self, other): *************** *** 219,226 **** self.children.remove(item) ! def pprint(self, indent=' ', level=0): if self.children: return ''.join(['%s%s\n' % (indent * level, self.starttag())] + ! [c.pprint(indent, level+1) for c in self.children] + ['%s%s\n' % (indent * level, self.endtag())]) else: --- 241,282 ---- self.children.remove(item) ! def findclass(self, childclass, start=0, end=sys.maxint): ! """ ! Return the index of the first child whose class matches `childclass`. ! ! `childclass` may also be a tuple of node classes, in which case any ! of the classes may match. ! """ ! if not isinstance(childclass, TupleType): ! childclass = (childclass,) ! for index in range(start, min(len(self), end)): ! for c in childclass: ! if isinstance(self[index], c): ! return index ! return None ! ! def findnonclass(self, childclass, start=0, end=sys.maxint): ! """ ! Return the index of the first child not matching `childclass`. ! ! `childclass` may also be a tuple of node classes, in which case none ! of the classes may match. ! """ ! if not isinstance(childclass, TupleType): ! childclass = (childclass,) ! for index in range(start, min(len(self), end)): ! match = 0 ! for c in childclass: ! if isinstance(self[index], c): ! match = 1 ! if not match: ! return index ! return None ! ! def pformat(self, indent=' ', level=0): if self.children: return ''.join(['%s%s\n' % (indent * level, self.starttag())] + ! [child.pformat(indent, level+1) ! for child in self.children] + ['%s%s\n' % (indent * level, self.endtag())]) else: *************** *** 260,263 **** --- 316,321 ---- self.indirectlinks = {} self.refnames = {} + self.autofootnotes = [] + self.autofootnoterefs = [] self.errorhandler = errorhandler *************** *** 334,337 **** --- 392,403 ---- self.explicitlinks.setdefault(name, []).append(linknode) linknode['name'] = name + + def addautofootnote(self, name, footnotenode): + footnotenode['auto'] = '1' + self.autofootnotes.append((name, footnotenode)) + + def addautofootnoteref(self, refname, refnode): + refnode['auto'] = '1' + self.autofootnoterefs.append((refname, refnode)) |