Show More
@@ -1,30 +1,30 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 |
|
|
|
3 | """This does HTTP GET requests given a host:port and path and returns | |
|
4 | 4 |
|
|
5 | 5 | |
|
6 | 6 | import httplib, sys, re |
|
7 | 7 | |
|
8 | 8 | try: |
|
9 | 9 | import msvcrt, os |
|
10 | 10 | msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
11 | 11 | msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
|
12 | 12 | except ImportError: |
|
13 | 13 | pass |
|
14 | 14 | |
|
15 | 15 | headers = [h.lower() for h in sys.argv[3:]] |
|
16 | 16 | conn = httplib.HTTPConnection(sys.argv[1]) |
|
17 | 17 | conn.request("GET", sys.argv[2]) |
|
18 | 18 | response = conn.getresponse() |
|
19 | 19 | print response.status, response.reason |
|
20 | 20 | for h in headers: |
|
21 | 21 | if response.getheader(h, None) is not None: |
|
22 | 22 | print "%s: %s" % (h, response.getheader(h)) |
|
23 | 23 | |
|
24 | 24 | data = response.read() |
|
25 | 25 | data = re.sub('\d+ years', 'many years', data) |
|
26 | 26 | sys.stdout.write(data) |
|
27 | 27 | |
|
28 | 28 | if 200 <= response.status <= 299: |
|
29 | 29 | sys.exit(0) |
|
30 | 30 | sys.exit(1) |
@@ -1,495 +1,495 b'' | |||
|
1 | 1 | adding get-with-headers.py |
|
2 | 2 | adding isolatin.txt |
|
3 | 3 | % hg serve |
|
4 | 4 | % hgweb filerevision, html |
|
5 | 5 | 200 Script output follows |
|
6 | 6 | |
|
7 | 7 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
8 | 8 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
9 | 9 | <head> |
|
10 | 10 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
11 | 11 | <meta name="robots" content="index, nofollow" /> |
|
12 | 12 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
13 | 13 | |
|
14 | 14 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
15 |
<title>test: |
|
|
15 | <title>test: 93b701795893 get-with-headers.py</title> | |
|
16 | 16 | </head> |
|
17 | 17 | <body> |
|
18 | 18 | |
|
19 | 19 | <div class="container"> |
|
20 | 20 | <div class="menu"> |
|
21 | 21 | <div class="logo"> |
|
22 | 22 | <a href="http://www.selenic.com/mercurial/"> |
|
23 | 23 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
24 | 24 | </div> |
|
25 | 25 | <ul> |
|
26 |
<li><a href="/shortlog/ |
|
|
27 |
<li><a href="/graph/ |
|
|
26 | <li><a href="/shortlog/93b701795893">log</a></li> | |
|
27 | <li><a href="/graph/93b701795893">graph</a></li> | |
|
28 | 28 | <li><a href="/tags">tags</a></li> |
|
29 | 29 | <li><a href="/branches">branches</a></li> |
|
30 | 30 | </ul> |
|
31 | 31 | <ul> |
|
32 |
<li><a href="/rev/ |
|
|
33 |
<li><a href="/file/ |
|
|
32 | <li><a href="/rev/93b701795893">changeset</a></li> | |
|
33 | <li><a href="/file/93b701795893/">browse</a></li> | |
|
34 | 34 | </ul> |
|
35 | 35 | <ul> |
|
36 | 36 | <li class="active">file</li> |
|
37 |
<li><a href="/diff/ |
|
|
38 |
<li><a href="/annotate/ |
|
|
39 |
<li><a href="/log/ |
|
|
40 |
<li><a href="/raw-file/ |
|
|
37 | <li><a href="/diff/93b701795893/get-with-headers.py">diff</a></li> | |
|
38 | <li><a href="/annotate/93b701795893/get-with-headers.py">annotate</a></li> | |
|
39 | <li><a href="/log/93b701795893/get-with-headers.py">file log</a></li> | |
|
40 | <li><a href="/raw-file/93b701795893/get-with-headers.py">raw</a></li> | |
|
41 | 41 | </ul> |
|
42 | 42 | </div> |
|
43 | 43 | |
|
44 | 44 | <div class="main"> |
|
45 | 45 | <h2><a href="/">test</a></h2> |
|
46 |
<h3>view get-with-headers.py @ 0: |
|
|
46 | <h3>view get-with-headers.py @ 0:93b701795893</h3> | |
|
47 | 47 | |
|
48 | 48 | <form class="search" action="/log"> |
|
49 | 49 | |
|
50 | 50 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
51 | 51 | <div id="hint">find changesets by author, revision, |
|
52 | 52 | files, or words in the commit message</div> |
|
53 | 53 | </form> |
|
54 | 54 | |
|
55 | 55 | <div class="description">a</div> |
|
56 | 56 | |
|
57 | 57 | <table id="changesetEntry"> |
|
58 | 58 | <tr> |
|
59 | 59 | <th class="author">author</th> |
|
60 | 60 | <td class="author">test</td> |
|
61 | 61 | </tr> |
|
62 | 62 | <tr> |
|
63 | 63 | <th class="date">date</th> |
|
64 | 64 | <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td> |
|
65 | 65 | </tr> |
|
66 | 66 | <tr> |
|
67 | 67 | <th class="author">parents</th> |
|
68 | 68 | <td class="author"></td> |
|
69 | 69 | </tr> |
|
70 | 70 | <tr> |
|
71 | 71 | <th class="author">children</th> |
|
72 | 72 | <td class="author"></td> |
|
73 | 73 | </tr> |
|
74 | 74 | |
|
75 | 75 | </table> |
|
76 | 76 | |
|
77 | 77 | <div class="overflow"> |
|
78 | 78 | <div class="sourcefirst"> line source</div> |
|
79 |
<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=" |
|
|
79 | <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="sd">"""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="sd">a subset of the headers plus the body of the result."""</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">"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="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">"</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 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">'\d+ years'</span><span class="p">,</span> <span class="s">'many years'</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"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</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> | |
|
80 | 80 | <div class="sourcelast"></div> |
|
81 | 81 | </div> |
|
82 | 82 | </div> |
|
83 | 83 | </div> |
|
84 | 84 | |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | </body> |
|
88 | 88 | </html> |
|
89 | 89 | |
|
90 | 90 | % hgweb filerevision, html |
|
91 | 91 | 200 Script output follows |
|
92 | 92 | |
|
93 | 93 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
94 | 94 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
95 | 95 | <head> |
|
96 | 96 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
97 | 97 | <meta name="robots" content="index, nofollow" /> |
|
98 | 98 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
99 | 99 | |
|
100 | 100 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
101 |
<title>test: |
|
|
101 | <title>test: 93b701795893 isolatin.txt</title> | |
|
102 | 102 | </head> |
|
103 | 103 | <body> |
|
104 | 104 | |
|
105 | 105 | <div class="container"> |
|
106 | 106 | <div class="menu"> |
|
107 | 107 | <div class="logo"> |
|
108 | 108 | <a href="http://www.selenic.com/mercurial/"> |
|
109 | 109 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
110 | 110 | </div> |
|
111 | 111 | <ul> |
|
112 |
<li><a href="/shortlog/ |
|
|
113 |
<li><a href="/graph/ |
|
|
112 | <li><a href="/shortlog/93b701795893">log</a></li> | |
|
113 | <li><a href="/graph/93b701795893">graph</a></li> | |
|
114 | 114 | <li><a href="/tags">tags</a></li> |
|
115 | 115 | <li><a href="/branches">branches</a></li> |
|
116 | 116 | </ul> |
|
117 | 117 | <ul> |
|
118 |
<li><a href="/rev/ |
|
|
119 |
<li><a href="/file/ |
|
|
118 | <li><a href="/rev/93b701795893">changeset</a></li> | |
|
119 | <li><a href="/file/93b701795893/">browse</a></li> | |
|
120 | 120 | </ul> |
|
121 | 121 | <ul> |
|
122 | 122 | <li class="active">file</li> |
|
123 |
<li><a href="/diff/ |
|
|
124 |
<li><a href="/annotate/ |
|
|
125 |
<li><a href="/log/ |
|
|
126 |
<li><a href="/raw-file/ |
|
|
123 | <li><a href="/diff/93b701795893/isolatin.txt">diff</a></li> | |
|
124 | <li><a href="/annotate/93b701795893/isolatin.txt">annotate</a></li> | |
|
125 | <li><a href="/log/93b701795893/isolatin.txt">file log</a></li> | |
|
126 | <li><a href="/raw-file/93b701795893/isolatin.txt">raw</a></li> | |
|
127 | 127 | </ul> |
|
128 | 128 | </div> |
|
129 | 129 | |
|
130 | 130 | <div class="main"> |
|
131 | 131 | <h2><a href="/">test</a></h2> |
|
132 |
<h3>view isolatin.txt @ 0: |
|
|
132 | <h3>view isolatin.txt @ 0:93b701795893</h3> | |
|
133 | 133 | |
|
134 | 134 | <form class="search" action="/log"> |
|
135 | 135 | |
|
136 | 136 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
137 | 137 | <div id="hint">find changesets by author, revision, |
|
138 | 138 | files, or words in the commit message</div> |
|
139 | 139 | </form> |
|
140 | 140 | |
|
141 | 141 | <div class="description">a</div> |
|
142 | 142 | |
|
143 | 143 | <table id="changesetEntry"> |
|
144 | 144 | <tr> |
|
145 | 145 | <th class="author">author</th> |
|
146 | 146 | <td class="author">test</td> |
|
147 | 147 | </tr> |
|
148 | 148 | <tr> |
|
149 | 149 | <th class="date">date</th> |
|
150 | 150 | <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td> |
|
151 | 151 | </tr> |
|
152 | 152 | <tr> |
|
153 | 153 | <th class="author">parents</th> |
|
154 | 154 | <td class="author"></td> |
|
155 | 155 | </tr> |
|
156 | 156 | <tr> |
|
157 | 157 | <th class="author">children</th> |
|
158 | 158 | <td class="author"></td> |
|
159 | 159 | </tr> |
|
160 | 160 | |
|
161 | 161 | </table> |
|
162 | 162 | |
|
163 | 163 | <div class="overflow"> |
|
164 | 164 | <div class="sourcefirst"> line source</div> |
|
165 | 165 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> h?bsch</div> |
|
166 | 166 | <div class="sourcelast"></div> |
|
167 | 167 | </div> |
|
168 | 168 | </div> |
|
169 | 169 | </div> |
|
170 | 170 | |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | </body> |
|
174 | 174 | </html> |
|
175 | 175 | |
|
176 | 176 | % hgweb fileannotate, html |
|
177 | 177 | 200 Script output follows |
|
178 | 178 | |
|
179 | 179 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
180 | 180 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
181 | 181 | <head> |
|
182 | 182 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
183 | 183 | <meta name="robots" content="index, nofollow" /> |
|
184 | 184 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
185 | 185 | |
|
186 | 186 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
187 | 187 | <title>test: get-with-headers.py annotate</title> |
|
188 | 188 | </head> |
|
189 | 189 | <body> |
|
190 | 190 | |
|
191 | 191 | <div class="container"> |
|
192 | 192 | <div class="menu"> |
|
193 | 193 | <div class="logo"> |
|
194 | 194 | <a href="http://www.selenic.com/mercurial/"> |
|
195 | 195 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
196 | 196 | </div> |
|
197 | 197 | <ul> |
|
198 |
<li><a href="/shortlog/ |
|
|
199 |
<li><a href="/graph/ |
|
|
198 | <li><a href="/shortlog/93b701795893">log</a></li> | |
|
199 | <li><a href="/graph/93b701795893">graph</a></li> | |
|
200 | 200 | <li><a href="/tags">tags</a></li> |
|
201 | 201 | <li><a href="/branches">branches</a></li> |
|
202 | 202 | </ul> |
|
203 | 203 | |
|
204 | 204 | <ul> |
|
205 |
<li><a href="/rev/ |
|
|
206 |
<li><a href="/file/ |
|
|
205 | <li><a href="/rev/93b701795893">changeset</a></li> | |
|
206 | <li><a href="/file/93b701795893/">browse</a></li> | |
|
207 | 207 | </ul> |
|
208 | 208 | <ul> |
|
209 |
<li><a href="/file/ |
|
|
210 |
<li><a href="/diff/ |
|
|
209 | <li><a href="/file/93b701795893/get-with-headers.py">file</a></li> | |
|
210 | <li><a href="/diff/93b701795893/get-with-headers.py">diff</a></li> | |
|
211 | 211 | <li class="active">annotate</li> |
|
212 |
<li><a href="/log/ |
|
|
213 |
<li><a href="/raw-annotate/ |
|
|
212 | <li><a href="/log/93b701795893/get-with-headers.py">file log</a></li> | |
|
213 | <li><a href="/raw-annotate/93b701795893/get-with-headers.py">raw</a></li> | |
|
214 | 214 | </ul> |
|
215 | 215 | </div> |
|
216 | 216 | |
|
217 | 217 | <div class="main"> |
|
218 | 218 | <h2><a href="/">test</a></h2> |
|
219 |
<h3>annotate get-with-headers.py @ 0: |
|
|
219 | <h3>annotate get-with-headers.py @ 0:93b701795893</h3> | |
|
220 | 220 | |
|
221 | 221 | <form class="search" action="/log"> |
|
222 | 222 | |
|
223 | 223 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
224 | 224 | <div id="hint">find changesets by author, revision, |
|
225 | 225 | files, or words in the commit message</div> |
|
226 | 226 | </form> |
|
227 | 227 | |
|
228 | 228 | <div class="description">a</div> |
|
229 | 229 | |
|
230 | 230 | <table id="changesetEntry"> |
|
231 | 231 | <tr> |
|
232 | 232 | <th class="author">author</th> |
|
233 | 233 | <td class="author">test</td> |
|
234 | 234 | </tr> |
|
235 | 235 | <tr> |
|
236 | 236 | <th class="date">date</th> |
|
237 | 237 | <td class="date">Thu Jan 01 00:00:00 1970 +0000 (many years ago)</td> |
|
238 | 238 | </tr> |
|
239 | 239 | <tr> |
|
240 | 240 | <th class="author">parents</th> |
|
241 | 241 | <td class="author"></td> |
|
242 | 242 | </tr> |
|
243 | 243 | <tr> |
|
244 | 244 | <th class="author">children</th> |
|
245 | 245 | <td class="author"></td> |
|
246 | 246 | </tr> |
|
247 | 247 | |
|
248 | 248 | </table> |
|
249 | 249 | |
|
250 | 250 | <br/> |
|
251 | 251 | |
|
252 | 252 | <div class="overflow"> |
|
253 | 253 | <table class="bigtable"> |
|
254 | 254 | <tr> |
|
255 | 255 | <th class="annotate">rev</th> |
|
256 | 256 | <th class="line"> line source</th> |
|
257 | 257 | </tr> |
|
258 | 258 | |
|
259 | 259 | <tr class="parity0"> |
|
260 | 260 | <td class="annotate"> |
|
261 |
<a href="/annotate/ |
|
|
262 |
title=" |
|
|
261 | <a href="/annotate/93b701795893/get-with-headers.py#1" | |
|
262 | title="93b701795893: a">test@0</a> | |
|
263 | 263 | </td> |
|
264 | 264 | <td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> |
|
265 | 265 | </tr> |
|
266 | 266 | <tr class="parity1"> |
|
267 | 267 | <td class="annotate"> |
|
268 |
<a href="/annotate/ |
|
|
269 |
title=" |
|
|
268 | <a href="/annotate/93b701795893/get-with-headers.py#2" | |
|
269 | title="93b701795893: a">test@0</a> | |
|
270 | 270 | </td> |
|
271 | 271 | <td class="source"><a href="#l2" id="l2"> 2</a> </td> |
|
272 | 272 | </tr> |
|
273 | 273 | <tr class="parity0"> |
|
274 | 274 | <td class="annotate"> |
|
275 |
<a href="/annotate/ |
|
|
276 |
title=" |
|
|
275 | <a href="/annotate/93b701795893/get-with-headers.py#3" | |
|
276 | title="93b701795893: a">test@0</a> | |
|
277 | 277 | </td> |
|
278 |
<td class="source"><a href="#l3" id="l3"> 3</a> <span class=" |
|
|
278 | <td class="source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""This does HTTP GET requests given a host:port and path and returns</span></td> | |
|
279 | 279 | </tr> |
|
280 | 280 | <tr class="parity1"> |
|
281 | 281 | <td class="annotate"> |
|
282 |
<a href="/annotate/ |
|
|
283 |
title=" |
|
|
282 | <a href="/annotate/93b701795893/get-with-headers.py#4" | |
|
283 | title="93b701795893: a">test@0</a> | |
|
284 | 284 | </td> |
|
285 | <td class="source"><a href="#l4" id="l4"> 4</a> <span class="s">a subset of the headers plus the body of the result."""</span></td> | |
|
285 | <td class="source"><a href="#l4" id="l4"> 4</a> <span class="sd">a subset of the headers plus the body of the result."""</span></td> | |
|
286 | 286 | </tr> |
|
287 | 287 | <tr class="parity0"> |
|
288 | 288 | <td class="annotate"> |
|
289 |
<a href="/annotate/ |
|
|
290 |
title=" |
|
|
289 | <a href="/annotate/93b701795893/get-with-headers.py#5" | |
|
290 | title="93b701795893: a">test@0</a> | |
|
291 | 291 | </td> |
|
292 | 292 | <td class="source"><a href="#l5" id="l5"> 5</a> </td> |
|
293 | 293 | </tr> |
|
294 | 294 | <tr class="parity1"> |
|
295 | 295 | <td class="annotate"> |
|
296 |
<a href="/annotate/ |
|
|
297 |
title=" |
|
|
296 | <a href="/annotate/93b701795893/get-with-headers.py#6" | |
|
297 | title="93b701795893: a">test@0</a> | |
|
298 | 298 | </td> |
|
299 | 299 | <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> |
|
300 | 300 | </tr> |
|
301 | 301 | <tr class="parity0"> |
|
302 | 302 | <td class="annotate"> |
|
303 |
<a href="/annotate/ |
|
|
304 |
title=" |
|
|
303 | <a href="/annotate/93b701795893/get-with-headers.py#7" | |
|
304 | title="93b701795893: a">test@0</a> | |
|
305 | 305 | </td> |
|
306 | 306 | <td class="source"><a href="#l7" id="l7"> 7</a> </td> |
|
307 | 307 | </tr> |
|
308 | 308 | <tr class="parity1"> |
|
309 | 309 | <td class="annotate"> |
|
310 |
<a href="/annotate/ |
|
|
311 |
title=" |
|
|
310 | <a href="/annotate/93b701795893/get-with-headers.py#8" | |
|
311 | title="93b701795893: a">test@0</a> | |
|
312 | 312 | </td> |
|
313 | 313 | <td class="source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></td> |
|
314 | 314 | </tr> |
|
315 | 315 | <tr class="parity0"> |
|
316 | 316 | <td class="annotate"> |
|
317 |
<a href="/annotate/ |
|
|
318 |
title=" |
|
|
317 | <a href="/annotate/93b701795893/get-with-headers.py#9" | |
|
318 | title="93b701795893: a">test@0</a> | |
|
319 | 319 | </td> |
|
320 | 320 | <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> |
|
321 | 321 | </tr> |
|
322 | 322 | <tr class="parity1"> |
|
323 | 323 | <td class="annotate"> |
|
324 |
<a href="/annotate/ |
|
|
325 |
title=" |
|
|
324 | <a href="/annotate/93b701795893/get-with-headers.py#10" | |
|
325 | title="93b701795893: a">test@0</a> | |
|
326 | 326 | </td> |
|
327 | 327 | <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> |
|
328 | 328 | </tr> |
|
329 | 329 | <tr class="parity0"> |
|
330 | 330 | <td class="annotate"> |
|
331 |
<a href="/annotate/ |
|
|
332 |
title=" |
|
|
331 | <a href="/annotate/93b701795893/get-with-headers.py#11" | |
|
332 | title="93b701795893: a">test@0</a> | |
|
333 | 333 | </td> |
|
334 | 334 | <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> |
|
335 | 335 | </tr> |
|
336 | 336 | <tr class="parity1"> |
|
337 | 337 | <td class="annotate"> |
|
338 |
<a href="/annotate/ |
|
|
339 |
title=" |
|
|
338 | <a href="/annotate/93b701795893/get-with-headers.py#12" | |
|
339 | title="93b701795893: a">test@0</a> | |
|
340 | 340 | </td> |
|
341 | 341 | <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> |
|
342 | 342 | </tr> |
|
343 | 343 | <tr class="parity0"> |
|
344 | 344 | <td class="annotate"> |
|
345 |
<a href="/annotate/ |
|
|
346 |
title=" |
|
|
345 | <a href="/annotate/93b701795893/get-with-headers.py#13" | |
|
346 | title="93b701795893: a">test@0</a> | |
|
347 | 347 | </td> |
|
348 | 348 | <td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></td> |
|
349 | 349 | </tr> |
|
350 | 350 | <tr class="parity1"> |
|
351 | 351 | <td class="annotate"> |
|
352 |
<a href="/annotate/ |
|
|
353 |
title=" |
|
|
352 | <a href="/annotate/93b701795893/get-with-headers.py#14" | |
|
353 | title="93b701795893: a">test@0</a> | |
|
354 | 354 | </td> |
|
355 | 355 | <td class="source"><a href="#l14" id="l14"> 14</a> </td> |
|
356 | 356 | </tr> |
|
357 | 357 | <tr class="parity0"> |
|
358 | 358 | <td class="annotate"> |
|
359 |
<a href="/annotate/ |
|
|
360 |
title=" |
|
|
359 | <a href="/annotate/93b701795893/get-with-headers.py#15" | |
|
360 | title="93b701795893: a">test@0</a> | |
|
361 | 361 | </td> |
|
362 | 362 | <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> |
|
363 | 363 | </tr> |
|
364 | 364 | <tr class="parity1"> |
|
365 | 365 | <td class="annotate"> |
|
366 |
<a href="/annotate/ |
|
|
367 |
title=" |
|
|
366 | <a href="/annotate/93b701795893/get-with-headers.py#16" | |
|
367 | title="93b701795893: a">test@0</a> | |
|
368 | 368 | </td> |
|
369 | 369 | <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> |
|
370 | 370 | </tr> |
|
371 | 371 | <tr class="parity0"> |
|
372 | 372 | <td class="annotate"> |
|
373 |
<a href="/annotate/ |
|
|
374 |
title=" |
|
|
373 | <a href="/annotate/93b701795893/get-with-headers.py#17" | |
|
374 | title="93b701795893: a">test@0</a> | |
|
375 | 375 | </td> |
|
376 | 376 | <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">"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></td> |
|
377 | 377 | </tr> |
|
378 | 378 | <tr class="parity1"> |
|
379 | 379 | <td class="annotate"> |
|
380 |
<a href="/annotate/ |
|
|
381 |
title=" |
|
|
380 | <a href="/annotate/93b701795893/get-with-headers.py#18" | |
|
381 | title="93b701795893: a">test@0</a> | |
|
382 | 382 | </td> |
|
383 | 383 | <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> |
|
384 | 384 | </tr> |
|
385 | 385 | <tr class="parity0"> |
|
386 | 386 | <td class="annotate"> |
|
387 |
<a href="/annotate/ |
|
|
388 |
title=" |
|
|
387 | <a href="/annotate/93b701795893/get-with-headers.py#19" | |
|
388 | title="93b701795893: a">test@0</a> | |
|
389 | 389 | </td> |
|
390 | 390 | <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> |
|
391 | 391 | </tr> |
|
392 | 392 | <tr class="parity1"> |
|
393 | 393 | <td class="annotate"> |
|
394 |
<a href="/annotate/ |
|
|
395 |
title=" |
|
|
394 | <a href="/annotate/93b701795893/get-with-headers.py#20" | |
|
395 | title="93b701795893: a">test@0</a> | |
|
396 | 396 | </td> |
|
397 | 397 | <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> |
|
398 | 398 | </tr> |
|
399 | 399 | <tr class="parity0"> |
|
400 | 400 | <td class="annotate"> |
|
401 |
<a href="/annotate/ |
|
|
402 |
title=" |
|
|
401 | <a href="/annotate/93b701795893/get-with-headers.py#21" | |
|
402 | title="93b701795893: a">test@0</a> | |
|
403 | 403 | </td> |
|
404 | 404 | <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> |
|
405 | 405 | </tr> |
|
406 | 406 | <tr class="parity1"> |
|
407 | 407 | <td class="annotate"> |
|
408 |
<a href="/annotate/ |
|
|
409 |
title=" |
|
|
408 | <a href="/annotate/93b701795893/get-with-headers.py#22" | |
|
409 | title="93b701795893: a">test@0</a> | |
|
410 | 410 | </td> |
|
411 | 411 | <td class="source"><a href="#l22" id="l22"> 22</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></td> |
|
412 | 412 | </tr> |
|
413 | 413 | <tr class="parity0"> |
|
414 | 414 | <td class="annotate"> |
|
415 |
<a href="/annotate/ |
|
|
416 |
title=" |
|
|
415 | <a href="/annotate/93b701795893/get-with-headers.py#23" | |
|
416 | title="93b701795893: a">test@0</a> | |
|
417 | 417 | </td> |
|
418 | 418 | <td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></td> |
|
419 | 419 | </tr> |
|
420 | 420 | <tr class="parity1"> |
|
421 | 421 | <td class="annotate"> |
|
422 |
<a href="/annotate/ |
|
|
423 |
title=" |
|
|
422 | <a href="/annotate/93b701795893/get-with-headers.py#24" | |
|
423 | title="93b701795893: a">test@0</a> | |
|
424 | 424 | </td> |
|
425 | 425 | <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> |
|
426 | 426 | </tr> |
|
427 | 427 | <tr class="parity0"> |
|
428 | 428 | <td class="annotate"> |
|
429 |
<a href="/annotate/ |
|
|
430 |
title=" |
|
|
429 | <a href="/annotate/93b701795893/get-with-headers.py#25" | |
|
430 | title="93b701795893: a">test@0</a> | |
|
431 | 431 | </td> |
|
432 | 432 | <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">'\d+ years'</span><span class="p">,</span> <span class="s">'many years'</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></td> |
|
433 | 433 | </tr> |
|
434 | 434 | <tr class="parity1"> |
|
435 | 435 | <td class="annotate"> |
|
436 |
<a href="/annotate/ |
|
|
437 |
title=" |
|
|
436 | <a href="/annotate/93b701795893/get-with-headers.py#26" | |
|
437 | title="93b701795893: a">test@0</a> | |
|
438 | 438 | </td> |
|
439 | 439 | <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> |
|
440 | 440 | </tr> |
|
441 | 441 | <tr class="parity0"> |
|
442 | 442 | <td class="annotate"> |
|
443 |
<a href="/annotate/ |
|
|
444 |
title=" |
|
|
443 | <a href="/annotate/93b701795893/get-with-headers.py#27" | |
|
444 | title="93b701795893: a">test@0</a> | |
|
445 | 445 | </td> |
|
446 | 446 | <td class="source"><a href="#l27" id="l27"> 27</a> </td> |
|
447 | 447 | </tr> |
|
448 | 448 | <tr class="parity1"> |
|
449 | 449 | <td class="annotate"> |
|
450 |
<a href="/annotate/ |
|
|
451 |
title=" |
|
|
450 | <a href="/annotate/93b701795893/get-with-headers.py#28" | |
|
451 | title="93b701795893: a">test@0</a> | |
|
452 | 452 | </td> |
|
453 | 453 | <td class="source"><a href="#l28" id="l28"> 28</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></td> |
|
454 | 454 | </tr> |
|
455 | 455 | <tr class="parity0"> |
|
456 | 456 | <td class="annotate"> |
|
457 |
<a href="/annotate/ |
|
|
458 |
title=" |
|
|
457 | <a href="/annotate/93b701795893/get-with-headers.py#29" | |
|
458 | title="93b701795893: a">test@0</a> | |
|
459 | 459 | </td> |
|
460 | 460 | <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> |
|
461 | 461 | </tr> |
|
462 | 462 | <tr class="parity1"> |
|
463 | 463 | <td class="annotate"> |
|
464 |
<a href="/annotate/ |
|
|
465 |
title=" |
|
|
464 | <a href="/annotate/93b701795893/get-with-headers.py#30" | |
|
465 | title="93b701795893: a">test@0</a> | |
|
466 | 466 | </td> |
|
467 | 467 | <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> |
|
468 | 468 | </tr> |
|
469 | 469 | </table> |
|
470 | 470 | </div> |
|
471 | 471 | </div> |
|
472 | 472 | </div> |
|
473 | 473 | |
|
474 | 474 | |
|
475 | 475 | |
|
476 | 476 | </body> |
|
477 | 477 | </html> |
|
478 | 478 | |
|
479 | 479 | % hgweb fileannotate, raw |
|
480 | 480 | |
|
481 | 481 | % hgweb filerevision, raw |
|
482 | 482 | |
|
483 | 483 | % hgweb highlightcss friendly |
|
484 | 484 | 200 Script output follows |
|
485 | 485 | |
|
486 | 486 | /* pygments_style = friendly */ |
|
487 | 487 | |
|
488 | 488 | % errors encountered |
|
489 | 489 | % hg serve again |
|
490 | 490 | % hgweb highlightcss fruity |
|
491 | 491 | 200 Script output follows |
|
492 | 492 | |
|
493 | 493 | /* pygments_style = fruity */ |
|
494 | 494 | |
|
495 | 495 | % errors encountered |
General Comments 0
You need to be logged in to leave comments.
Login now