##// END OF EJS Templates
test-highlight: adapt output to latest pygments keeping backwards compatibility
Christian Ebert -
r8083:29ac24a3 default
parent child Browse files
Show More
@@ -1,89 +1,89 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 "$TESTDIR/hghave" pygments || exit 80
3 "$TESTDIR/hghave" pygments || exit 80
4
4
5 cat <<EOF >> $HGRCPATH
5 cat <<EOF >> $HGRCPATH
6 [extensions]
6 [extensions]
7 hgext.highlight =
7 hgext.highlight =
8 [web]
8 [web]
9 pygments_style = friendly
9 pygments_style = friendly
10 EOF
10 EOF
11
11
12 hg init test
12 hg init test
13 cd test
13 cd test
14 cp $TESTDIR/get-with-headers.py ./
14 cp $TESTDIR/get-with-headers.py ./
15
15
16 # check for UnicodeDecodeError with iso-8859-1 file contents
16 # check for UnicodeDecodeError with iso-8859-1 file contents
17 python -c 'fp = open("isolatin.txt", "w"); fp.write("h\xFCbsch\n"); fp.close();'
17 python -c 'fp = open("isolatin.txt", "w"); fp.write("h\xFCbsch\n"); fp.close();'
18
18
19 hg ci -Ama
19 hg ci -Ama
20
20
21 echo % hg serve
21 echo % hg serve
22 hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
22 hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
23 cat hg.pid >> $DAEMON_PIDS
23 cat hg.pid >> $DAEMON_PIDS
24
24
25 echo % hgweb filerevision, html
25 echo % hgweb filerevision, html
26 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \
26 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \
27 | sed "s/class=\"k\"/class=\"kn\"/g"
27 | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mf\"/class=\"mi\"/g"
28
28
29 echo % hgweb filerevision, html
29 echo % hgweb filerevision, html
30 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/isolatin.txt') \
30 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/isolatin.txt') \
31 | sed "s/class=\"k\"/class=\"kn\"/g"
31 | sed "s/class=\"k\"/class=\"kn\"/g"
32
32
33 echo % hgweb fileannotate, html
33 echo % hgweb fileannotate, html
34 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \
34 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \
35 | sed "s/class=\"k\"/class=\"kn\"/g"
35 | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mi\"/class=\"mf\"/g"
36
36
37 echo % hgweb fileannotate, raw
37 echo % hgweb fileannotate, raw
38 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py?style=raw') \
38 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py?style=raw') \
39 | sed "s/test@//" > a
39 | sed "s/test@//" > a
40
40
41 echo "200 Script output follows" > b
41 echo "200 Script output follows" > b
42 echo "" >> b
42 echo "" >> b
43 echo "" >> b
43 echo "" >> b
44 hg annotate "get-with-headers.py" >> b
44 hg annotate "get-with-headers.py" >> b
45 echo "" >> b
45 echo "" >> b
46 echo "" >> b
46 echo "" >> b
47 echo "" >> b
47 echo "" >> b
48 echo "" >> b
48 echo "" >> b
49
49
50 diff -u b a
50 diff -u b a
51
51
52 echo
52 echo
53 echo % hgweb filerevision, raw
53 echo % hgweb filerevision, raw
54 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py?style=raw') \
54 ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py?style=raw') \
55 > a
55 > a
56
56
57 echo "200 Script output follows" > b
57 echo "200 Script output follows" > b
58 echo "" >> b
58 echo "" >> b
59 hg cat get-with-headers.py >> b
59 hg cat get-with-headers.py >> b
60
60
61 diff -u b a
61 diff -u b a
62
62
63 echo
63 echo
64 echo % hgweb highlightcss friendly
64 echo % hgweb highlightcss friendly
65 "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out
65 "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out
66 head -n 4 out
66 head -n 4 out
67 rm out
67 rm out
68
68
69 echo % errors encountered
69 echo % errors encountered
70 cat errors.log
70 cat errors.log
71 "$TESTDIR/killdaemons.py"
71 "$TESTDIR/killdaemons.py"
72
72
73 # Change the pygments style
73 # Change the pygments style
74 cat > .hg/hgrc <<EOF
74 cat > .hg/hgrc <<EOF
75 [web]
75 [web]
76 pygments_style = fruity
76 pygments_style = fruity
77 EOF
77 EOF
78
78
79 echo % hg serve again
79 echo % hg serve again
80 hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
80 hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log
81 cat hg.pid >> $DAEMON_PIDS
81 cat hg.pid >> $DAEMON_PIDS
82
82
83 echo % hgweb highlightcss fruity
83 echo % hgweb highlightcss fruity
84 "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out
84 "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out
85 head -n 4 out
85 head -n 4 out
86 rm out
86 rm out
87
87
88 echo % errors encountered
88 echo % errors encountered
89 cat errors.log
89 cat errors.log
@@ -1,282 +1,282 b''
1 adding get-with-headers.py
1 adding get-with-headers.py
2 adding isolatin.txt
2 adding isolatin.txt
3 % hg serve
3 % hg serve
4 % hgweb filerevision, html
4 % hgweb filerevision, html
5 200 Script output follows
5 200 Script output follows
6
6
7 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
7 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
8 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
8 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
9 <head>
9 <head>
10 <link rel="icon" href="/static/hgicon.png" type="image/png" />
10 <link rel="icon" href="/static/hgicon.png" type="image/png" />
11 <meta name="robots" content="index, nofollow" />
11 <meta name="robots" content="index, nofollow" />
12 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
12 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
13
13
14 <link rel="stylesheet" href="/highlightcss" type="text/css" />
14 <link rel="stylesheet" href="/highlightcss" type="text/css" />
15 <title>test: 7c3facd7c58a get-with-headers.py</title>
15 <title>test: 7c3facd7c58a get-with-headers.py</title>
16 </head>
16 </head>
17 <body>
17 <body>
18
18
19 <div class="container">
19 <div class="container">
20 <div class="menu">
20 <div class="menu">
21 <div class="logo">
21 <div class="logo">
22 <a href="http://www.selenic.com/mercurial/">
22 <a href="http://www.selenic.com/mercurial/">
23 <img src="/static/hglogo.png" alt="mercurial" /></a>
23 <img src="/static/hglogo.png" alt="mercurial" /></a>
24 </div>
24 </div>
25 <ul>
25 <ul>
26 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
26 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
27 <li><a href="/graph/7c3facd7c58a">graph</a></li>
27 <li><a href="/graph/7c3facd7c58a">graph</a></li>
28 <li><a href="/tags">tags</a></li>
28 <li><a href="/tags">tags</a></li>
29 </ul>
29 </ul>
30 <ul>
30 <ul>
31 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
31 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
32 <li><a href="/file/7c3facd7c58a/">browse</a></li>
32 <li><a href="/file/7c3facd7c58a/">browse</a></li>
33 </ul>
33 </ul>
34 <ul>
34 <ul>
35 <li class="active">file</li>
35 <li class="active">file</li>
36 <li><a href="/diff/7c3facd7c58a/get-with-headers.py">diff</a></li>
36 <li><a href="/diff/7c3facd7c58a/get-with-headers.py">diff</a></li>
37 <li><a href="/annotate/7c3facd7c58a/get-with-headers.py">annotate</a></li>
37 <li><a href="/annotate/7c3facd7c58a/get-with-headers.py">annotate</a></li>
38 <li><a href="/log/7c3facd7c58a/get-with-headers.py">file log</a></li>
38 <li><a href="/log/7c3facd7c58a/get-with-headers.py">file log</a></li>
39 <li><a href="/raw-file/7c3facd7c58a/get-with-headers.py">raw</a></li>
39 <li><a href="/raw-file/7c3facd7c58a/get-with-headers.py">raw</a></li>
40 </ul>
40 </ul>
41 </div>
41 </div>
42
42
43 <div class="main">
43 <div class="main">
44 <h2><a href="/">test</a></h2>
44 <h2><a href="/">test</a></h2>
45 <h3>view get-with-headers.py @ 0:7c3facd7c58a</h3>
45 <h3>view get-with-headers.py @ 0:7c3facd7c58a</h3>
46
46
47 <form class="search" action="/log">
47 <form class="search" action="/log">
48
48
49 <p><input name="rev" id="search1" type="text" size="30" /></p>
49 <p><input name="rev" id="search1" type="text" size="30" /></p>
50 <div id="hint">find changesets by author, revision,
50 <div id="hint">find changesets by author, revision,
51 files, or words in the commit message</div>
51 files, or words in the commit message</div>
52 </form>
52 </form>
53
53
54 <div class="description">a</div>
54 <div class="description">a</div>
55
55
56 <table id="changesetEntry">
56 <table id="changesetEntry">
57 <tr>
57 <tr>
58 <th class="author">author</th>
58 <th class="author">author</th>
59 <td class="author">&#116;&#101;&#115;&#116;</td>
59 <td class="author">&#116;&#101;&#115;&#116;</td>
60 </tr>
60 </tr>
61 <tr>
61 <tr>
62 <th class="date">date</th>
62 <th class="date">date</th>
63 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
63 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
64 </tr>
64 </tr>
65 <tr>
65 <tr>
66 <th class="author">parents</th>
66 <th class="author">parents</th>
67 <td class="author"></td>
67 <td class="author"></td>
68 </tr>
68 </tr>
69 <tr>
69 <tr>
70 <th class="author">children</th>
70 <th class="author">children</th>
71 <td class="author"></td>
71 <td class="author"></td>
72 </tr>
72 </tr>
73
73
74 </table>
74 </table>
75
75
76 <div class="overflow">
76 <div class="overflow">
77 <div class="sourcefirst"> line source</div>
77 <div class="sourcefirst"> line source</div>
78 <div class="parity0 source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></div><div class="parity1 source"><a href="#l2" id="l2"> 2</a> </div><div class="parity0 source"><a href="#l3" id="l3"> 3</a> <span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></div><div class="parity1 source"><a href="#l4" id="l4"> 4</a> <span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></div><div class="parity0 source"><a href="#l5" id="l5"> 5</a> </div><div class="parity1 source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></div><div class="parity0 source"><a href="#l7" id="l7"> 7</a> </div><div class="parity1 source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></div><div class="parity0 source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></div><div class="parity1 source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity0 source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity1 source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></div><div class="parity0 source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></div><div class="parity1 source"><a href="#l14" id="l14"> 14</a> </div><div class="parity0 source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></div><div class="parity1 source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></div><div class="parity0 source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></div><div class="parity1 source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></div><div class="parity0 source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></div><div class="parity1 source"><a href="#l20" id="l20"> 20</a> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></div><div class="parity0 source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></div><div class="parity1 source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></div><div class="parity0 source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></div><div class="parity1 source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></div><div class="parity0 source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">&#39;\d+ years&#39;</span><span class="p">,</span> <span class="s">&#39;many years&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></div><div class="parity1 source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div><div class="parity0 source"><a href="#l27" id="l27"> 27</a> </div><div class="parity1 source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mf">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mf">299</span><span class="p">:</span></div><div class="parity0 source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></div><div class="parity1 source"><a href="#l30" id="l30"> 30</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span></div>
78 <div class="parity0 source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></div><div class="parity1 source"><a href="#l2" id="l2"> 2</a> </div><div class="parity0 source"><a href="#l3" id="l3"> 3</a> <span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></div><div class="parity1 source"><a href="#l4" id="l4"> 4</a> <span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></div><div class="parity0 source"><a href="#l5" id="l5"> 5</a> </div><div class="parity1 source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></div><div class="parity0 source"><a href="#l7" id="l7"> 7</a> </div><div class="parity1 source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></div><div class="parity0 source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></div><div class="parity1 source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity0 source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity1 source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></div><div class="parity0 source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></div><div class="parity1 source"><a href="#l14" id="l14"> 14</a> </div><div class="parity0 source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">3</span><span class="p">:]]</span></div><div class="parity1 source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></div><div class="parity0 source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span></div><div class="parity1 source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></div><div class="parity0 source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></div><div class="parity1 source"><a href="#l20" id="l20"> 20</a> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></div><div class="parity0 source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></div><div class="parity1 source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></div><div class="parity0 source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></div><div class="parity1 source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></div><div class="parity0 source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">&#39;\d+ years&#39;</span><span class="p">,</span> <span class="s">&#39;many years&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></div><div class="parity1 source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div><div class="parity0 source"><a href="#l27" id="l27"> 27</a> </div><div class="parity1 source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mi">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mi">299</span><span class="p">:</span></div><div class="parity0 source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div><div class="parity1 source"><a href="#l30" id="l30"> 30</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div>
79 <div class="sourcelast"></div>
79 <div class="sourcelast"></div>
80 </div>
80 </div>
81 </div>
81 </div>
82 </div>
82 </div>
83
83
84
84
85
85
86 </body>
86 </body>
87 </html>
87 </html>
88
88
89 % hgweb filerevision, html
89 % hgweb filerevision, html
90 200 Script output follows
90 200 Script output follows
91
91
92 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
92 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
93 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
93 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
94 <head>
94 <head>
95 <link rel="icon" href="/static/hgicon.png" type="image/png" />
95 <link rel="icon" href="/static/hgicon.png" type="image/png" />
96 <meta name="robots" content="index, nofollow" />
96 <meta name="robots" content="index, nofollow" />
97 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
97 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
98
98
99 <link rel="stylesheet" href="/highlightcss" type="text/css" />
99 <link rel="stylesheet" href="/highlightcss" type="text/css" />
100 <title>test: 7c3facd7c58a isolatin.txt</title>
100 <title>test: 7c3facd7c58a isolatin.txt</title>
101 </head>
101 </head>
102 <body>
102 <body>
103
103
104 <div class="container">
104 <div class="container">
105 <div class="menu">
105 <div class="menu">
106 <div class="logo">
106 <div class="logo">
107 <a href="http://www.selenic.com/mercurial/">
107 <a href="http://www.selenic.com/mercurial/">
108 <img src="/static/hglogo.png" alt="mercurial" /></a>
108 <img src="/static/hglogo.png" alt="mercurial" /></a>
109 </div>
109 </div>
110 <ul>
110 <ul>
111 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
111 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
112 <li><a href="/graph/7c3facd7c58a">graph</a></li>
112 <li><a href="/graph/7c3facd7c58a">graph</a></li>
113 <li><a href="/tags">tags</a></li>
113 <li><a href="/tags">tags</a></li>
114 </ul>
114 </ul>
115 <ul>
115 <ul>
116 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
116 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
117 <li><a href="/file/7c3facd7c58a/">browse</a></li>
117 <li><a href="/file/7c3facd7c58a/">browse</a></li>
118 </ul>
118 </ul>
119 <ul>
119 <ul>
120 <li class="active">file</li>
120 <li class="active">file</li>
121 <li><a href="/diff/7c3facd7c58a/isolatin.txt">diff</a></li>
121 <li><a href="/diff/7c3facd7c58a/isolatin.txt">diff</a></li>
122 <li><a href="/annotate/7c3facd7c58a/isolatin.txt">annotate</a></li>
122 <li><a href="/annotate/7c3facd7c58a/isolatin.txt">annotate</a></li>
123 <li><a href="/log/7c3facd7c58a/isolatin.txt">file log</a></li>
123 <li><a href="/log/7c3facd7c58a/isolatin.txt">file log</a></li>
124 <li><a href="/raw-file/7c3facd7c58a/isolatin.txt">raw</a></li>
124 <li><a href="/raw-file/7c3facd7c58a/isolatin.txt">raw</a></li>
125 </ul>
125 </ul>
126 </div>
126 </div>
127
127
128 <div class="main">
128 <div class="main">
129 <h2><a href="/">test</a></h2>
129 <h2><a href="/">test</a></h2>
130 <h3>view isolatin.txt @ 0:7c3facd7c58a</h3>
130 <h3>view isolatin.txt @ 0:7c3facd7c58a</h3>
131
131
132 <form class="search" action="/log">
132 <form class="search" action="/log">
133
133
134 <p><input name="rev" id="search1" type="text" size="30" /></p>
134 <p><input name="rev" id="search1" type="text" size="30" /></p>
135 <div id="hint">find changesets by author, revision,
135 <div id="hint">find changesets by author, revision,
136 files, or words in the commit message</div>
136 files, or words in the commit message</div>
137 </form>
137 </form>
138
138
139 <div class="description">a</div>
139 <div class="description">a</div>
140
140
141 <table id="changesetEntry">
141 <table id="changesetEntry">
142 <tr>
142 <tr>
143 <th class="author">author</th>
143 <th class="author">author</th>
144 <td class="author">&#116;&#101;&#115;&#116;</td>
144 <td class="author">&#116;&#101;&#115;&#116;</td>
145 </tr>
145 </tr>
146 <tr>
146 <tr>
147 <th class="date">date</th>
147 <th class="date">date</th>
148 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
148 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
149 </tr>
149 </tr>
150 <tr>
150 <tr>
151 <th class="author">parents</th>
151 <th class="author">parents</th>
152 <td class="author"></td>
152 <td class="author"></td>
153 </tr>
153 </tr>
154 <tr>
154 <tr>
155 <th class="author">children</th>
155 <th class="author">children</th>
156 <td class="author"></td>
156 <td class="author"></td>
157 </tr>
157 </tr>
158
158
159 </table>
159 </table>
160
160
161 <div class="overflow">
161 <div class="overflow">
162 <div class="sourcefirst"> line source</div>
162 <div class="sourcefirst"> line source</div>
163 <div class="parity0 source"><a href="#l1" id="l1"> 1</a> h?bsch</div>
163 <div class="parity0 source"><a href="#l1" id="l1"> 1</a> h?bsch</div>
164 <div class="sourcelast"></div>
164 <div class="sourcelast"></div>
165 </div>
165 </div>
166 </div>
166 </div>
167 </div>
167 </div>
168
168
169
169
170
170
171 </body>
171 </body>
172 </html>
172 </html>
173
173
174 % hgweb fileannotate, html
174 % hgweb fileannotate, html
175 200 Script output follows
175 200 Script output follows
176
176
177 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
177 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
178 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
178 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
179 <head>
179 <head>
180 <link rel="icon" href="/static/hgicon.png" type="image/png" />
180 <link rel="icon" href="/static/hgicon.png" type="image/png" />
181 <meta name="robots" content="index, nofollow" />
181 <meta name="robots" content="index, nofollow" />
182 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
182 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
183
183
184 <link rel="stylesheet" href="/highlightcss" type="text/css" />
184 <link rel="stylesheet" href="/highlightcss" type="text/css" />
185 <title>test: get-with-headers.py annotate</title>
185 <title>test: get-with-headers.py annotate</title>
186 </head>
186 </head>
187 <body>
187 <body>
188
188
189 <div class="container">
189 <div class="container">
190 <div class="menu">
190 <div class="menu">
191 <div class="logo">
191 <div class="logo">
192 <a href="http://www.selenic.com/mercurial/">
192 <a href="http://www.selenic.com/mercurial/">
193 <img src="/static/hglogo.png" alt="mercurial" /></a>
193 <img src="/static/hglogo.png" alt="mercurial" /></a>
194 </div>
194 </div>
195 <ul>
195 <ul>
196 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
196 <li><a href="/shortlog/7c3facd7c58a">log</a></li>
197 <li><a href="/graph/7c3facd7c58a">graph</a></li>
197 <li><a href="/graph/7c3facd7c58a">graph</a></li>
198 <li><a href="/tags">tags</a></li>
198 <li><a href="/tags">tags</a></li>
199 </ul>
199 </ul>
200
200
201 <ul>
201 <ul>
202 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
202 <li><a href="/rev/7c3facd7c58a">changeset</a></li>
203 <li><a href="/file/7c3facd7c58a/">browse</a></li>
203 <li><a href="/file/7c3facd7c58a/">browse</a></li>
204 </ul>
204 </ul>
205 <ul>
205 <ul>
206 <li><a href="/file/7c3facd7c58a/get-with-headers.py">file</a></li>
206 <li><a href="/file/7c3facd7c58a/get-with-headers.py">file</a></li>
207 <li><a href="/diff/7c3facd7c58a/get-with-headers.py">diff</a></li>
207 <li><a href="/diff/7c3facd7c58a/get-with-headers.py">diff</a></li>
208 <li class="active">annotate</li>
208 <li class="active">annotate</li>
209 <li><a href="/log/7c3facd7c58a/get-with-headers.py">file log</a></li>
209 <li><a href="/log/7c3facd7c58a/get-with-headers.py">file log</a></li>
210 <li><a href="/raw-annotate/7c3facd7c58a/get-with-headers.py">raw</a></li>
210 <li><a href="/raw-annotate/7c3facd7c58a/get-with-headers.py">raw</a></li>
211 </ul>
211 </ul>
212 </div>
212 </div>
213
213
214 <div class="main">
214 <div class="main">
215 <h2><a href="/">test</a></h2>
215 <h2><a href="/">test</a></h2>
216 <h3>annotate get-with-headers.py @ 0:7c3facd7c58a</h3>
216 <h3>annotate get-with-headers.py @ 0:7c3facd7c58a</h3>
217
217
218 <form class="search" action="/log">
218 <form class="search" action="/log">
219
219
220 <p><input name="rev" id="search1" type="text" size="30" /></p>
220 <p><input name="rev" id="search1" type="text" size="30" /></p>
221 <div id="hint">find changesets by author, revision,
221 <div id="hint">find changesets by author, revision,
222 files, or words in the commit message</div>
222 files, or words in the commit message</div>
223 </form>
223 </form>
224
224
225 <div class="description">a</div>
225 <div class="description">a</div>
226
226
227 <table id="changesetEntry">
227 <table id="changesetEntry">
228 <tr>
228 <tr>
229 <th class="author">author</th>
229 <th class="author">author</th>
230 <td class="author">&#116;&#101;&#115;&#116;</td>
230 <td class="author">&#116;&#101;&#115;&#116;</td>
231 </tr>
231 </tr>
232 <tr>
232 <tr>
233 <th class="date">date</th>
233 <th class="date">date</th>
234 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
234 <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td>
235 </tr>
235 </tr>
236 <tr>
236 <tr>
237 <th class="author">parents</th>
237 <th class="author">parents</th>
238 <td class="author"></td>
238 <td class="author"></td>
239 </tr>
239 </tr>
240 <tr>
240 <tr>
241 <th class="author">children</th>
241 <th class="author">children</th>
242 <td class="author"></td>
242 <td class="author"></td>
243 </tr>
243 </tr>
244
244
245 </table>
245 </table>
246
246
247 <br/>
247 <br/>
248
248
249 <div class="overflow">
249 <div class="overflow">
250 <table class="bigtable">
250 <table class="bigtable">
251 <tr>
251 <tr>
252 <th class="annotate">rev</th>
252 <th class="annotate">rev</th>
253 <th class="line">&nbsp;&nbsp;line source</th>
253 <th class="line">&nbsp;&nbsp;line source</th>
254 </tr>
254 </tr>
255 <tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#1" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#2" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l2" id="l2"> 2</a> </td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#3" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l3" id="l3"> 3</a> <span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#4" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l4" id="l4"> 4</a> <span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#5" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l5" id="l5"> 5</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#6" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#7" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l7" id="l7"> 7</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#8" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#9" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#10" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#11" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#12" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#13" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#14" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l14" id="l14"> 14</a> </td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#15" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#16" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#17" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#18" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#19" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#20" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l20" id="l20"> 20</a> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#21" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#22" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#23" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#24" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#25" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">&#39;\d+ years&#39;</span><span class="p">,</span> <span class="s">&#39;many years&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#26" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#27" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l27" id="l27"> 27</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#28" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mf">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mf">299</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#29" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#30" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l30" id="l30"> 30</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span></td></tr>
255 <tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#1" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#2" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l2" id="l2"> 2</a> </td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#3" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l3" id="l3"> 3</a> <span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;This does HTTP get requests given a host:port and path and returns</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#4" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l4" id="l4"> 4</a> <span class="s">a subset of the headers plus the body of the result.&quot;&quot;&quot;</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#5" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l5" id="l5"> 5</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#6" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#7" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l7" id="l7"> 7</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#8" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#9" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#10" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#11" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#12" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#13" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#14" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l14" id="l14"> 14</a> </td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#15" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#16" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#17" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">&quot;GET&quot;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#18" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#19" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#20" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l20" id="l20"> 20</a> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#21" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#22" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#23" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#24" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#25" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">&#39;\d+ years&#39;</span><span class="p">,</span> <span class="s">&#39;many years&#39;</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#26" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#27" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l27" id="l27"> 27</a> </td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#28" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mf">200</span> <span class="o">&lt;=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o">&lt;=</span> <span class="mf">299</span><span class="p">:</span></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#29" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/7c3facd7c58a/get-with-headers.py#30" title="7c3facd7c58a: a">test@0</a></td><td class="source"><a href="#l30" id="l30"> 30</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span></td></tr>
256 </table>
256 </table>
257 </div>
257 </div>
258 </div>
258 </div>
259 </div>
259 </div>
260
260
261
261
262
262
263 </body>
263 </body>
264 </html>
264 </html>
265
265
266 % hgweb fileannotate, raw
266 % hgweb fileannotate, raw
267
267
268 % hgweb filerevision, raw
268 % hgweb filerevision, raw
269
269
270 % hgweb highlightcss friendly
270 % hgweb highlightcss friendly
271 200 Script output follows
271 200 Script output follows
272
272
273 /* pygments_style = friendly */
273 /* pygments_style = friendly */
274
274
275 % errors encountered
275 % errors encountered
276 % hg serve again
276 % hg serve again
277 % hgweb highlightcss fruity
277 % hgweb highlightcss fruity
278 200 Script output follows
278 200 Script output follows
279
279
280 /* pygments_style = fruity */
280 /* pygments_style = fruity */
281
281
282 % errors encountered
282 % errors encountered
General Comments 0
You need to be logged in to leave comments. Login now