Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{sgmllib} --- |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 2 | Simple SGML parser} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{sgmllib} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | \modulesynopsis{Only as much of an SGML parser as needed to parse HTML.} |
| 6 | |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 7 | \index{SGML} |
| 8 | |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 9 | This module defines a class \class{SGMLParser} which serves as the |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 10 | basis for parsing text files formatted in SGML (Standard Generalized |
| 11 | Mark-up Language). In fact, it does not provide a full SGML parser |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 12 | --- it only parses SGML insofar as it is used by HTML, and the module |
Fred Drake | 25211f5 | 2001-07-05 16:34:36 +0000 | [diff] [blame] | 13 | only exists as a base for the \refmodule{htmllib} module. Another |
| 14 | HTML parser which supports XHTML and offers a somewhat different |
| 15 | interface is available in the \refmodule{HTMLParser} module. |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 16 | |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 17 | \begin{classdesc}{SGMLParser}{} |
| 18 | The \class{SGMLParser} class is instantiated without arguments. |
| 19 | The parser is hardcoded to recognize the following |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 20 | constructs: |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 21 | |
| 22 | \begin{itemize} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 23 | \item |
| 24 | Opening and closing tags of the form |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 25 | \samp{<\var{tag} \var{attr}="\var{value}" ...>} and |
| 26 | \samp{</\var{tag}>}, respectively. |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 27 | |
| 28 | \item |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 29 | Numeric character references of the form \samp{\&\#\var{name};}. |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 30 | |
| 31 | \item |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 32 | Entity references of the form \samp{\&\var{name};}. |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 33 | |
| 34 | \item |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 35 | SGML comments of the form \samp{<!--\var{text}-->}. Note that |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 36 | spaces, tabs, and newlines are allowed between the trailing |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 37 | \samp{>} and the immediately preceding \samp{--}. |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 38 | |
| 39 | \end{itemize} |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 40 | \end{classdesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 41 | |
Fred Drake | 961c288 | 2004-09-10 01:20:21 +0000 | [diff] [blame] | 42 | A single exception is defined as well: |
| 43 | |
| 44 | \begin{excdesc}{SGMLParseError} |
| 45 | Exception raised by the \class{SGMLParser} class when it encounters an |
| 46 | error while parsing. |
| 47 | \versionadded{2.1} |
| 48 | \end{excdesc} |
| 49 | |
| 50 | |
| 51 | \class{SGMLParser} instances have the following methods: |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 52 | |
Fred Drake | 8f92595 | 1996-10-09 16:13:22 +0000 | [diff] [blame] | 53 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 54 | \begin{methoddesc}{reset}{} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 55 | Reset the instance. Loses all unprocessed data. This is called |
| 56 | implicitly at instantiation time. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 57 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 58 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 59 | \begin{methoddesc}{setnomoretags}{} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 60 | Stop processing tags. Treat all following input as literal input |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 61 | (CDATA). (This is only provided so the HTML tag |
| 62 | \code{<PLAINTEXT>} can be implemented.) |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 63 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 64 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 65 | \begin{methoddesc}{setliteral}{} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 66 | Enter literal mode (CDATA mode). |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 67 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 68 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 69 | \begin{methoddesc}{feed}{data} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 70 | Feed some text to the parser. It is processed insofar as it consists |
| 71 | of complete elements; incomplete data is buffered until more data is |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 72 | fed or \method{close()} is called. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 73 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 74 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 75 | \begin{methoddesc}{close}{} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 76 | Force processing of all buffered data as if it were followed by an |
| 77 | end-of-file mark. This method may be redefined by a derived class to |
| 78 | define additional processing at the end of the input, but the |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 79 | redefined version should always call \method{close()}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 80 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 81 | |
Fred Drake | 25e7cee | 2000-07-03 14:32:04 +0000 | [diff] [blame] | 82 | \begin{methoddesc}{get_starttag_text}{} |
| 83 | Return the text of the most recently opened start tag. This should |
| 84 | not normally be needed for structured processing, but may be useful in |
| 85 | dealing with HTML ``as deployed'' or for re-generating input with |
| 86 | minimal changes (whitespace between attributes can be preserved, |
| 87 | etc.). |
| 88 | \end{methoddesc} |
| 89 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 90 | \begin{methoddesc}{handle_starttag}{tag, method, attributes} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 91 | This method is called to handle start tags for which either a |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 92 | \method{start_\var{tag}()} or \method{do_\var{tag}()} method has been |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 93 | defined. The \var{tag} argument is the name of the tag converted to |
| 94 | lower case, and the \var{method} argument is the bound method which |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 95 | should be used to support semantic interpretation of the start tag. |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 96 | The \var{attributes} argument is a list of \code{(\var{name}, |
| 97 | \var{value})} pairs containing the attributes found inside the tag's |
Georg Brandl | 9cdf563 | 2006-04-01 08:39:50 +0000 | [diff] [blame] | 98 | \code{<>} brackets. |
| 99 | |
| 100 | The \var{name} has been translated to lower case. |
Georg Brandl | 7f6b67c | 2006-04-01 08:35:18 +0000 | [diff] [blame] | 101 | Double quotes and backslashes in the \var{value} have been interpreted, |
Georg Brandl | 9cdf563 | 2006-04-01 08:39:50 +0000 | [diff] [blame] | 102 | as well as known character references and known entity references |
| 103 | terminated by a semicolon (normally, entity references can be terminated |
| 104 | by any non-alphanumerical character, but this would break the very |
Georg Brandl | cd10347 | 2006-04-01 20:40:16 +0000 | [diff] [blame] | 105 | common case of \code{<A HREF="url?spam=1\&eggs=2">} when \code{eggs} |
Georg Brandl | 9cdf563 | 2006-04-01 08:39:50 +0000 | [diff] [blame] | 106 | is a valid entity name). |
| 107 | |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 108 | For instance, for the tag \code{<A HREF="http://www.cwi.nl/">}, this |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 109 | method would be called as \samp{unknown_starttag('a', [('href', |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 110 | 'http://www.cwi.nl/')])}. The base implementation simply calls |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 111 | \var{method} with \var{attributes} as the only argument. |
Georg Brandl | 7f6b67c | 2006-04-01 08:35:18 +0000 | [diff] [blame] | 112 | \versionadded[Handling of entity and character references within |
| 113 | attribute values]{2.5} |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 114 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 115 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 116 | \begin{methoddesc}{handle_endtag}{tag, method} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 117 | This method is called to handle endtags for which an |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 118 | \method{end_\var{tag}()} method has been defined. The |
| 119 | \var{tag} argument is the name of the tag converted to lower case, and |
| 120 | the \var{method} argument is the bound method which should be used to |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 121 | support semantic interpretation of the end tag. If no |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 122 | \method{end_\var{tag}()} method is defined for the closing element, |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 123 | this handler is not called. The base implementation simply calls |
| 124 | \var{method}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 125 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 126 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 127 | \begin{methoddesc}{handle_data}{data} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 128 | This method is called to process arbitrary data. It is intended to be |
| 129 | overridden by a derived class; the base class implementation does |
| 130 | nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 131 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 132 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 133 | \begin{methoddesc}{handle_charref}{ref} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 134 | This method is called to process a character reference of the form |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 135 | \samp{\&\#\var{ref};}. In the base implementation, \var{ref} must |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 136 | be a decimal number in the |
| 137 | range 0-255. It translates the character to \ASCII{} and calls the |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 138 | method \method{handle_data()} with the character as argument. If |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 139 | \var{ref} is invalid or out of range, the method |
| 140 | \code{unknown_charref(\var{ref})} is called to handle the error. A |
| 141 | subclass must override this method to provide support for named |
| 142 | character entities. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 143 | \end{methoddesc} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 144 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 145 | \begin{methoddesc}{handle_entityref}{ref} |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 146 | This method is called to process a general entity reference of the |
| 147 | form \samp{\&\var{ref};} where \var{ref} is an general entity |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 148 | reference. It looks for \var{ref} in the instance (or class) |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 149 | variable \member{entitydefs} which should be a mapping from entity |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 150 | names to corresponding translations. If a translation is found, it |
| 151 | calls the method \method{handle_data()} with the translation; |
| 152 | otherwise, it calls the method \code{unknown_entityref(\var{ref})}. |
| 153 | The default \member{entitydefs} defines translations for |
| 154 | \code{\&}, \code{\&apos}, \code{\>}, \code{\<}, and |
| 155 | \code{\"}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 156 | \end{methoddesc} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 157 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 158 | \begin{methoddesc}{handle_comment}{comment} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 159 | This method is called when a comment is encountered. The |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 160 | \var{comment} argument is a string containing the text between the |
Fred Drake | b441eb8 | 1998-02-13 14:37:12 +0000 | [diff] [blame] | 161 | \samp{<!--} and \samp{-->} delimiters, but not the delimiters |
| 162 | themselves. For example, the comment \samp{<!--text-->} will |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 163 | cause this method to be called with the argument \code{'text'}. The |
| 164 | default method does nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 165 | \end{methoddesc} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 166 | |
Fred Drake | b15bbc8 | 2001-03-16 20:39:41 +0000 | [diff] [blame] | 167 | \begin{methoddesc}{handle_decl}{data} |
| 168 | Method called when an SGML declaration is read by the parser. In |
| 169 | practice, the \code{DOCTYPE} declaration is the only thing observed in |
| 170 | HTML, but the parser does not discriminate among different (or broken) |
| 171 | declarations. Internal subsets in a \code{DOCTYPE} declaration are |
| 172 | not supported. The \var{data} parameter will be the entire contents |
| 173 | of the declaration inside the \code{<!}...\code{>} markup. The |
| 174 | default implementation does nothing. |
| 175 | \end{methoddesc} |
| 176 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 177 | \begin{methoddesc}{report_unbalanced}{tag} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 178 | This method is called when an end tag is found which does not |
| 179 | correspond to any open element. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 180 | \end{methoddesc} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 181 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 182 | \begin{methoddesc}{unknown_starttag}{tag, attributes} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 183 | This method is called to process an unknown start tag. It is intended |
| 184 | to be overridden by a derived class; the base class implementation |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 185 | does nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 186 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 187 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 188 | \begin{methoddesc}{unknown_endtag}{tag} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 189 | This method is called to process an unknown end tag. It is intended |
| 190 | to be overridden by a derived class; the base class implementation |
| 191 | does nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 192 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 193 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 194 | \begin{methoddesc}{unknown_charref}{ref} |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 195 | This method is called to process unresolvable numeric character |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 196 | references. Refer to \method{handle_charref()} to determine what is |
| 197 | handled by default. It is intended to be overridden by a derived |
| 198 | class; the base class implementation does nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 199 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 200 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 201 | \begin{methoddesc}{unknown_entityref}{ref} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 202 | This method is called to process an unknown entity reference. It is |
| 203 | intended to be overridden by a derived class; the base class |
| 204 | implementation does nothing. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 205 | \end{methoddesc} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 206 | |
| 207 | Apart from overriding or extending the methods listed above, derived |
| 208 | classes may also define methods of the following form to define |
| 209 | processing of specific tags. Tag names in the input stream are case |
| 210 | independent; the \var{tag} occurring in method names must be in lower |
| 211 | case: |
| 212 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 213 | \begin{methoddescni}{start_\var{tag}}{attributes} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 214 | This method is called to process an opening tag \var{tag}. It has |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 215 | preference over \method{do_\var{tag}()}. The |
| 216 | \var{attributes} argument has the same meaning as described for |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 217 | \method{handle_starttag()} above. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 218 | \end{methoddescni} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 219 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 220 | \begin{methoddescni}{do_\var{tag}}{attributes} |
Andrew M. Kuchling | 29d530b | 2006-06-03 18:09:41 +0000 | [diff] [blame] | 221 | This method is called to process an opening tag \var{tag} |
| 222 | for which no \method{start_\var{tag}} method is defined. |
| 223 | The \var{attributes} argument |
Fred Drake | 2dde74c | 1998-03-12 14:42:23 +0000 | [diff] [blame] | 224 | has the same meaning as described for \method{handle_starttag()} above. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 225 | \end{methoddescni} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 226 | |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 227 | \begin{methoddescni}{end_\var{tag}}{} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 228 | This method is called to process a closing tag \var{tag}. |
Fred Drake | 8fe533e | 1998-03-27 05:27:08 +0000 | [diff] [blame] | 229 | \end{methoddescni} |
Guido van Rossum | 8675115 | 1995-02-28 17:14:32 +0000 | [diff] [blame] | 230 | |
Fred Drake | 42439ad | 1996-10-08 21:51:49 +0000 | [diff] [blame] | 231 | Note that the parser maintains a stack of open elements for which no |
| 232 | end tag has been found yet. Only tags processed by |
Fred Drake | 4e28c59 | 1999-04-22 18:25:47 +0000 | [diff] [blame] | 233 | \method{start_\var{tag}()} are pushed on this stack. Definition of an |
| 234 | \method{end_\var{tag}()} method is optional for these tags. For tags |
| 235 | processed by \method{do_\var{tag}()} or by \method{unknown_tag()}, no |
| 236 | \method{end_\var{tag}()} method must be defined; if defined, it will |
| 237 | not be used. If both \method{start_\var{tag}()} and |
| 238 | \method{do_\var{tag}()} methods exist for a tag, the |
| 239 | \method{start_\var{tag}()} method takes precedence. |