docstring-checkins Mailing List for Docstring Processing System (Page 10)
Status: Pre-Alpha
Brought to you by:
goodger
You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(53) |
Sep
(54) |
Oct
(26) |
Nov
(27) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(60) |
Feb
(85) |
Mar
(94) |
Apr
(40) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: David G. <go...@us...> - 2002-01-30 04:49:56
|
Update of /cvsroot/docstring/dps/dps/parsers In directory usw-pr-cvs1:/tmp/cvs-serv22491/dps/dps/parsers Modified Files: __init__.py Log Message: - model.Parser -> __init__.py, with updates. Index: __init__.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/parsers/__init__.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** __init__.py 2001/07/22 22:35:42 1.1.1.1 --- __init__.py 2002/01/30 04:49:53 1.2 *************** *** 1,3 **** #! /usr/bin/env python ! # $Id$ ! # by David Goodger (dgo...@bi...) --- 1,27 ---- #! /usr/bin/env python ! ! """ ! :Author: David Goodger ! :Contact: go...@us... ! :Revision: $Revision$ ! :Date: $Date$ ! :Copyright: This module has been placed in the public domain. ! """ ! ! __docformat__ = 'reStructuredText' ! ! ! class Parser: ! ! def __init__(self, debug=0): ! """Initialize the Parser instance.""" ! self.debug = debug ! ! def parse(self, inputstring, docroot): ! """Override to parse `inputstring` into document tree `docroot`.""" ! raise NotImplementedError('subclass must override this method') ! ! def setup_parse(self, inputstring, docroot): ! """Initial setup, used by `parse()`.""" ! self.inputstring = inputstring ! self.docroot = docroot |
From: David G. <go...@us...> - 2002-01-30 04:47:14
|
Update of /cvsroot/docstring/dps/test In directory usw-pr-cvs1:/tmp/cvs-serv22065/dps/test Modified Files: DPSTestSupport.py Log Message: - Updated new document Node creation protocol. Index: DPSTestSupport.py =================================================================== RCS file: /cvsroot/docstring/dps/test/DPSTestSupport.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DPSTestSupport.py 2002/01/26 00:04:50 1.3 --- DPSTestSupport.py 2002/01/30 04:47:11 1.4 *************** *** 223,227 **** if self.runInDebugger: pdb.set_trace() ! doctree = self.parser.parse(self.input) for transformClass in self.transforms: transformClass().transform(doctree) --- 223,228 ---- if self.runInDebugger: pdb.set_trace() ! doctree = utils.newdocument(warninglevel=4, errorlevel=4) ! self.parser.parse(self.input, doctree) for transformClass in self.transforms: transformClass().transform(doctree) *************** *** 235,239 **** print '-' * 70 print self.input ! doctree = self.parser.parse(self.input) print '-' * 70 print doctree.pformat() --- 236,242 ---- print '-' * 70 print self.input ! doctree = utils.newdocument( ! languagecode='en', warninglevel=4, errorlevel=4) ! self.parser.parse(self.input, doctree) print '-' * 70 print doctree.pformat() |
From: David G. <go...@us...> - 2002-01-30 04:47:05
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv21996/dps/dps Modified Files: utils.py Log Message: - Updated new document Node creation protocol. Index: utils.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/utils.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** utils.py 2002/01/16 02:45:22 1.10 --- utils.py 2002/01/30 04:47:02 1.11 *************** *** 69,72 **** --- 69,78 ---- + def newdocument(languagecode='en', warninglevel=1, errorlevel=3, + warningstream=None): + reporter = Reporter(warninglevel, errorlevel) + document = nodes.document(languagecode='en', reporter=reporter) + return document + def parseattributes(lines, attributespec): """ |
From: David G. <go...@us...> - 2002-01-30 04:43:25
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv20729/dps/test/test_transforms Modified Files: test_substitutions.py Log Message: updated Index: test_substitutions.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_substitutions.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_substitutions.py 2002/01/29 02:18:14 1.1 --- test_substitutions.py 2002/01/30 04:43:23 1.2 *************** *** 21,26 **** def suite(): ! parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', ! debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) --- 21,25 ---- def suite(): ! parser = Parser(debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) |
From: David G. <go...@us...> - 2002-01-30 04:43:15
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv20668/dps/test/test_transforms Modified Files: test_hyperlinks.py Log Message: updated Index: test_hyperlinks.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_hyperlinks.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_hyperlinks.py 2002/01/26 00:08:39 1.1 --- test_hyperlinks.py 2002/01/30 04:43:12 1.2 *************** *** 21,26 **** def suite(): ! parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', ! debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) --- 21,25 ---- def suite(): ! parser = Parser(debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) |
From: David G. <go...@us...> - 2002-01-30 04:43:07
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv20626/dps/test/test_transforms Modified Files: test_footnotes.py Log Message: updated Index: test_footnotes.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_footnotes.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_footnotes.py 2002/01/29 02:17:52 1.2 --- test_footnotes.py 2002/01/30 04:43:05 1.3 *************** *** 21,26 **** def suite(): ! parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', ! debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) --- 21,25 ---- def suite(): ! parser = Parser(debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) |
From: David G. <go...@us...> - 2002-01-30 04:42:59
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv20603/dps/test/test_transforms Modified Files: test_doctitle.py Log Message: updated Index: test_doctitle.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_doctitle.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_doctitle.py 2002/01/16 02:41:12 1.1 --- test_doctitle.py 2002/01/30 04:42:56 1.2 *************** *** 21,26 **** def suite(): ! parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', ! debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) --- 21,25 ---- def suite(): ! parser = Parser(debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) |
From: David G. <go...@us...> - 2002-01-30 04:42:52
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv20581/dps/test/test_transforms Modified Files: test_docinfo.py Log Message: updated Index: test_docinfo.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_docinfo.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_docinfo.py 2002/01/26 00:07:53 1.2 --- test_docinfo.py 2002/01/30 04:42:50 1.3 *************** *** 21,26 **** def suite(): ! parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', ! debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) --- 21,25 ---- def suite(): ! parser = Parser(debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) |
From: David G. <go...@us...> - 2002-01-30 04:41:02
|
Update of /cvsroot/docstring/dps/dps/formatters In directory usw-pr-cvs1:/tmp/cvs-serv20238/dps/dps/formatters Removed Files: model.py Log Message: to be replaced by "writers" or "builders" subpackage --- model.py DELETED --- |
From: David G. <go...@us...> - 2002-01-30 04:40:55
|
Update of /cvsroot/docstring/dps/dps/formatters In directory usw-pr-cvs1:/tmp/cvs-serv20210/dps/dps/formatters Removed Files: __init__.py Log Message: to be replaced by "writers" or "builders" subpackage --- __init__.py DELETED --- |
From: David G. <go...@us...> - 2002-01-29 02:24:43
|
Update of /cvsroot/docstring/dps In directory usw-pr-cvs1:/tmp/cvs-serv2628/dps Modified Files: HISTORY.txt Log Message: updated Index: HISTORY.txt =================================================================== RCS file: /cvsroot/docstring/dps/HISTORY.txt,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** HISTORY.txt 2002/01/28 02:22:34 1.34 --- HISTORY.txt 2002/01/29 02:24:40 1.35 *************** *** 82,85 **** --- 82,88 ---- - Reworked for hyperlink transforms. - Added support for footnote transform. + - Added 'problematic', inline relative of 'system_warning'. + - Added ``Node.parent`` back-reference for transforms. + - Added ``Element.index()`` and ``Element.replace()`` methods. * dps/roman.py: Added to project. Written by and courtesy of Mark *************** *** 193,196 **** --- 196,200 ---- allowing nested inline elements. - Removed generic 'directive'. + - Added 'problematic', inline relative of 'system_warning'. * spec/pdpi.dtd: |
From: David G. <go...@us...> - 2002-01-29 02:18:35
|
Update of /cvsroot/docstring/dps/spec In directory usw-pr-cvs1:/tmp/cvs-serv1597/dps/spec Modified Files: dps-notes.txt Log Message: updated Index: dps-notes.txt =================================================================== RCS file: /cvsroot/docstring/dps/spec/dps-notes.txt,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dps-notes.txt 2002/01/28 02:18:17 1.20 --- dps-notes.txt 2002/01/29 02:18:32 1.21 *************** *** 17,21 **** [Tibs:] Eventually we need to have direct documentation in there on how it all hangs together - the DTD is not enough ! (indeed, is it still meant to be correct?). - Rework PEP 257, separating style from spec from tools, wrt DPS. See --- 17,21 ---- [Tibs:] Eventually we need to have direct documentation in there on how it all hangs together - the DTD is not enough ! (indeed, is it still meant to be correct? [Yes, it is.]). - Rework PEP 257, separating style from spec from tools, wrt DPS. See *************** *** 49,58 **** - Write modules for common transforms. See Transforms_ below. - - Resolving auto-numbered footnotes & references. - - Resolving internal, external, and indirect hyperlinks. - - Propagating URIs to chained hyperlink targets. - - These transformations may be turned on or off by individual modes. - - Ask Python-dev for opinions (GvR for a pronouncement) on special variables (__author__, __version__, etc.): convenience vs. namespace --- 49,52 ---- *************** *** 101,254 **** ========== - Footnote Numbering - ------------------ - - [Tony] - This runs over a subtree (clearly for Python code, we don't want to - run it over anything bigger than a docstring, lest we confuse - footnotes!) and sorts out the numbering (in my development version of - pyspd (not on the web yet) this is actually done as part of the HTML - output phase, which is clearly the Wrong Place for it. - - David - a question or two on this. Each autonumbered footnote/footnote - reference has the attribute 'auto' set to "1". I want to *insert* - actual footnote numbers into the tree. I can just add a new attribute - 'auto-number' into elements as required, *or* I could ask that you set - 'auto' to be "-1" for the "no number yet" case, and use 'auto' to - store the *actual* number calculated. Which to do is a style issue, so - I'd prefer to leave it up to you (but using the same attribute would - make things a bit neater in the code - I'm not sure if it would - generate as elegant XML, though - I'd need to look up the detailed - attribute present/absent rules). - - [David] - Auto-numbered footnotes have attribute ``auto=1`` and no label. - Auto-numbered footnote_references have no reference text (they're - empty elements). If you resolve the numbering, just add a label - element to the beginning of the footnote, and reference text to the - footnote_reference. Take this input:: - - References to the first ([A]_), third ([#spam]_), and second - ([#]_) footnotes. - - .. [A] This footnote is labeled with "A". - .. [#] This footnote is auto-numbered. - .. [#spam] This footnote has autonumber name "spam". - - Parsed (watch for empty footnote_reference elements: indentation):: - - <document> - <paragraph> - References to the first ( - <footnote_reference refname="a"> - A - ), third ( - <footnote_reference auto="1" refname="spam"> - ), and second - ( - <footnote_reference auto="1"> - ) footnotes. - <footnote name="a"> - <label> - A - <paragraph> - This footnote is labeled with "A". - <footnote auto="1"> - <paragraph> - This footnote is auto-numbered. - <footnote auto="1" name="spam"> - <paragraph> - This footnote has autonumber name "spam". - - Only the first footnote_reference contains reference text. After - auto-numbering resolution, the tree should become:: - - <document> - <paragraph> - References to the first ( - <footnote_reference refname="a"> - A - ), third ( - <footnote_reference auto="1" refname="spam"> - 2 - ), and second - ( - <footnote_reference auto="1" refname="_footnote 1"> - 1 - ) footnotes. - <footnote name="a"> - <label> - A - <paragraph> - This footnote is labeled with "A". - <footnote auto="1" name="_footnote 1"> - <label> - 1 - <paragraph> - This footnote is auto-numbered. - <footnote auto="1" name="spam"> - <label> - 2 - <paragraph> - This footnote has autonumber name "spam". - - The labels and reference text are added to the two auto-numbered - footnotes & footnote_references. The unnamed auto-numbered footnote - & reference need name & refname attributes. Let's use "_footnote " + - footnote number for those attributes (a name-mangling unlikely to - occur in the real world; note that this hasn't been documented yet). - Of course (!), the implicitlinks and refnames instance attributes of - the dps.nodes.document instance must be updated. (It will soon be my - pleasure to document the dps/nodes.py data structure, since I'm - gradually forgetting its details.) - - After adding labels and reference text, the "auto" attributes can be - ignored. - - - [David] - > Let's use "_footnote " + footnote number for those attributes - > (a name-mangling unlikely to occur in the real world; note that - > this hasn't been documented yet). - - [Tony] - > Hmm - I wasn't assuming that unnamed autonumbered footnotes would have any - > name other than the number (since you're following the XML tradition and - > storing such things as strings anyway). - - [David] - I suppose we could go either way. I'm re-examining (for validity) what I - wrote in the spec: - - Automatic footnote numbering may not be mixed with manual footnote - numbering; it would cause numbering and referencing conflicts. - - Would such mixing inevitably cause conflicts? We could probably work around - potential conflicts with a decent algorithm. Should we? Requires thought. - Opinions? - - [Tony] - Well, I read that paragraph in the documentation, and decided that it - was in the category of "don't, in practice, care" so far as I was - concerned. This is the same category I put the forbidding of nested - inline markup - quite clearly one *can* do it, but equally clearly it's - a pain to implement, and not a terribly great gain, all things - considered. - - It's a category with the subtext "examine for correctness after we've - had some experience of people *using* reST in the wild". - - Thus, given there are lots of other things to do, I would tend to leave - it as-is (especially if you are able to *warn* people about it if they - do it by mistake). - - To my mind, being able to do ``[#thing]_`` probably give people enough - precision over footnotes whils still allowing autonumbering - the *only* - potential problem is when referring to a footnote in a different - document (and that, again, is something I would leave fallow for the - moment, although we know I tend to want to use roles as annotation for - that sort of thing). - - Footnote Gathering ------------------ --- 95,98 ---- *************** *** 261,280 **** It probably comes in two phases, because in a Python context we need ! to *resolve* them on a per-docstring basis, but if the user is trying ! to do the callout form of presentation, they would then want to group ! them all at the end of the document. ! Substitutions ! ------------- ! @@@ Table of Contents ----------------- - @@@ - This runs over the entire tree, and locates <section> elements. It produces a <contents> subtree, which can be inserted at the --- 105,131 ---- It probably comes in two phases, because in a Python context we need ! to *resolve* them on a per-docstring basis [do we? --DG], but if the ! user is trying to do the callout form of presentation, they would then ! want to group them all at the end of the document. ! Reference Merging ! ----------------- ! When merging two or more subdocuments (such as docstrings), ! conflicting references may need to be resolved. There may be: + - duplicate reference and/or substitution names that need to be made + unique; and + - duplicate footnote numbers that need to be renumbered. + Should this be done before or after reference-resolving transforms + are applied? What about references from within one subdocument to + inside another? + + Table of Contents ----------------- This runs over the entire tree, and locates <section> elements. It produces a <contents> subtree, which can be inserted at the *************** *** 446,449 **** --- 297,335 ---- self.doctree.walkabout(self) + + Mixing Automatic and Manual Footnote Numbering + ============================================== + + [David] + I'm re-examining (for validity) what I wrote in the spec: + + Automatic footnote numbering may not be mixed with manual footnote + numbering; it would cause numbering and referencing conflicts. + + Would such mixing inevitably cause conflicts? We could probably work around + potential conflicts with a decent algorithm. Should we? Requires thought. + Opinions? + + [Tony] + Well, I read that paragraph in the documentation, and decided that it + was in the category of "don't, in practice, care" so far as I was + concerned. This is the same category I put the forbidding of nested + inline markup - quite clearly one *can* do it, but equally clearly it's + a pain to implement, and not a terribly great gain, all things + considered. + + It's a category with the subtext "examine for correctness after we've + had some experience of people *using* reST in the wild". + + Thus, given there are lots of other things to do, I would tend to leave + it as-is (especially if you are able to *warn* people about it if they + do it by mistake). + + To my mind, being able to do ``[#thing]_`` probably give people enough + precision over footnotes whils still allowing autonumbering - the *only* + potential problem is when referring to a footnote in a different + document (and that, again, is something I would leave fallow for the + moment, although we know I tend to want to use roles as annotation for + that sort of thing). |
From: David G. <go...@us...> - 2002-01-29 02:18:16
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv1540/dps/test/test_transforms Added Files: test_substitutions.py Log Message: tests for dps.transforms.references.Substitutions --- NEW FILE: test_substitutions.py --- #! /usr/bin/env python """ :Author: David Goodger :Contact: go...@us... :Revision: $Revision: 1.1 $ :Date: $Date: 2002/01/29 02:18:14 $ :Copyright: This module has been placed in the public domain. Tests for dps.transforms.references.Substitutions. """ import DPSTestSupport from dps.transforms.references import Substitutions import UnitTestFolder try: from restructuredtext import Parser except ImportError: from dps.parsers.restructuredtext import Parser def suite(): parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) return s totest = {} totest['substitutions'] = ((Substitutions,), [ ["""\ The |biohazard| symbol is deservedly scary-looking. .. |biohazard| image:: biohazard.png """, """\ <document> <paragraph> The <image alt="biohazard" uri="biohazard.png"> symbol is deservedly scary-looking. <substitution_definition name="biohazard"> <image alt="biohazard" uri="biohazard.png"> """], ["""\ Here's an |unknown| substitution. """, """\ <document> <paragraph> Here's an <problematic> unknown substitution. <system_warning level="2"> <paragraph> Undefined substitution referenced: "unknown". """], ]) if __name__ == '__main__': import unittest unittest.main(defaultTest='suite') |
From: David G. <go...@us...> - 2002-01-29 02:17:55
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv1461/dps/test/test_transforms Modified Files: test_footnotes.py Log Message: updated Index: test_footnotes.py =================================================================== RCS file: /cvsroot/docstring/dps/test/test_transforms/test_footnotes.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_footnotes.py 2002/01/28 02:20:33 1.1 --- test_footnotes.py 2002/01/29 02:17:52 1.2 *************** *** 70,74 **** <document> <paragraph> ! autonumber: <footnote_reference auto="1" refname="1"> 1 --- 70,74 ---- <document> <paragraph> ! autonumber: \n\ <footnote_reference auto="1" refname="1"> 1 *************** *** 165,175 **** <paragraph> Here are some internal cross-references to the implicit targets ! generated by the footnotes: <reference refname="first"> first ! , <reference refname="second"> second ! , <reference refname="third"> third --- 165,175 ---- <paragraph> Here are some internal cross-references to the implicit targets ! generated by the footnotes: \n\ <reference refname="first"> first ! , \n\ <reference refname="second"> second ! , \n\ <reference refname="third"> third *************** *** 197,201 **** <footnote_reference auto="1" refname="four"> 4 ! should be 4, <footnote_reference auto="1" refname="1"> 1 --- 197,201 ---- <footnote_reference auto="1" refname="four"> 4 ! should be 4, \n\ <footnote_reference auto="1" refname="1"> 1 *************** *** 203,212 **** <footnote_reference auto="1" refname="3"> 3 ! should be 3, <footnote_reference auto="1"> is one too many, <footnote_reference auto="1" refname="two"> 2 ! should be 2, and <footnote_reference auto="1" refname="six"> doesn't exist. --- 203,212 ---- <footnote_reference auto="1" refname="3"> 3 ! should be 3, \n\ <footnote_reference auto="1"> is one too many, <footnote_reference auto="1" refname="two"> 2 ! should be 2, and \n\ <footnote_reference auto="1" refname="six"> doesn't exist. *************** *** 278,288 **** autonumber-labeled """], - ]) - ''' ["""\ """, """\ """], ! ''' if __name__ == '__main__': --- 278,318 ---- autonumber-labeled """], ["""\ + A labeled autonumbered footnote referece: [#footnote]_. + + An unlabeled autonumbered footnote referece: [#]_. + + .. [#] Unlabeled autonumbered footnote. + .. [#footnote] Labeled autonumbered footnote. + Note that the footnotes are not in the same + order as the references. """, """\ + <document> + <paragraph> + A labeled autonumbered footnote referece: \n\ + <footnote_reference auto="1" refname="footnote"> + 2 + . + <paragraph> + An unlabeled autonumbered footnote referece: \n\ + <footnote_reference auto="1" refname="1"> + 1 + . + <footnote auto="1" name="1"> + <label> + 1 + <paragraph> + Unlabeled autonumbered footnote. + <footnote auto="1" name="footnote"> + <label> + 2 + <paragraph> + Labeled autonumbered footnote. + Note that the footnotes are not in the same + order as the references. """], ! ]) ! if __name__ == '__main__': |
From: David G. <go...@us...> - 2002-01-29 02:17:45
|
Update of /cvsroot/docstring/dps/spec In directory usw-pr-cvs1:/tmp/cvs-serv1431/dps/spec Modified Files: gpdi.dtd Log Message: updated Index: gpdi.dtd =================================================================== RCS file: /cvsroot/docstring/dps/spec/gpdi.dtd,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** gpdi.dtd 2002/01/26 00:03:16 1.28 --- gpdi.dtd 2002/01/29 02:17:42 1.29 *************** *** 121,125 **** " emphasis | strong | interpreted | literal | reference | footnote_reference | substitution_reference ! | target | image %additional.inline.elements; "> --- 121,125 ---- " emphasis | strong | interpreted | literal | reference | footnote_reference | substitution_reference ! | target | image | problematic %additional.inline.elements; "> *************** *** 460,463 **** --- 460,466 ---- %basic.atts; %refname.att;> + + <!ELEMENT problematic (%text.model;)> + <!ATTLIST problematic %basic.atts;> |
From: David G. <go...@us...> - 2002-01-29 02:17:35
|
Update of /cvsroot/docstring/dps/dps/transforms In directory usw-pr-cvs1:/tmp/cvs-serv1404/dps/dps/transforms Modified Files: references.py Log Message: updated Index: references.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/transforms/references.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** references.py 2002/01/28 02:19:47 1.2 --- references.py 2002/01/29 02:17:32 1.3 *************** *** 145,149 **** def resolve_chained_targets(self): ! ChainedTargetResolver(self.doctree).walk() def resolve_indirect(self): --- 145,150 ---- def resolve_chained_targets(self): ! visitor = ChainedTargetResolver(self.doctree) ! self.doctree.walk(visitor) def resolve_indirect(self): *************** *** 299,312 **** """ """ def transform(self, doctree): self.setup_transform(doctree) - startnum = doctree.autofootnote_start self.autofootnote_labels = [] self.number_footnotes() self.number_footnote_references(startnum) def number_footnotes(self): for footnote in self.doctree.autofootnotes: label = str(self.doctree.autofootnote_start) --- 300,377 ---- """ + Assign numbers and resolve links to autonumbered footnotes and references. + + Given the following ``doctree`` as input:: + + <document> + <paragraph> + A labeled autonumbered footnote referece: + <footnote_reference auto="1" refname="footnote"> + <paragraph> + An unlabeled autonumbered footnote referece: + <footnote_reference auto="1"> + <footnote auto="1"> + <paragraph> + Unlabeled autonumbered footnote. + <footnote auto="1" name="footnote"> + <paragraph> + Labeled autonumbered footnote. + + Auto-numbered footnotes have attribute ``auto="1"`` and no label. + Auto-numbered footnote_references have no reference text (they're + empty elements). When resolving the numbering, a ``label`` element + is added to the beginning of the ``footnote``, and reference text + to the ``footnote_reference``. + + The transformed result will be:: + + <document> + <paragraph> + A labeled autonumbered footnote referece: + <footnote_reference auto="1" refname="footnote"> + 2 + <paragraph> + An unlabeled autonumbered footnote referece: + <footnote_reference auto="1" refname="1"> + 1 + <footnote auto="1" name="1"> + <label> + 1 + <paragraph> + Unlabeled autonumbered footnote. + <footnote auto="1" name="footnote"> + <label> + 2 + <paragraph> + Labeled autonumbered footnote. + + Note that the footnotes are not in the same order as the references. + + The labels and reference text are added to the auto-numbered + ``footnote`` and ``footnote_reference`` elements. The unlabeled + auto-numbered footnote and reference are assigned name and refname + attributes respectively, being the footnote number. + + After adding labels and reference text, the "auto" attributes can be + ignored. """ + autofootnote_labels = None + """Keep track of unlabeled autonumbered footnotes.""" + def transform(self, doctree): self.setup_transform(doctree) self.autofootnote_labels = [] + startnum = doctree.autofootnote_start self.number_footnotes() self.number_footnote_references(startnum) def number_footnotes(self): + """ + Assign numbers to autonumbered footnotes. + + For labeled footnotes, copy the number over to corresponding footnote + references. + """ for footnote in self.doctree.autofootnotes: label = str(self.doctree.autofootnote_start) *************** *** 326,329 **** --- 391,395 ---- def number_footnote_references(self, startnum): + """Assign numbers to unlabeled autonumbered footnote references.""" i = 0 for ref in self.doctree.autofootnote_refs: *************** *** 347,352 **** """ """ def transform(self, doctree): ! pass --- 413,456 ---- """ + Given the following ``doctree`` as input:: + + <document> + <paragraph> + The + <substitution_reference refname="biohazard"> + biohazard + symbol is deservedly scary-looking. + <substitution_definition name="biohazard"> + <image alt="biohazard" uri="biohazard.png"> + + The ``substitution_reference`` will simply be replaced by the + contents of the corresponding ``substitution_definition``. + + The transformed result will be:: + + <document> + <paragraph> + The + <image alt="biohazard" uri="biohazard.png"> + symbol is deservedly scary-looking. + <substitution_definition name="biohazard"> + <image alt="biohazard" uri="biohazard.png"> """ def transform(self, doctree): ! self.setup_transform(doctree) ! self.do_substitutions() ! ! def do_substitutions(self): ! defs = self.doctree.substitution_defs ! for refname, refs in self.doctree.substitution_refs.items(): ! for ref in refs: ! if defs.has_key(refname): ! ref.parent.replace(ref, defs[refname].getchildren()) ! else: ! sw = self.doctree.reporter.error( ! 'Undefined substitution referenced: "%s".' % refname) ! self.doctree += sw ! ref.parent.replace(ref, nodes.problematic( ! ref.rawsource, '', *ref.getchildren())) ! self.doctree.substitution_refs = None # release replaced references |
From: David G. <go...@us...> - 2002-01-29 02:17:20
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv1329/dps/dps Modified Files: nodes.py Log Message: updated Index: nodes.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/nodes.py,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** nodes.py 2002/01/28 02:18:45 1.23 --- nodes.py 2002/01/29 02:17:18 1.24 *************** *** 31,34 **** --- 31,37 ---- """Abstract base class of nodes in a document tree.""" + parent = None + """Back-reference to the `Node` containing this `Node`.""" + def __nonzero__(self): """Node instances are always true.""" *************** *** 132,138 **** """The raw text from which this element was constructed.""" ! self.children = list(children) ! """List of child nodes (elements and/or text).""" self.attributes = attributes """Dictionary of attribute {name: value}.""" --- 135,143 ---- """The raw text from which this element was constructed.""" ! self.children = [] ! """List of child nodes (elements and/or `Text`).""" + self.extend(children) # extend self.children w/ attributes + self.attributes = attributes """Dictionary of attribute {name: value}.""" *************** *** 217,223 **** --- 222,231 ---- self.attributes[key] = item elif isinstance(key, IntType): + item.parent = self self.children[key] = item elif isinstance(key, SliceType): assert key.step is None, 'cannot handle slice with stride' + for node in item: + node.parent = self self.children[key.start:key.stop] = item else: *************** *** 246,251 **** --- 254,262 ---- """Append a node or a list of nodes to `self.children`.""" if isinstance(other, Node): + other.parent = self self.children.append(other) elif other is not None: + for node in other: + node.parent = self self.children.extend(other) return self *************** *** 269,280 **** def append(self, item): ! assert isinstance(item, Node) self.children.append(item) def extend(self, item): self.children.extend(item) def insert(self, i, item): assert isinstance(item, Node) self.children.insert(i, item) --- 280,294 ---- def append(self, item): ! item.parent = self self.children.append(item) def extend(self, item): + for node in item: + node.parent = self self.children.extend(item) def insert(self, i, item): assert isinstance(item, Node) + item.parent = self self.children.insert(i, item) *************** *** 283,289 **** def remove(self, item): - assert isinstance(item, Node) self.children.remove(item) def findclass(self, childclass, start=0, end=sys.maxint): """ --- 297,313 ---- def remove(self, item): self.children.remove(item) + def index(self, item): + return self.children.index(item) + + def replace(self, old, new): + """Replace one child `Node` with another child or children.""" + index = self.index(old) + if isinstance(new, Node): + self[index] = new + elif new is not None: + self[index:index+1] = new + def findclass(self, childclass, start=0, end=sys.maxint): """ *************** *** 673,676 **** --- 697,701 ---- class substitution_reference(Inline, Reference, TextElement): pass class image(General, Inline, TextElement): pass + class problematic(Inline, TextElement): pass *************** *** 694,698 **** note option option_argument option_list option_list_item organization ! paragraph reference revision row section short_option status strong substitution_definition --- 719,723 ---- note option option_argument option_list option_list_item organization ! paragraph problematic reference revision row section short_option status strong substitution_definition *************** *** 714,718 **** "``visit_`` + node class name" method is called by `Node.walk()` upon entering a node. ! .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, --- 739,743 ---- "``visit_`` + node class name" method is called by `Node.walk()` upon entering a node. ! .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA, |
From: David G. <go...@us...> - 2002-01-28 02:22:36
|
Update of /cvsroot/docstring/dps In directory usw-pr-cvs1:/tmp/cvs-serv11709/dps Modified Files: HISTORY.txt Log Message: updated Index: HISTORY.txt =================================================================== RCS file: /cvsroot/docstring/dps/HISTORY.txt,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** HISTORY.txt 2002/01/26 00:10:29 1.33 --- HISTORY.txt 2002/01/28 02:22:34 1.34 *************** *** 81,84 **** --- 81,85 ---- - Removed Python-specific element classes. - Reworked for hyperlink transforms. + - Added support for footnote transform. * dps/roman.py: Added to project. Written by and courtesy of Mark |
From: David G. <go...@us...> - 2002-01-28 02:21:57
|
Update of /cvsroot/docstring/dps/test In directory usw-pr-cvs1:/tmp/cvs-serv11581/dps/test Added Files: difflib.py Log Message: Pre-Python2.2 version as required by tests. --- NEW FILE: difflib.py --- #! /usr/bin/env python """ Module difflib -- helpers for computing deltas between objects. Function get_close_matches(word, possibilities, n=3, cutoff=0.6): Use SequenceMatcher to return list of the best "good enough" matches. Function ndiff(a, b): Return a delta: the difference between `a` and `b` (lists of strings). Function restore(delta, which): Return one of the two sequences that generated an ndiff delta. Class SequenceMatcher: A flexible class for comparing pairs of sequences of any type. Class Differ: For producing human-readable deltas from sequences of lines of text. [...1050 lines suppressed...] emu """ try: tag = {1: "- ", 2: "+ "}[int(which)] except KeyError: raise ValueError, ('unknown delta choice (must be 1 or 2): %r' % which) prefixes = (" ", tag) results = [] for line in delta: if line[:2] in prefixes: results.append(line[2:]) return results def _test(): import doctest, difflib return doctest.testmod(difflib) if __name__ == "__main__": _test() |
From: David G. <go...@us...> - 2002-01-28 02:20:36
|
Update of /cvsroot/docstring/dps/test/test_transforms In directory usw-pr-cvs1:/tmp/cvs-serv11367/dps/test/test_transforms Added Files: test_footnotes.py Log Message: Tests for dps.transforms.references.Footnotes --- NEW FILE: test_footnotes.py --- #! /usr/bin/env python """ :Author: David Goodger :Contact: go...@us... :Revision: $Revision: 1.1 $ :Date: $Date: 2002/01/28 02:20:33 $ :Copyright: This module has been placed in the public domain. Tests for dps.transforms.references.Footnotes. """ import DPSTestSupport from dps.transforms.references import Footnotes import UnitTestFolder try: from restructuredtext import Parser except ImportError: from dps.parsers.restructuredtext import Parser def suite(): parser = Parser(warninglevel=4, errorlevel=4, languagecode='en', debug=UnitTestFolder.debug) s = DPSTestSupport.TransformTestSuite(parser) s.generateTests(totest) return s totest = {} totest['footnotes'] = ((Footnotes,), [ ["""\ [label]_ .. [label] text """, """\ <document> <paragraph> <footnote_reference refname="label"> label <footnote name="label"> <label> label <paragraph> text """], ["""\ [#autolabel]_ .. [#autolabel] text """, """\ <document> <paragraph> <footnote_reference auto="1" refname="autolabel"> 1 <footnote auto="1" name="autolabel"> <label> 1 <paragraph> text """], # @@@ remove "auto" atts? ["""\ autonumber: [#]_ .. [#] text """, """\ <document> <paragraph> autonumber: <footnote_reference auto="1" refname="1"> 1 <footnote auto="1" name="1"> <label> 1 <paragraph> text """], ["""\ [#]_ is the first auto-numbered footnote reference. [#]_ is the second auto-numbered footnote reference. .. [#] Auto-numbered footnote 1. .. [#] Auto-numbered footnote 2. .. [#] Auto-numbered footnote 3. [#]_ is the third auto-numbered footnote reference. """, """\ <document> <paragraph> <footnote_reference auto="1" refname="1"> 1 is the first auto-numbered footnote reference. <footnote_reference auto="1" refname="2"> 2 is the second auto-numbered footnote reference. <footnote auto="1" name="1"> <label> 1 <paragraph> Auto-numbered footnote 1. <footnote auto="1" name="2"> <label> 2 <paragraph> Auto-numbered footnote 2. <footnote auto="1" name="3"> <label> 3 <paragraph> Auto-numbered footnote 3. <paragraph> <footnote_reference auto="1" refname="3"> 3 is the third auto-numbered footnote reference. """], ["""\ [#third]_ is a reference to the third auto-numbered footnote. .. [#first] First auto-numbered footnote. .. [#second] Second auto-numbered footnote. .. [#third] Third auto-numbered footnote. [#second]_ is a reference to the second auto-numbered footnote. [#first]_ is a reference to the first auto-numbered footnote. [#third]_ is another reference to the third auto-numbered footnote. Here are some internal cross-references to the implicit targets generated by the footnotes: first_, second_, third_. """, """\ <document> <paragraph> <footnote_reference auto="1" refname="third"> 3 is a reference to the third auto-numbered footnote. <footnote auto="1" name="first"> <label> 1 <paragraph> First auto-numbered footnote. <footnote auto="1" name="second"> <label> 2 <paragraph> Second auto-numbered footnote. <footnote auto="1" name="third"> <label> 3 <paragraph> Third auto-numbered footnote. <paragraph> <footnote_reference auto="1" refname="second"> 2 is a reference to the second auto-numbered footnote. <footnote_reference auto="1" refname="first"> 1 is a reference to the first auto-numbered footnote. <footnote_reference auto="1" refname="third"> 3 is another reference to the third auto-numbered footnote. <paragraph> Here are some internal cross-references to the implicit targets generated by the footnotes: <reference refname="first"> first , <reference refname="second"> second , <reference refname="third"> third . """], ["""\ Mixed anonymous and labelled auto-numbered footnotes: [#four]_ should be 4, [#]_ should be 1, [#]_ should be 3, [#]_ is one too many, [#two]_ should be 2, and [#six]_ doesn't exist. .. [#] Auto-numbered footnote 1. .. [#two] Auto-numbered footnote 2. .. [#] Auto-numbered footnote 3. .. [#four] Auto-numbered footnote 4. .. [#five] Auto-numbered footnote 5. .. [#five] Auto-numbered footnote 5 again (duplicate). """, """\ <document> <paragraph> Mixed anonymous and labelled auto-numbered footnotes: <paragraph> <footnote_reference auto="1" refname="four"> 4 should be 4, <footnote_reference auto="1" refname="1"> 1 should be 1, <footnote_reference auto="1" refname="3"> 3 should be 3, <footnote_reference auto="1"> is one too many, <footnote_reference auto="1" refname="two"> 2 should be 2, and <footnote_reference auto="1" refname="six"> doesn't exist. <footnote auto="1" name="1"> <label> 1 <paragraph> Auto-numbered footnote 1. <footnote auto="1" name="two"> <label> 2 <paragraph> Auto-numbered footnote 2. <footnote auto="1" name="3"> <label> 3 <paragraph> Auto-numbered footnote 3. <footnote auto="1" name="four"> <label> 4 <paragraph> Auto-numbered footnote 4. <footnote auto="1" dupname="five"> <label> 5 <paragraph> Auto-numbered footnote 5. <footnote auto="1" dupname="five"> <label> 6 <system_warning level="1"> <paragraph> Duplicate explicit target name: "five" <paragraph> Auto-numbered footnote 5 again (duplicate). <system_warning level="2"> <paragraph> Too many autonumbered footnote references: only 2 corresponding footnotes available. """], ["""\ Mixed auto-numbered and manual footnotes: .. [1] manually numbered .. [#] auto-numbered .. [#label] autonumber-labeled """, """\ <document> <paragraph> Mixed auto-numbered and manual footnotes: <footnote dupname="1"> <label> 1 <paragraph> manually numbered <footnote auto="1" dupname="1"> <label> 1 <paragraph> auto-numbered <system_warning level="1"> <paragraph> Duplicate explicit target name: "1" <footnote auto="1" name="label"> <label> 2 <paragraph> autonumber-labeled """], ]) ''' ["""\ """, """\ """], ''' if __name__ == '__main__': import unittest unittest.main(defaultTest='suite') |
From: David G. <go...@us...> - 2002-01-28 02:19:50
|
Update of /cvsroot/docstring/dps/dps/transforms In directory usw-pr-cvs1:/tmp/cvs-serv11195/dps/dps/transforms Modified Files: references.py Log Message: - Added footnote numbering transform. Index: references.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/transforms/references.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** references.py 2002/01/26 00:10:09 1.1 --- references.py 2002/01/28 02:19:47 1.2 *************** *** 302,306 **** def transform(self, doctree): ! pass --- 302,345 ---- def transform(self, doctree): ! self.setup_transform(doctree) ! startnum = doctree.autofootnote_start ! self.autofootnote_labels = [] ! self.number_footnotes() ! self.number_footnote_references(startnum) ! ! def number_footnotes(self): ! for footnote in self.doctree.autofootnotes: ! label = str(self.doctree.autofootnote_start) ! self.doctree.autofootnote_start += 1 ! footnote.insert(0, nodes.label('', label)) ! if footnote.hasattr('dupname'): ! continue ! if footnote.hasattr('name'): ! name = footnote['name'] ! for ref in self.doctree.footnote_refs.get(name, []): ! ref += nodes.Text(label) ! ref.resolved = 1 ! else: ! footnote['name'] = label ! self.doctree.note_explicit_target(footnote, footnote) ! self.autofootnote_labels.append(label) ! ! def number_footnote_references(self, startnum): ! i = 0 ! for ref in self.doctree.autofootnote_refs: ! if ref.resolved or ref.hasattr('refname'): ! continue ! try: ! ref += nodes.Text(self.autofootnote_labels[i]) ! ref['refname'] = self.autofootnote_labels[i] ! except IndexError: ! sw = self.doctree.reporter.error( ! 'Too many autonumbered footnote references: only %s ' ! 'corresponding footnotes available.' ! % len(self.autofootnote_labels)) ! self.doctree += sw ! break ! ref.resolved = 1 ! i += 1 |
From: David G. <go...@us...> - 2002-01-28 02:18:47
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv11017/dps/dps Modified Files: nodes.py Log Message: - Added support for footnote transform. Index: nodes.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/nodes.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** nodes.py 2002/01/25 23:58:09 1.22 --- nodes.py 2002/01/28 02:18:45 1.23 *************** *** 436,439 **** --- 436,442 ---- """Mapping of substitution names to substitution_reference nodes.""" + self.footnote_refs = {} + """Mapping of footnote labels to footnote_reference nodes.""" + self.anonymous_targets = [] """List of anonymous target nodes.""" *************** *** 532,535 **** --- 535,542 ---- def note_autofootnote_ref(self, refnode): self.autofootnote_refs.append(refnode) + + def note_footnote_ref(self, refnode): + self.footnote_refs.setdefault(refnode['refname'], []).append(refnode) + self.note_refname(refnode) def note_substitution_def(self, substitutiondefnode, innode=None): |
From: David G. <go...@us...> - 2002-01-28 02:18:20
|
Update of /cvsroot/docstring/dps/spec In directory usw-pr-cvs1:/tmp/cvs-serv10929/dps/spec Modified Files: dps-notes.txt Log Message: updated Index: dps-notes.txt =================================================================== RCS file: /cvsroot/docstring/dps/spec/dps-notes.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dps-notes.txt 2002/01/26 00:02:16 1.19 --- dps-notes.txt 2002/01/28 02:18:17 1.20 *************** *** 67,70 **** --- 67,76 ---- - Apply the `coding conventions`_ as given below. + - Reconsider the need to keep a list of duplicates in + ``nodes.document.explicit_targets``. Rather, just keep the last + instance, and "clear" it and any new ones if necessary. Perhaps just + a {'name': None} mapping is enough to indicate that the target is + invalid? + Coding Conventions *************** *** 406,415 **** ! nodes.py ======== ! Add ``Nodes.walkabout()``, ``Visitor.walkabout()``, ``Visitor.leave_*()``, and ``GenericVisitor.default_leave()`` methods ! to catch elements on the way out? Here's ``Nodes.walkabout()``:: def walkabout(self, visitor, ancestry=()): --- 412,421 ---- ! Visitors ======== ! To nodes.py, add ``Node.walkabout()``, ``Visitor.walkabout()``, ``Visitor.leave_*()``, and ``GenericVisitor.default_leave()`` methods ! to catch elements on the way out? Here's ``Node.walkabout()``:: def walkabout(self, visitor, ancestry=()): |
From: David G. <go...@us...> - 2002-01-26 00:10:32
|
Update of /cvsroot/docstring/dps In directory usw-pr-cvs1:/tmp/cvs-serv7309/dps Modified Files: HISTORY.txt Log Message: updated Index: HISTORY.txt =================================================================== RCS file: /cvsroot/docstring/dps/HISTORY.txt,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** HISTORY.txt 2002/01/16 02:56:37 1.32 --- HISTORY.txt 2002/01/26 00:10:29 1.33 *************** *** 48,53 **** - Added 'error', 'attention'. - Fixed link bookkeeping. ! - Added docstrings to _Element. ! - Extended _Element.__iadd__ (``+=``) to lists of nodes. - Duplicate hyperlink names -> dupname attribute. - Allow any DOM implementation from ``asdom()`` method. (I think.) --- 48,53 ---- - Added 'error', 'attention'. - Fixed link bookkeeping. ! - Added docstrings. ! - Extended Element.__iadd__ (``+=``) to lists of nodes. - Duplicate hyperlink names -> dupname attribute. - Allow any DOM implementation from ``asdom()`` method. (I think.) *************** *** 76,79 **** --- 76,84 ---- - 'errorhandler' -> 'reporter'. - Added document.languagecode. + - Added Visitor classes & Node.walk(). + - Improved ``__repr__()``. + - Improved some names. + - Removed Python-specific element classes. + - Reworked for hyperlink transforms. * dps/roman.py: Added to project. Written by and courtesy of Mark *************** *** 127,130 **** --- 132,136 ---- - Added 'bibliographic_fields' and 'author_separators' (transform support). + - Removed Python-specific interpreted text mapping. * dps/transforms: Subpackage added. |
From: David G. <go...@us...> - 2002-01-26 00:10:12
|
Update of /cvsroot/docstring/dps/dps/transforms In directory usw-pr-cvs1:/tmp/cvs-serv7211/dps/dps/transforms Added Files: references.py Log Message: Transforms for resolving references: hyperlinks, footnotes, and substitutions. --- NEW FILE: references.py --- #! /usr/bin/env python """ :Authors: David Goodger :Contact: go...@us... :Revision: $Revision: 1.1 $ :Date: $Date: 2002/01/26 00:10:09 $ :Copyright: This module has been placed in the public domain. Transforms for resolving references: - `Hyperlinks`: Used to resolve hyperlink targets and references. - `Footnotes`: Resolve footnote numbering and references. - `Substitutions`: Resolve substitutions. """ __docformat__ = 'reStructuredText' import re from dps import nodes, utils from dps.transforms import TransformError, Transform class Hyperlinks(Transform): """ Resolve the various types of hyperlink targets and references. Shown in isolation, the following individual transforms are performed: 1. Anonymous references and targets:: <paragraph> <reference anonymous="1"> text <target anonymous="1"> Corresponding references and targets are assigned names, and the "anonymous" attributes are dropped:: <paragraph> <reference refname="_:1:_"> text <target name="_:1:_"> 2. Chained targets:: <target name="chained"> <target name="external hyperlink" refuri="http://uri"> Attributes "refuri" and "refname" are migrated from the final concrete target up the chain of contiguous adjacent internal targets:: <target name="chained" refuri="http://uri"> <target name="external hyperlink" refuri="http://uri"> 3. a) Indirect targets:: <paragraph> <reference refname="indirect external"> indirect external <target name="direct external" refuri="http://indirect"> <target name="indirect external" refname="direct external"> Attributes "refuri" and "refname" are migrated back to all indirect targets from the final concrete target (i.e. not referring to another indirect target):: <paragraph> <reference refname="indirect external"> indirect external <target name="direct external" refuri="http://indirect"> <target name="indirect external" refuri="http://indirect"> If the "refuri" attribute is migrated, the preexisting "refname" attribute is dropped. This turns indirect external references into direct external references. b) Indirect internal references:: <target name="final target"> <paragraph> <reference refname="indirect internal"> indirect internal <target name="indirect internal 2" refname="final target"> <target name="indirect internal" refname="indirect internal 2"> Targets which indirectly refer to an internal target become one-hop indirect (their "refname" attributes are directly set to the internal target's "name"). References which indirectly refer to an internal target become direct internal references:: <target name="final target"> <paragraph> <reference refname="final target"> indirect internal <target name="indirect internal 2" refname="final target"> <target name="indirect internal" refname="final target"> 4. External references:: <paragraph> <reference refname="direct external"> direct external <target name="direct external" refuri="http://direct"> The "refname" attribute is replaced by the direct "refuri" attribute:: <paragraph> <reference refuri="http://direct"> direct external <target name="direct external" refuri="http://direct"> """ def transform(self, doctree): self.setup_transform(doctree) self.resolve_anonymous() self.resolve_chained_targets() self.resolve_indirect() self.resolve_external_references() def resolve_anonymous(self): if len(self.doctree.anonymous_refs) \ != len(self.doctree.anonymous_targets): sw = self.doctree.reporter.error( 'Anonymous hyperlink mismatch: %s references but %s targets.' % (len(self.doctree.anonymous_refs), len(self.doctree.anonymous_targets))) self.doctree += sw return for i in range(len(self.doctree.anonymous_refs)): name = '_:%s:_' % self.doctree.anonymous_start self.doctree.anonymous_start += 1 ref = self.doctree.anonymous_refs[i] ref['refname'] = name del ref['anonymous'] self.doctree.note_refname(ref) target = self.doctree.anonymous_targets[i] target['name'] = name del target['anonymous'] self.doctree.note_implicit_target(target, self.doctree) if target.hasattr('refname'): self.doctree.note_indirect_target(target) if target.hasattr('refuri'): self.doctree.note_external_target(target) def resolve_chained_targets(self): ChainedTargetResolver(self.doctree).walk() def resolve_indirect(self): for name, targets in self.doctree.indirect_targets.items(): if len(targets) == 1: target = targets[-1] if not target.resolved: self.one_indirect_target(target) if target.hasattr('refname'): self.one_indirect_reference(target['name'], target['refname']) def one_indirect_target(self, target): name = target['name'] refname = target['refname'] try: reftargetlist = self.doctree.explicit_targets[refname] except KeyError: sw = self.doctree.reporter.warning( 'Indirect hyperlink target "%s" refers to target "%s", ' 'which does not exist.' % (name, refname)) self.doctree += sw reftarget = reftargetlist[-1] if reftarget.hasattr('name'): if not reftarget.resolved and reftarget.hasattr('refname'): self.one_indirect_target(reftarget) if reftarget.hasattr('refuri'): target['refuri'] = reftarget['refuri'] del target['refname'] self.doctree.note_external_target(target) elif reftarget.hasattr('refname'): target['refname'] = reftarget['refname'] target.resolved = 1 def one_indirect_reference(self, name, refname): try: reflist = self.doctree.refnames[name] except KeyError, instance: sw = self.doctree.reporter.information( 'Indirect hyperlink target "%s" is not referenced.' % name) self.doctree += sw return for ref in self.doctree.refnames[name]: if ref.resolved: continue try: ref['refname'] = refname except KeyError, instance: sw = self.doctree.reporter.error( 'Indirect hyperlink target "%s" has no "refname" ' 'attribute.' % name) self.doctree += sw continue ref.resolved = 1 if isinstance(ref, nodes.target): self.one_indirect_reference(ref['name'], refname) def resolve_external_references(self): for name, targets in self.doctree.external_targets.items(): target = targets[-1] if target.hasattr('refuri') and target.hasattr('name'): self.one_external_reference(name, targets[-1]['refuri']) def one_external_reference(self, name, refuri): try: reflist = self.doctree.refnames[name] except KeyError, instance: sw = self.doctree.reporter.information( 'External hyperlink target "%s" is not referenced.' % name) self.doctree += sw return for ref in self.doctree.refnames[name]: if ref.resolved: continue try: ref['refuri'] = refuri except KeyError, instance: sw = self.doctree.reporter.error( 'External hyperlink target "%s" has no "refuri" ' 'attribute.' % name) self.doctree += sw continue del ref['refname'] ref.resolved = 1 if isinstance(ref, nodes.target): self.one_external_reference(ref['name'], refuri) class ChainedTargetResolver(nodes.Visitor): """ Copy reference attributes up a length of hyperlink target chain. "Chained targets" are multiple adjacent internal hyperlink targets which "point to" an external or indirect target. After the transform, all chained targets will effectively point to the same place. Given the following ``doctree`` as input:: <document> <target name="a"> <target name="b"> <target name="c" refuri="http://chained.external.targets"> <target name="d"> <paragraph> I'm known as "d". <target name="e"> <target name="f"> <target name="g" refname="d"> ``ChainedTargetResolver(doctree).walk()`` will transform the above into:: <document> <target name="a" refuri="http://chained.external.targets"> <target name="b" refuri="http://chained.external.targets"> <target name="c" refuri="http://chained.external.targets"> <target name="d"> <paragraph> I'm known as "d". <target name="e" refname="d"> <target name="f" refname="d"> <target name="g" refname="d"> """ def visit_target(self, node, ancestry): if node.hasattr('refuri'): refuri = node['refuri'] parent, index = ancestry[-1] for i in range(index - 1, -1, -1): sibling = parent[i] if not isinstance(sibling, nodes.target) \ or sibling.hasattr('refuri') \ or sibling.hasattr('refname'): break sibling['refuri'] = refuri self.doctree.note_external_target(sibling) elif node.hasattr('refname'): refname = node['refname'] parent, index = ancestry[-1] for i in range(index - 1, -1, -1): sibling = parent[i] if not isinstance(sibling, nodes.target) \ or sibling.hasattr('refuri') \ or sibling.hasattr('refname'): break sibling['refname'] = refname self.doctree.note_indirect_target(sibling) class Footnotes(Transform): """ """ def transform(self, doctree): pass class Substitutions(Transform): """ """ def transform(self, doctree): pass |