Show More
@@ -1,29 +1,29 | |||||
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 | EOF |
|
8 | EOF | |
9 |
|
9 | |||
10 | hg init test |
|
10 | hg init test | |
11 | cd test |
|
11 | cd test | |
12 | cp $TESTDIR/get-with-headers.py ./ |
|
12 | cp $TESTDIR/get-with-headers.py ./ | |
13 | hg ci -Ama |
|
13 | hg ci -Ama | |
14 |
|
14 | |||
15 | echo % hg serve |
|
15 | echo % hg serve | |
16 | hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
16 | hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log | |
17 | cat hg.pid >> $DAEMON_PIDS |
|
17 | cat hg.pid >> $DAEMON_PIDS | |
18 |
|
18 | |||
19 | echo % hgweb filerevision |
|
19 | echo % hgweb filerevision | |
20 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \ |
|
20 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \ | |
21 | | sed "s/[0-9]* years ago/long ago/g" |
|
21 | | sed "s/[0-9]* years ago/long ago/g" | sed "s/class=\"k\"/class=\"kn\"/g" | |
22 |
|
22 | |||
23 | echo % hgweb fileannotate |
|
23 | echo % hgweb fileannotate | |
24 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \ |
|
24 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \ | |
25 | | sed "s/[0-9]* years ago/long ago/g" |
|
25 | | sed "s/[0-9]* years ago/long ago/g" | sed "s/class=\"k\"/class=\"kn\"/g" | |
26 |
|
26 | |||
27 | echo % errors encountered |
|
27 | echo % errors encountered | |
28 | cat errors.log |
|
28 | cat errors.log | |
29 |
|
29 |
@@ -1,129 +1,129 | |||||
1 | adding get-with-headers.py |
|
1 | adding get-with-headers.py | |
2 | % hg serve |
|
2 | % hg serve | |
3 | % hgweb filerevision |
|
3 | % hgweb filerevision | |
4 | 200 Script output follows |
|
4 | 200 Script output follows | |
5 |
|
5 | |||
6 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
6 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
7 | <html> |
|
7 | <html> | |
8 | <head> |
|
8 | <head> | |
9 | <link rel="icon" href="/static/hgicon.png" type="image/png"> |
|
9 | <link rel="icon" href="/static/hgicon.png" type="image/png"> | |
10 | <meta name="robots" content="index, nofollow" /> |
|
10 | <meta name="robots" content="index, nofollow" /> | |
11 | <link rel="stylesheet" href="/static/style.css" type="text/css" /> |
|
11 | <link rel="stylesheet" href="/static/style.css" type="text/css" /> | |
12 |
|
12 | |||
13 | <link rel="stylesheet" href="/static/highlight.css" type="text/css" /> |
|
13 | <link rel="stylesheet" href="/static/highlight.css" type="text/css" /> | |
14 | <title>test:get-with-headers.py</title> |
|
14 | <title>test:get-with-headers.py</title> | |
15 | </head> |
|
15 | </head> | |
16 | <body> |
|
16 | <body> | |
17 |
|
17 | |||
18 | <div class="buttons"> |
|
18 | <div class="buttons"> | |
19 | <a href="/log/0">changelog</a> |
|
19 | <a href="/log/0">changelog</a> | |
20 | <a href="/shortlog/0">shortlog</a> |
|
20 | <a href="/shortlog/0">shortlog</a> | |
21 | <a href="/tags">tags</a> |
|
21 | <a href="/tags">tags</a> | |
22 | <a href="/rev/79ee608ca36d">changeset</a> |
|
22 | <a href="/rev/79ee608ca36d">changeset</a> | |
23 | <a href="/file/79ee608ca36d/">files</a> |
|
23 | <a href="/file/79ee608ca36d/">files</a> | |
24 | <a href="/log/79ee608ca36d/get-with-headers.py">revisions</a> |
|
24 | <a href="/log/79ee608ca36d/get-with-headers.py">revisions</a> | |
25 | <a href="/annotate/79ee608ca36d/get-with-headers.py">annotate</a> |
|
25 | <a href="/annotate/79ee608ca36d/get-with-headers.py">annotate</a> | |
26 | <a href="/raw-file/79ee608ca36d/get-with-headers.py">raw</a> |
|
26 | <a href="/raw-file/79ee608ca36d/get-with-headers.py">raw</a> | |
27 | </div> |
|
27 | </div> | |
28 |
|
28 | |||
29 | <h2>get-with-headers.py</h2> |
|
29 | <h2>get-with-headers.py</h2> | |
30 |
|
30 | |||
31 | <table> |
|
31 | <table> | |
32 | <tr> |
|
32 | <tr> | |
33 | <td class="metatag">changeset 0:</td> |
|
33 | <td class="metatag">changeset 0:</td> | |
34 | <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr> |
|
34 | <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr> | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | <tr> |
|
37 | <tr> | |
38 | <td class="metatag">author:</td> |
|
38 | <td class="metatag">author:</td> | |
39 | <td>test</td></tr> |
|
39 | <td>test</td></tr> | |
40 | <tr> |
|
40 | <tr> | |
41 | <td class="metatag">date:</td> |
|
41 | <td class="metatag">date:</td> | |
42 | <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr> |
|
42 | <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr> | |
43 | <tr> |
|
43 | <tr> | |
44 | <td class="metatag">permissions:</td> |
|
44 | <td class="metatag">permissions:</td> | |
45 | <td>-rwxr-xr-x</td></tr> |
|
45 | <td>-rwxr-xr-x</td></tr> | |
46 | <tr> |
|
46 | <tr> | |
47 | <td class="metatag">description:</td> |
|
47 | <td class="metatag">description:</td> | |
48 | <td>a</td> |
|
48 | <td>a</td> | |
49 | </tr> |
|
49 | </tr> | |
50 | </table> |
|
50 | </table> | |
51 |
|
51 | |||
52 | <pre> |
|
52 | <pre> | |
53 | <div class="parity0"><a class="lineno" href="#l1" id="l1"> 1</a><span class="c">#!/usr/bin/env python</span></div><div class="parity1"><a class="lineno" href="#l2" id="l2"> 2</a></div><div class="parity0"><a class="lineno" href="#l3" id="l3"> 3</a><span class="n">__doc__</span> <span class="o">=</span> <span class="s">"""This does HTTP get requests given a host:port and path and returns</span></div><div class="parity1"><a class="lineno" href="#l4" id="l4"> 4</a><span class="s">a subset of the headers plus the body of the result."""</span></div><div class="parity0"><a class="lineno" href="#l5" id="l5"> 5</a></div><div class="parity1"><a class="lineno" href="#l6" id="l6"> 6</a><span class="k">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span></div><div class="parity0"><a class="lineno" href="#l7" id="l7"> 7</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="k">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"><a class="lineno" href="#l8" id="l8"> 8</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"><a class="lineno" href="#l9" id="l9"> 9</a><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</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"><a class="lineno" href="#l10" id="l10"> 10</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"><a class="lineno" href="#l11" id="l11"> 11</a><span class="k">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"><a class="lineno" href="#l12" id="l12"> 12</a><span class="k">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"><a class="lineno" href="#l13" id="l13"> 13</a> <span class="k">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"><a class="lineno" href="#l14" id="l14"> 14</a> <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</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"><a class="lineno" href="#l15" id="l15"> 15</a><span class="k">print</span></div><div class="parity1"><a class="lineno" href="#l16" id="l16"> 16</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">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></div><div class="parity0"><a class="lineno" href="#l17" id="l17"> 17</a></div><div class="parity1"><a class="lineno" href="#l18" id="l18"> 18</a><span class="k">if</span> <span class="mf">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mf">299</span><span class="p">:</span></div><div class="parity0"><a class="lineno" href="#l19" id="l19"> 19</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"><a class="lineno" href="#l20" id="l20"> 20</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> |
|
53 | <div class="parity0"><a class="lineno" href="#l1" id="l1"> 1</a><span class="c">#!/usr/bin/env python</span></div><div class="parity1"><a class="lineno" href="#l2" id="l2"> 2</a></div><div class="parity0"><a class="lineno" href="#l3" id="l3"> 3</a><span class="n">__doc__</span> <span class="o">=</span> <span class="s">"""This does HTTP get requests given a host:port and path and returns</span></div><div class="parity1"><a class="lineno" href="#l4" id="l4"> 4</a><span class="s">a subset of the headers plus the body of the result."""</span></div><div class="parity0"><a class="lineno" href="#l5" id="l5"> 5</a></div><div class="parity1"><a class="lineno" 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></div><div class="parity0"><a class="lineno" href="#l7" id="l7"> 7</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"><a class="lineno" href="#l8" id="l8"> 8</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"><a class="lineno" href="#l9" id="l9"> 9</a><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</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"><a class="lineno" href="#l10" id="l10"> 10</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"><a class="lineno" href="#l11" id="l11"> 11</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"><a class="lineno" href="#l12" id="l12"> 12</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"><a class="lineno" href="#l13" id="l13"> 13</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"><a class="lineno" href="#l14" id="l14"> 14</a> <span class="kn">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</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"><a class="lineno" href="#l15" id="l15"> 15</a><span class="kn">print</span></div><div class="parity1"><a class="lineno" href="#l16" id="l16"> 16</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">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></div><div class="parity0"><a class="lineno" href="#l17" id="l17"> 17</a></div><div class="parity1"><a class="lineno" href="#l18" id="l18"> 18</a><span class="kn">if</span> <span class="mf">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mf">299</span><span class="p">:</span></div><div class="parity0"><a class="lineno" href="#l19" id="l19"> 19</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"><a class="lineno" href="#l20" id="l20"> 20</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> | |
54 | </pre> |
|
54 | </pre> | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | <div class="logo"> |
|
57 | <div class="logo"> | |
58 | <a href="http://www.selenic.com/mercurial/"> |
|
58 | <a href="http://www.selenic.com/mercurial/"> | |
59 | <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a> |
|
59 | <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a> | |
60 | </div> |
|
60 | </div> | |
61 |
|
61 | |||
62 | </body> |
|
62 | </body> | |
63 | </html> |
|
63 | </html> | |
64 |
|
64 | |||
65 | % hgweb fileannotate |
|
65 | % hgweb fileannotate | |
66 | 200 Script output follows |
|
66 | 200 Script output follows | |
67 |
|
67 | |||
68 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
68 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
69 | <html> |
|
69 | <html> | |
70 | <head> |
|
70 | <head> | |
71 | <link rel="icon" href="/static/hgicon.png" type="image/png"> |
|
71 | <link rel="icon" href="/static/hgicon.png" type="image/png"> | |
72 | <meta name="robots" content="index, nofollow" /> |
|
72 | <meta name="robots" content="index, nofollow" /> | |
73 | <link rel="stylesheet" href="/static/style.css" type="text/css" /> |
|
73 | <link rel="stylesheet" href="/static/style.css" type="text/css" /> | |
74 |
|
74 | |||
75 | <link rel="stylesheet" href="/static/highlight.css" type="text/css" /> |
|
75 | <link rel="stylesheet" href="/static/highlight.css" type="text/css" /> | |
76 | <title>test: get-with-headers.py annotate</title> |
|
76 | <title>test: get-with-headers.py annotate</title> | |
77 | </head> |
|
77 | </head> | |
78 | <body> |
|
78 | <body> | |
79 |
|
79 | |||
80 | <div class="buttons"> |
|
80 | <div class="buttons"> | |
81 | <a href="/log/0">changelog</a> |
|
81 | <a href="/log/0">changelog</a> | |
82 | <a href="/shortlog/0">shortlog</a> |
|
82 | <a href="/shortlog/0">shortlog</a> | |
83 | <a href="/tags">tags</a> |
|
83 | <a href="/tags">tags</a> | |
84 | <a href="/rev/79ee608ca36d">changeset</a> |
|
84 | <a href="/rev/79ee608ca36d">changeset</a> | |
85 | <a href="/file/79ee608ca36d/">files</a> |
|
85 | <a href="/file/79ee608ca36d/">files</a> | |
86 | <a href="/file/79ee608ca36d/get-with-headers.py">file</a> |
|
86 | <a href="/file/79ee608ca36d/get-with-headers.py">file</a> | |
87 | <a href="/log/79ee608ca36d/get-with-headers.py">revisions</a> |
|
87 | <a href="/log/79ee608ca36d/get-with-headers.py">revisions</a> | |
88 | <a href="/raw-annotate/79ee608ca36d/get-with-headers.py">raw</a> |
|
88 | <a href="/raw-annotate/79ee608ca36d/get-with-headers.py">raw</a> | |
89 | </div> |
|
89 | </div> | |
90 |
|
90 | |||
91 | <h2>Annotate get-with-headers.py</h2> |
|
91 | <h2>Annotate get-with-headers.py</h2> | |
92 |
|
92 | |||
93 | <table> |
|
93 | <table> | |
94 | <tr> |
|
94 | <tr> | |
95 | <td class="metatag">changeset 0:</td> |
|
95 | <td class="metatag">changeset 0:</td> | |
96 | <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr> |
|
96 | <td><a href="/rev/79ee608ca36d">79ee608ca36d</a></td></tr> | |
97 |
|
97 | |||
98 |
|
98 | |||
99 | <tr> |
|
99 | <tr> | |
100 | <td class="metatag">author:</td> |
|
100 | <td class="metatag">author:</td> | |
101 | <td>test</td></tr> |
|
101 | <td>test</td></tr> | |
102 | <tr> |
|
102 | <tr> | |
103 | <td class="metatag">date:</td> |
|
103 | <td class="metatag">date:</td> | |
104 | <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr> |
|
104 | <td>Thu Jan 01 00:00:00 1970 +0000 (long ago)</td></tr> | |
105 | <tr> |
|
105 | <tr> | |
106 | <td class="metatag">permissions:</td> |
|
106 | <td class="metatag">permissions:</td> | |
107 | <td>-rwxr-xr-x</td></tr> |
|
107 | <td>-rwxr-xr-x</td></tr> | |
108 | <tr> |
|
108 | <tr> | |
109 | <td class="metatag">description:</td> |
|
109 | <td class="metatag">description:</td> | |
110 | <td>a</td> |
|
110 | <td>a</td> | |
111 | </tr> |
|
111 | </tr> | |
112 | </table> |
|
112 | </table> | |
113 |
|
113 | |||
114 | <br/> |
|
114 | <br/> | |
115 |
|
115 | |||
116 | <table cellspacing="0" cellpadding="0"> |
|
116 | <table cellspacing="0" cellpadding="0"> | |
117 | <tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l1">test@0</a></td><td><a class="lineno" href="#l1" id="l1"> 1</a></td><td><pre><span class="c">#!/usr/bin/env python</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l2">test@0</a></td><td><a class="lineno" href="#l2" id="l2"> 2</a></td><td><pre></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l3">test@0</a></td><td><a class="lineno" href="#l3" id="l3"> 3</a></td><td><pre><span class="n">__doc__</span> <span class="o">=</span> <span class="s">"""This does HTTP get requests given a host:port and path and returns</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l4">test@0</a></td><td><a class="lineno" href="#l4" id="l4"> 4</a></td><td><pre><span class="s">a subset of the headers plus the body of the result."""</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l5">test@0</a></td><td><a class="lineno" href="#l5" id="l5"> 5</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l6">test@0</a></td><td><a class="lineno" href="#l6" id="l6"> 6</a></td><td><pre><span class="k">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l7">test@0</a></td><td><a class="lineno" href="#l7" id="l7"> 7</a></td><td><pre><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="k">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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l8">test@0</a></td><td><a class="lineno" href="#l8" id="l8"> 8</a></td><td><pre><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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l9">test@0</a></td><td><a class="lineno" href="#l9" id="l9"> 9</a></td><td><pre><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l10">test@0</a></td><td><a class="lineno" href="#l10" id="l10"> 10</a></td><td><pre><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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l11">test@0</a></td><td><a class="lineno" href="#l11" id="l11"> 11</a></td><td><pre><span class="k">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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l12">test@0</a></td><td><a class="lineno" href="#l12" id="l12"> 12</a></td><td><pre><span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l13">test@0</a></td><td><a class="lineno" href="#l13" id="l13"> 13</a></td><td><pre> <span class="k">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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l14">test@0</a></td><td><a class="lineno" href="#l14" id="l14"> 14</a></td><td><pre> <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l15">test@0</a></td><td><a class="lineno" href="#l15" id="l15"> 15</a></td><td><pre><span class="k">print</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l16">test@0</a></td><td><a class="lineno" href="#l16" id="l16"> 16</a></td><td><pre><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">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l17">test@0</a></td><td><a class="lineno" href="#l17" id="l17"> 17</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l18">test@0</a></td><td><a class="lineno" href="#l18" id="l18"> 18</a></td><td><pre><span class="k">if</span> <span class="mf">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mf">299</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l19">test@0</a></td><td><a class="lineno" href="#l19" id="l19"> 19</a></td><td><pre> <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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l20">test@0</a></td><td><a class="lineno" href="#l20" id="l20"> 20</a></td><td><pre><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></pre></td></tr> |
|
117 | <tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l1">test@0</a></td><td><a class="lineno" href="#l1" id="l1"> 1</a></td><td><pre><span class="c">#!/usr/bin/env python</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l2">test@0</a></td><td><a class="lineno" href="#l2" id="l2"> 2</a></td><td><pre></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l3">test@0</a></td><td><a class="lineno" href="#l3" id="l3"> 3</a></td><td><pre><span class="n">__doc__</span> <span class="o">=</span> <span class="s">"""This does HTTP get requests given a host:port and path and returns</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l4">test@0</a></td><td><a class="lineno" href="#l4" id="l4"> 4</a></td><td><pre><span class="s">a subset of the headers plus the body of the result."""</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l5">test@0</a></td><td><a class="lineno" href="#l5" id="l5"> 5</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l6">test@0</a></td><td><a class="lineno" href="#l6" id="l6"> 6</a></td><td><pre><span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l7">test@0</a></td><td><a class="lineno" href="#l7" id="l7"> 7</a></td><td><pre><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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l8">test@0</a></td><td><a class="lineno" href="#l8" id="l8"> 8</a></td><td><pre><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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l9">test@0</a></td><td><a class="lineno" href="#l9" id="l9"> 9</a></td><td><pre><span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l10">test@0</a></td><td><a class="lineno" href="#l10" id="l10"> 10</a></td><td><pre><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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l11">test@0</a></td><td><a class="lineno" href="#l11" id="l11"> 11</a></td><td><pre><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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l12">test@0</a></td><td><a class="lineno" href="#l12" id="l12"> 12</a></td><td><pre><span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l13">test@0</a></td><td><a class="lineno" href="#l13" id="l13"> 13</a></td><td><pre> <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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l14">test@0</a></td><td><a class="lineno" href="#l14" id="l14"> 14</a></td><td><pre> <span class="kn">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</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></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l15">test@0</a></td><td><a class="lineno" href="#l15" id="l15"> 15</a></td><td><pre><span class="kn">print</span></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l16">test@0</a></td><td><a class="lineno" href="#l16" id="l16"> 16</a></td><td><pre><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">response</span><span class="o">.</span><span class="n">read</span><span class="p">())</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l17">test@0</a></td><td><a class="lineno" href="#l17" id="l17"> 17</a></td><td><pre></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l18">test@0</a></td><td><a class="lineno" href="#l18" id="l18"> 18</a></td><td><pre><span class="kn">if</span> <span class="mf">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mf">299</span><span class="p">:</span></pre></td></tr><tr class="parity0"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l19">test@0</a></td><td><a class="lineno" href="#l19" id="l19"> 19</a></td><td><pre> <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></pre></td></tr><tr class="parity1"><td class="annotate"><a href="/annotate/79ee608ca36d/get-with-headers.py#l20">test@0</a></td><td><a class="lineno" href="#l20" id="l20"> 20</a></td><td><pre><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></pre></td></tr> | |
118 | </table> |
|
118 | </table> | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | <div class="logo"> |
|
121 | <div class="logo"> | |
122 | <a href="http://www.selenic.com/mercurial/"> |
|
122 | <a href="http://www.selenic.com/mercurial/"> | |
123 | <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a> |
|
123 | <img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a> | |
124 | </div> |
|
124 | </div> | |
125 |
|
125 | |||
126 | </body> |
|
126 | </body> | |
127 | </html> |
|
127 | </html> | |
128 |
|
128 | |||
129 | % errors encountered |
|
129 | % errors encountered |
General Comments 0
You need to be logged in to leave comments.
Login now