FrontPage 

TB Wiki

Login

Regression Test

Expected HTML for page "DocWebSed"


expected html
nothing
t1 t
2<table align="right"><tr><td><div class="toc">
3Contents:
4<ul>
5  <li><a href="#Introduction">Introduction</a></li>
6  <li><a href="#Processor_Syntax">Processor&nbsp;Syntax</a></li>
7  <li><a href="#WebSed_configuration_specification">WebSed&nbsp;configuration&nbsp;specification</a></li>
8  <ul>
9    <li><a href="#source_line">source&nbsp;line</a></li>
10    <li><a href="#match_specification">match&nbsp;specification</a></li>
11    <ul>
12      <li><a href="#match_expressions">match&nbsp;expressions</a></li>
13      <li><a href="#end_patterns">end&nbsp;patterns</a></li>
14      <li><a href="#precursors_and_the_websed_parsing_state_machine">precursors&nbsp;and&nbsp;the&nbsp;websed&nbsp;parsing&nbsp;state&nbsp;machine</a></li>
15      <li><a href="#Anonymous_sequences">Anonymous&nbsp;sequences</a></li>
16    </ul>
17    <li><a href="#format_specification">format&nbsp;specification</a></li>
18  </ul>
19  <li><a href="#Examples">Examples</a></li>
20</ul>
21</div></td></tr></table>
22<p>
23<h1><a name="Introduction">Introduction</a>
24<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=Introduction">edit section</a>]</font></span>
25</h1>
26WebSed is a tbwiki processor for extracting information from other pages or
27web sites, and using that as part of tbwiki output.
28<p>
29<h1><a name="Processor_Syntax">Processor Syntax</a>
30<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=Processor_Syntax">edit section</a>]</font></span>
31</h1>
32The WebSed processor uses the contents of the processor block to find
33external data, and to assign names to individual pieces of data.  Also,
34the processor block has text which this data can be placed into.
35<p>
36The processor block starts with the processor name and has the internal parts:
37<ul><li>a line indicating the source
38<li>a match specification (one or more regular expression statements)
39<li>a delimiter (always "---")
40<li>a format specification, which is the output text, containing data references
41</ul>
42<p>
43Here's an example:
44<pre>
45{{{#!WebSed
46http ://testlab.celinuxforum.org:8000/files/UserTimTestWebsed.html
47phone=^phone\s*=\s*(.*)
48---
49Tim's phone number is %%(phone)s
50</pre>
51}}}
52<p>
53Assuming that the file UserTimTestWebsed.html had the contents:
54<pre>
55   foo bar
56   phone=123-4567
57   baz baf
58</pre>
59This this example would print out the text:
60<p>
61<pre>
62   Tim's phone number is 123-4567
63</pre>
64<p>
65In this example, the html file is read from the indicated web site, and
66the lines are examined, looking for "phone=&lt;something&gt;"
67<p>
68That "&lt;something&gt;" is assigned to the websed variable 'phone'.
69<p>
70This variable can be placed in the block output for this processor block,
71as indicated.
72<p>
73<h1><a name="WebSed_configuration_specification">WebSed configuration specification</a>
74<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=WebSed_configuration_specification">edit section</a>]</font></span>
75</h1>
76<pre>
77{{{#WebSed
78&lt;source&gt;
79&lt;match_spec&gt;
80---
81&lt;format_spec&gt;
82</pre>
83}}}
84<p>
85<h2><a name="source_line">source line</a>
86<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=source_line">edit section</a>]</font></span>
87</h2>
88The "source" line can refer to a page in this wiki or an external web page.
89If the reference starts with an exclamation point, it refers to a page
90in this wiki.  ie !FrontPage
91<p>
92if the name includes '<a href="http:'">http:'</a> or '<a href="https:',">https:',</a> then the page is assumed to
93be an external page3, and it is opened with Python's url library.
94<p>
95Otherwise, the reference is presumed to be an internal page, but it is
96still opened with Python's url library, using a path relative to this
97wiki.
98<p>
99The URL should be of the form: name:password@<a href="http://domain/dir/file?params">http://domain/dir/file?params</a>
100<p>
101<h2><a name="match_specification">match specification</a>
102<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=match_specification">edit section</a>]</font></span>
103</h2>
104A match specification has lines describing the method to parse the source
105data, and to assign values to named websed variables.
106<p>
107The specification can be one or more match expressions, each on it's own line.
108The simplest specification is a single match expression consisting
109of one variable and one regular expression (with one group).
110<p>
111Possible lines:
112<ul><li>&lt;var&gt;=&lt;regex&gt;
113<li>&lt;var&gt;_endpat=&lt;regex&gt;
114<li>&lt;var&gt;_precursors=&lt;var list&gt;
115<li>search_space_start=&lt;regex&gt;
116<li>search_space_end=&lt;regex&gt;
117<li>linear
118<li>=&lt;regex&gt;    (anonymous sequence)
119</ul>
120<p>
121Any line starting with '#' is considered a comment and is ignored by the
122websed engine.
123<p>
124All regular expressions use python "re" syntax.  See the <a href="http://docs.python.org/library/re.html">Python re library documentation</a> for details.
125<p>
126Note that WebSed uses the "search" method when matching. Regular expression patterns may match anywhere on the line, not just at the beginning of the line.
127<p>
128<h3><a name="match_expressions">match expressions</a>
129<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=match_expressions">edit section</a>]</font></span>
130</h3>
131Match expressions indicates a variable name and a regular expression to
132match, in order to provide a value for that variable.
133<p>
134Match expressions are of the form "&lt;variable_name&gt;=&lt;regular expression&gt;"
135<p>
136The regular expression should include a group (an expression inside parenthesis).  The text that matches this group is used at the value for the variable.
137<p>
138Each line in the source data is compared with the right-hand side of the
139match expression (the regular expression), and if a match is found, the
140sub-expression which matches the first group is saved as the value for the variable named in the left-hand size of the match expression.
141<p>
142Example:
143<p>
144user=name:\s*(.*)
145<p>
146Will match a line with the string "name:" in it, and assign the everything
147past the whitespace (if any) following the colon to the websed variable "user".
148<p>
149<h3><a name="end_patterns">end patterns</a>
150<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=end_patterns">edit section</a>]</font></span>
151</h3>
152Most of the time, a match expression will provide a single value (from
153the group in the regular expression) for a match variable.  However, you
154can also copy a set of lines from the source data, using a match expression
155and an associated "end pattern match expression".
156<p>
157To specify an end pattern, suffix the name of the variable with "_endpat"
158in the match expression.
159<p>
160The collecting of data will start when the match expression is matched, and collecting of data will stop when the _endpat match expression
161is matched.
162<p>
163For example:
164<p>
165<pre>
166   foo=^BEGIN()
167   foo_endpat=^END()
168</pre>
169<p>
170Will collect all the lines BETWEEN the lines in the source that start with
171"BEGIN" and "END".  Note that the pattern expression must still have a group,
172even though the group is empty.  The group is not currently used (but may be in
173the future to support multi-line blocks starting or ending in the middle of a line).
174<p>
175<h3><a name="precursors_and_the_websed_parsing_state_machine">precursors and the websed parsing state machine</a>
176<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=precursors_and_the_websed_parsing_state_machine">edit section</a>]</font></span>
177</h3>
178The match specification allows for the description of a complex state machine,
179which allows the regular expression to match only in certain contexts.
180It is not, however, a full context sensitive parser.
181<p>
182For a given variable, it is possible to define a list of precursors,
183which are variables which must be matched before a pattern
184can match the first variable.
185<p>
186This means that a complex state machine can be specified for parsing
187the variables values from the source data.
188<p>
189For example, if I'm scanning for the word "foo" in the text, then
190I scan specify that I must first see matches for "cat" and "bar" first.
191<p>
192<pre>
193  cat=black (cat)
194  bar=(the) bar
195  foo=foo is (.*)[.]
196  foo_precursors=bar,cat
197</pre>
198<p>
199In the above example, the following text would trigger the the matching of foo:
200<pre>
201  I thought I saw a black cat
202  in the bar.
203  The value of foo is ufo.
204</pre>
205Note that value of 'foo' would be "ufo", but would only be assigned if
206both cat and bar were seen.  They do not have to be matched in any order.
207If a specific order of matching is required for 'cat' and 'bar', then
208a precursor can be used on those as well (e.g. bar_precursor=cat)
209<p>
210Notice that 'cat' would have the value "cat", while "bar" would have the value
211"the".
212<p>
213If the word 'linear' appears on a line by itself, it indicates that the
214search expressions preceding it must be matched in the order given
215in match spec.
216<p>
217For example, if I listed three search expressions, foo, bar, and baz.
218then the 'baz' expression would not match until both the foo and bar
219expressions had matched (in that order).
220<p>
221<h3><a name="Anonymous_sequences">Anonymous sequences</a>
222<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=Anonymous_sequences">edit section</a>]</font></span>
223</h3>
224If a match line starts with '=' (that is, the variable name is missing in
225the match expressions), then the match specifies an "anonymous sequence".
226<p>
227An anonymous sequence can be used to match several data items on a single line.
228<p>
229If used, a match spec may contain only one anonymous sequence, and the
230format string should use string format specifiers instead of named format
231variables.
232<p>
233For example, the following could be used to reword the sentence:
234<p>
235<pre>
236{{{#!WebSed
237=the (\w*) bike was (\w*)
238---
239I believe that the %s bicycle might have been %s.
240</pre>
241}}}
242<p>
243<h2><a name="format_specification">format specification</a>
244<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=format_specification">edit section</a>]</font></span>
245</h2>
246The format specification has the text to return for this block.
247Usually, this will include references to matched items parsed from the source.
248<p>
249&lt;format_spec&gt; can be empty, in which case a list of any variables found are
250printed with their names (if any) separated by spaces.
251<p>
252<p>
253<b>NOTE that variables in the format specification have to use double-percents
254in their declarations, like so:
255<p>
256<ul><div style="background-color:#ffffe0; padding:5px; border-style: solid solid solid solid; border-width: 1px 1px 1px 1px;">
257<pre>%%(var_name)s</pre></div></ul>
258 
259<p>
260<h1><a name="Examples">Examples</a>
261<span align=right class="section_edit_link">[<a href="/tbwiki/DocWebSed?action=edit&section=Examples">edit section</a>]</font></span>
262</h1>
263See <a style="color:red;" href="/tbwiki/TestWebSedProcessor">TestWebSedProcessor</a> for examples uses of this processor
264<p>
265</b>
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Differences for page "DocWebSed"


expected html
generated html
t No Differences Found t No Differences Found 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Update saved output

Back to diff page

Return to Regression_Test page
TBWiki engine 1.9.3 by Tim Bird