Show More
@@ -1,604 +1,605 b'' | |||
|
1 | 1 | |
|
2 | 2 | $ "$TESTDIR/hghave" pygments || exit 80 |
|
3 | 3 | $ cat <<EOF >> $HGRCPATH |
|
4 | 4 | > [extensions] |
|
5 | 5 | > highlight = |
|
6 | 6 | > [web] |
|
7 | 7 | > pygments_style = friendly |
|
8 | 8 | > EOF |
|
9 | 9 | $ hg init test |
|
10 | 10 | $ cd test |
|
11 | 11 | |
|
12 | 12 | create random Python file to exercise Pygments |
|
13 | 13 | |
|
14 | 14 | $ cat <<EOF > primes.py |
|
15 | 15 | > #!/usr/bin/env python |
|
16 | 16 | > |
|
17 | 17 | > """Fun with generators. Corresponding Haskell implementation: |
|
18 | 18 | > |
|
19 | 19 | > primes = 2 : sieve [3, 5..] |
|
20 | 20 | > where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] |
|
21 | 21 | > """ |
|
22 | 22 | > |
|
23 | 23 | > from itertools import dropwhile, ifilter, islice, count, chain |
|
24 | 24 | > |
|
25 | 25 | > def primes(): |
|
26 | 26 | > """Generate all primes.""" |
|
27 | 27 | > def sieve(ns): |
|
28 | 28 | > p = ns.next() |
|
29 | 29 | > # It is important to yield *here* in order to stop the |
|
30 | 30 | > # infinite recursion. |
|
31 | 31 | > yield p |
|
32 | 32 | > ns = ifilter(lambda n: n % p != 0, ns) |
|
33 | 33 | > for n in sieve(ns): |
|
34 | 34 | > yield n |
|
35 | 35 | > |
|
36 | 36 | > odds = ifilter(lambda i: i % 2 == 1, count()) |
|
37 | 37 | > return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) |
|
38 | 38 | > |
|
39 | 39 | > if __name__ == "__main__": |
|
40 | 40 | > import sys |
|
41 | 41 | > try: |
|
42 | 42 | > n = int(sys.argv[1]) |
|
43 | 43 | > except (ValueError, IndexError): |
|
44 | 44 | > n = 10 |
|
45 | 45 | > p = primes() |
|
46 | 46 | > print "The first %d primes: %s" % (n, list(islice(p, n))) |
|
47 | 47 | > EOF |
|
48 | 48 | $ hg ci -Ama |
|
49 | 49 | adding primes.py |
|
50 | 50 | |
|
51 | 51 | hg serve |
|
52 | 52 | |
|
53 | 53 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
54 | 54 | $ cat hg.pid >> $DAEMON_PIDS |
|
55 | 55 | |
|
56 | 56 | hgweb filerevision, html |
|
57 | 57 | |
|
58 | 58 | $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py') \ |
|
59 | 59 | > | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mf\"/class=\"mi\"/g" |
|
60 | 60 | 200 Script output follows |
|
61 | 61 | |
|
62 | 62 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
63 | 63 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
64 | 64 | <head> |
|
65 | 65 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
66 | 66 | <meta name="robots" content="index, nofollow" /> |
|
67 | 67 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
68 | 68 | |
|
69 | 69 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
70 | 70 | <title>test: 853dcd4de2a6 primes.py</title> |
|
71 | 71 | </head> |
|
72 | 72 | <body> |
|
73 | 73 | |
|
74 | 74 | <div class="container"> |
|
75 | 75 | <div class="menu"> |
|
76 | 76 | <div class="logo"> |
|
77 | 77 | <a href="http://mercurial.selenic.com/"> |
|
78 | 78 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
79 | 79 | </div> |
|
80 | 80 | <ul> |
|
81 | 81 | <li><a href="/shortlog/853dcd4de2a6">log</a></li> |
|
82 | 82 | <li><a href="/graph/853dcd4de2a6">graph</a></li> |
|
83 | 83 | <li><a href="/tags">tags</a></li> |
|
84 | 84 | <li><a href="/branches">branches</a></li> |
|
85 | 85 | </ul> |
|
86 | 86 | <ul> |
|
87 | 87 | <li><a href="/rev/853dcd4de2a6">changeset</a></li> |
|
88 | 88 | <li><a href="/file/853dcd4de2a6/">browse</a></li> |
|
89 | 89 | </ul> |
|
90 | 90 | <ul> |
|
91 | 91 | <li class="active">file</li> |
|
92 | 92 | <li><a href="/file/tip/primes.py">latest</a></li> |
|
93 | 93 | <li><a href="/diff/853dcd4de2a6/primes.py">diff</a></li> |
|
94 | 94 | <li><a href="/annotate/853dcd4de2a6/primes.py">annotate</a></li> |
|
95 | 95 | <li><a href="/log/853dcd4de2a6/primes.py">file log</a></li> |
|
96 | 96 | <li><a href="/raw-file/853dcd4de2a6/primes.py">raw</a></li> |
|
97 | 97 | </ul> |
|
98 | 98 | <ul> |
|
99 | 99 | <li><a href="/help">help</a></li> |
|
100 | 100 | </ul> |
|
101 | 101 | </div> |
|
102 | 102 | |
|
103 | 103 | <div class="main"> |
|
104 | 104 | <h2><a href="/">test</a></h2> |
|
105 | 105 | <h3>view primes.py @ 0:853dcd4de2a6</h3> |
|
106 | 106 | |
|
107 | 107 | <form class="search" action="/log"> |
|
108 | 108 | |
|
109 | 109 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
110 | 110 | <div id="hint">find changesets by author, revision, |
|
111 | 111 | files, or words in the commit message</div> |
|
112 | 112 | </form> |
|
113 | 113 | |
|
114 | 114 | <div class="description">a</div> |
|
115 | 115 | |
|
116 | 116 | <table id="changesetEntry"> |
|
117 | 117 | <tr> |
|
118 | 118 | <th class="author">author</th> |
|
119 | 119 | <td class="author">test</td> |
|
120 | 120 | </tr> |
|
121 | 121 | <tr> |
|
122 | 122 | <th class="date">date</th> |
|
123 | 123 | <td class="date">Thu Jan 01 00:00:00 1970 +0000 (1970-01-01)</td> |
|
124 | 124 | </tr> |
|
125 | 125 | <tr> |
|
126 | 126 | <th class="author">parents</th> |
|
127 | 127 | <td class="author"></td> |
|
128 | 128 | </tr> |
|
129 | 129 | <tr> |
|
130 | 130 | <th class="author">children</th> |
|
131 | 131 | <td class="author"></td> |
|
132 | 132 | </tr> |
|
133 | 133 | |
|
134 | 134 | </table> |
|
135 | 135 | |
|
136 | 136 | <div class="overflow"> |
|
137 | 137 | <div class="sourcefirst"> line source</div> |
|
138 | 138 | |
|
139 | 139 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></div> |
|
140 | 140 | <div class="parity1 source"><a href="#l2" id="l2"> 2</a> </div> |
|
141 | 141 | <div class="parity0 source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></div> |
|
142 | 142 | <div class="parity1 source"><a href="#l4" id="l4"> 4</a> </div> |
|
143 | 143 | <div class="parity0 source"><a href="#l5" id="l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></div> |
|
144 | 144 | <div class="parity1 source"><a href="#l6" id="l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></div> |
|
145 | 145 | <div class="parity0 source"><a href="#l7" id="l7"> 7</a> <span class="sd">"""</span></div> |
|
146 | 146 | <div class="parity1 source"><a href="#l8" id="l8"> 8</a> </div> |
|
147 | 147 | <div class="parity0 source"><a href="#l9" id="l9"> 9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></div> |
|
148 | 148 | <div class="parity1 source"><a href="#l10" id="l10"> 10</a> </div> |
|
149 | 149 | <div class="parity0 source"><a href="#l11" id="l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></div> |
|
150 | 150 | <div class="parity1 source"><a href="#l12" id="l12"> 12</a> <span class="sd">"""Generate all primes."""</span></div> |
|
151 | 151 | <div class="parity0 source"><a href="#l13" id="l13"> 13</a> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></div> |
|
152 | 152 | <div class="parity1 source"><a href="#l14" id="l14"> 14</a> <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></div> |
|
153 | 153 | <div class="parity0 source"><a href="#l15" id="l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></div> |
|
154 | 154 | <div class="parity1 source"><a href="#l16" id="l16"> 16</a> <span class="c"># infinite recursion.</span></div> |
|
155 | 155 | <div class="parity0 source"><a href="#l17" id="l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></div> |
|
156 | 156 | <div class="parity1 source"><a href="#l18" id="l18"> 18</a> <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></div> |
|
157 | 157 | <div class="parity0 source"><a href="#l19" id="l19"> 19</a> <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></div> |
|
158 | 158 | <div class="parity1 source"><a href="#l20" id="l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></div> |
|
159 | 159 | <div class="parity0 source"><a href="#l21" id="l21"> 21</a> </div> |
|
160 | 160 | <div class="parity1 source"><a href="#l22" id="l22"> 22</a> <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></div> |
|
161 | 161 | <div class="parity0 source"><a href="#l23" id="l23"> 23</a> <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mi">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o"><</span> <span class="mi">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></div> |
|
162 | 162 | <div class="parity1 source"><a href="#l24" id="l24"> 24</a> </div> |
|
163 | 163 | <div class="parity0 source"><a href="#l25" id="l25"> 25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></div> |
|
164 | 164 | <div class="parity1 source"><a href="#l26" id="l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></div> |
|
165 | 165 | <div class="parity0 source"><a href="#l27" id="l27"> 27</a> <span class="kn">try</span><span class="p">:</span></div> |
|
166 | 166 | <div class="parity1 source"><a href="#l28" id="l28"> 28</a> <span class="n">n</span> <span class="o">=</span> <span class="nb">int</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> |
|
167 | 167 | <div class="parity0 source"><a href="#l29" id="l29"> 29</a> <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></div> |
|
168 | 168 | <div class="parity1 source"><a href="#l30" id="l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mi">10</span></div> |
|
169 | 169 | <div class="parity0 source"><a href="#l31" id="l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></div> |
|
170 | 170 | <div class="parity1 source"><a href="#l32" id="l32"> 32</a> <span class="kn">print</span> <span class="s">"The first </span><span class="si">%d</span><span class="s"> primes: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">islice</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span></div> |
|
171 | 171 | <div class="sourcelast"></div> |
|
172 | 172 | </div> |
|
173 | 173 | </div> |
|
174 | 174 | </div> |
|
175 | 175 | |
|
176 | 176 | |
|
177 | 177 | |
|
178 | 178 | </body> |
|
179 | 179 | </html> |
|
180 | 180 | |
|
181 | 181 | |
|
182 | 182 | hgweb fileannotate, html |
|
183 | 183 | |
|
184 | 184 | $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py') \ |
|
185 | 185 | > | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mi\"/class=\"mf\"/g" |
|
186 | 186 | 200 Script output follows |
|
187 | 187 | |
|
188 | 188 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
189 | 189 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
190 | 190 | <head> |
|
191 | 191 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
192 | 192 | <meta name="robots" content="index, nofollow" /> |
|
193 | 193 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
194 | 194 | |
|
195 | 195 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
196 | 196 | <title>test: primes.py annotate</title> |
|
197 | 197 | </head> |
|
198 | 198 | <body> |
|
199 | 199 | |
|
200 | 200 | <div class="container"> |
|
201 | 201 | <div class="menu"> |
|
202 | 202 | <div class="logo"> |
|
203 | 203 | <a href="http://mercurial.selenic.com/"> |
|
204 | 204 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
205 | 205 | </div> |
|
206 | 206 | <ul> |
|
207 | 207 | <li><a href="/shortlog/853dcd4de2a6">log</a></li> |
|
208 | 208 | <li><a href="/graph/853dcd4de2a6">graph</a></li> |
|
209 | 209 | <li><a href="/tags">tags</a></li> |
|
210 | <li><a href="/bookmarks">bookmarks</a></li> | |
|
210 | 211 | <li><a href="/branches">branches</a></li> |
|
211 | 212 | </ul> |
|
212 | 213 | |
|
213 | 214 | <ul> |
|
214 | 215 | <li><a href="/rev/853dcd4de2a6">changeset</a></li> |
|
215 | 216 | <li><a href="/file/853dcd4de2a6/">browse</a></li> |
|
216 | 217 | </ul> |
|
217 | 218 | <ul> |
|
218 | 219 | <li><a href="/file/853dcd4de2a6/primes.py">file</a></li> |
|
219 | 220 | <li><a href="/file/tip/primes.py">latest</a></li> |
|
220 | 221 | <li><a href="/diff/853dcd4de2a6/primes.py">diff</a></li> |
|
221 | 222 | <li class="active">annotate</li> |
|
222 | 223 | <li><a href="/log/853dcd4de2a6/primes.py">file log</a></li> |
|
223 | 224 | <li><a href="/raw-annotate/853dcd4de2a6/primes.py">raw</a></li> |
|
224 | 225 | </ul> |
|
225 | 226 | <ul> |
|
226 | 227 | <li><a href="/help">help</a></li> |
|
227 | 228 | </ul> |
|
228 | 229 | </div> |
|
229 | 230 | |
|
230 | 231 | <div class="main"> |
|
231 | 232 | <h2><a href="/">test</a></h2> |
|
232 | 233 | <h3>annotate primes.py @ 0:853dcd4de2a6</h3> |
|
233 | 234 | |
|
234 | 235 | <form class="search" action="/log"> |
|
235 | 236 | |
|
236 | 237 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
237 | 238 | <div id="hint">find changesets by author, revision, |
|
238 | 239 | files, or words in the commit message</div> |
|
239 | 240 | </form> |
|
240 | 241 | |
|
241 | 242 | <div class="description">a</div> |
|
242 | 243 | |
|
243 | 244 | <table id="changesetEntry"> |
|
244 | 245 | <tr> |
|
245 | 246 | <th class="author">author</th> |
|
246 | 247 | <td class="author">test</td> |
|
247 | 248 | </tr> |
|
248 | 249 | <tr> |
|
249 | 250 | <th class="date">date</th> |
|
250 | 251 | <td class="date">Thu Jan 01 00:00:00 1970 +0000 (1970-01-01)</td> |
|
251 | 252 | </tr> |
|
252 | 253 | <tr> |
|
253 | 254 | <th class="author">parents</th> |
|
254 | 255 | <td class="author"></td> |
|
255 | 256 | </tr> |
|
256 | 257 | <tr> |
|
257 | 258 | <th class="author">children</th> |
|
258 | 259 | <td class="author"></td> |
|
259 | 260 | </tr> |
|
260 | 261 | |
|
261 | 262 | </table> |
|
262 | 263 | |
|
263 | 264 | <div class="overflow"> |
|
264 | 265 | <table class="bigtable"> |
|
265 | 266 | <tr> |
|
266 | 267 | <th class="annotate">rev</th> |
|
267 | 268 | <th class="line"> line source</th> |
|
268 | 269 | </tr> |
|
269 | 270 | |
|
270 | 271 | <tr class="parity0"> |
|
271 | 272 | <td class="annotate"> |
|
272 | 273 | <a href="/annotate/853dcd4de2a6/primes.py#1" |
|
273 | 274 | title="853dcd4de2a6: a">test@0</a> |
|
274 | 275 | </td> |
|
275 | 276 | <td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> |
|
276 | 277 | </tr> |
|
277 | 278 | <tr class="parity1"> |
|
278 | 279 | <td class="annotate"> |
|
279 | 280 | <a href="/annotate/853dcd4de2a6/primes.py#2" |
|
280 | 281 | title="853dcd4de2a6: a">test@0</a> |
|
281 | 282 | </td> |
|
282 | 283 | <td class="source"><a href="#l2" id="l2"> 2</a> </td> |
|
283 | 284 | </tr> |
|
284 | 285 | <tr class="parity0"> |
|
285 | 286 | <td class="annotate"> |
|
286 | 287 | <a href="/annotate/853dcd4de2a6/primes.py#3" |
|
287 | 288 | title="853dcd4de2a6: a">test@0</a> |
|
288 | 289 | </td> |
|
289 | 290 | <td class="source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></td> |
|
290 | 291 | </tr> |
|
291 | 292 | <tr class="parity1"> |
|
292 | 293 | <td class="annotate"> |
|
293 | 294 | <a href="/annotate/853dcd4de2a6/primes.py#4" |
|
294 | 295 | title="853dcd4de2a6: a">test@0</a> |
|
295 | 296 | </td> |
|
296 | 297 | <td class="source"><a href="#l4" id="l4"> 4</a> </td> |
|
297 | 298 | </tr> |
|
298 | 299 | <tr class="parity0"> |
|
299 | 300 | <td class="annotate"> |
|
300 | 301 | <a href="/annotate/853dcd4de2a6/primes.py#5" |
|
301 | 302 | title="853dcd4de2a6: a">test@0</a> |
|
302 | 303 | </td> |
|
303 | 304 | <td class="source"><a href="#l5" id="l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></td> |
|
304 | 305 | </tr> |
|
305 | 306 | <tr class="parity1"> |
|
306 | 307 | <td class="annotate"> |
|
307 | 308 | <a href="/annotate/853dcd4de2a6/primes.py#6" |
|
308 | 309 | title="853dcd4de2a6: a">test@0</a> |
|
309 | 310 | </td> |
|
310 | 311 | <td class="source"><a href="#l6" id="l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></td> |
|
311 | 312 | </tr> |
|
312 | 313 | <tr class="parity0"> |
|
313 | 314 | <td class="annotate"> |
|
314 | 315 | <a href="/annotate/853dcd4de2a6/primes.py#7" |
|
315 | 316 | title="853dcd4de2a6: a">test@0</a> |
|
316 | 317 | </td> |
|
317 | 318 | <td class="source"><a href="#l7" id="l7"> 7</a> <span class="sd">"""</span></td> |
|
318 | 319 | </tr> |
|
319 | 320 | <tr class="parity1"> |
|
320 | 321 | <td class="annotate"> |
|
321 | 322 | <a href="/annotate/853dcd4de2a6/primes.py#8" |
|
322 | 323 | title="853dcd4de2a6: a">test@0</a> |
|
323 | 324 | </td> |
|
324 | 325 | <td class="source"><a href="#l8" id="l8"> 8</a> </td> |
|
325 | 326 | </tr> |
|
326 | 327 | <tr class="parity0"> |
|
327 | 328 | <td class="annotate"> |
|
328 | 329 | <a href="/annotate/853dcd4de2a6/primes.py#9" |
|
329 | 330 | title="853dcd4de2a6: a">test@0</a> |
|
330 | 331 | </td> |
|
331 | 332 | <td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></td> |
|
332 | 333 | </tr> |
|
333 | 334 | <tr class="parity1"> |
|
334 | 335 | <td class="annotate"> |
|
335 | 336 | <a href="/annotate/853dcd4de2a6/primes.py#10" |
|
336 | 337 | title="853dcd4de2a6: a">test@0</a> |
|
337 | 338 | </td> |
|
338 | 339 | <td class="source"><a href="#l10" id="l10"> 10</a> </td> |
|
339 | 340 | </tr> |
|
340 | 341 | <tr class="parity0"> |
|
341 | 342 | <td class="annotate"> |
|
342 | 343 | <a href="/annotate/853dcd4de2a6/primes.py#11" |
|
343 | 344 | title="853dcd4de2a6: a">test@0</a> |
|
344 | 345 | </td> |
|
345 | 346 | <td class="source"><a href="#l11" id="l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></td> |
|
346 | 347 | </tr> |
|
347 | 348 | <tr class="parity1"> |
|
348 | 349 | <td class="annotate"> |
|
349 | 350 | <a href="/annotate/853dcd4de2a6/primes.py#12" |
|
350 | 351 | title="853dcd4de2a6: a">test@0</a> |
|
351 | 352 | </td> |
|
352 | 353 | <td class="source"><a href="#l12" id="l12"> 12</a> <span class="sd">"""Generate all primes."""</span></td> |
|
353 | 354 | </tr> |
|
354 | 355 | <tr class="parity0"> |
|
355 | 356 | <td class="annotate"> |
|
356 | 357 | <a href="/annotate/853dcd4de2a6/primes.py#13" |
|
357 | 358 | title="853dcd4de2a6: a">test@0</a> |
|
358 | 359 | </td> |
|
359 | 360 | <td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> |
|
360 | 361 | </tr> |
|
361 | 362 | <tr class="parity1"> |
|
362 | 363 | <td class="annotate"> |
|
363 | 364 | <a href="/annotate/853dcd4de2a6/primes.py#14" |
|
364 | 365 | title="853dcd4de2a6: a">test@0</a> |
|
365 | 366 | </td> |
|
366 | 367 | <td class="source"><a href="#l14" id="l14"> 14</a> <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></td> |
|
367 | 368 | </tr> |
|
368 | 369 | <tr class="parity0"> |
|
369 | 370 | <td class="annotate"> |
|
370 | 371 | <a href="/annotate/853dcd4de2a6/primes.py#15" |
|
371 | 372 | title="853dcd4de2a6: a">test@0</a> |
|
372 | 373 | </td> |
|
373 | 374 | <td class="source"><a href="#l15" id="l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></td> |
|
374 | 375 | </tr> |
|
375 | 376 | <tr class="parity1"> |
|
376 | 377 | <td class="annotate"> |
|
377 | 378 | <a href="/annotate/853dcd4de2a6/primes.py#16" |
|
378 | 379 | title="853dcd4de2a6: a">test@0</a> |
|
379 | 380 | </td> |
|
380 | 381 | <td class="source"><a href="#l16" id="l16"> 16</a> <span class="c"># infinite recursion.</span></td> |
|
381 | 382 | </tr> |
|
382 | 383 | <tr class="parity0"> |
|
383 | 384 | <td class="annotate"> |
|
384 | 385 | <a href="/annotate/853dcd4de2a6/primes.py#17" |
|
385 | 386 | title="853dcd4de2a6: a">test@0</a> |
|
386 | 387 | </td> |
|
387 | 388 | <td class="source"><a href="#l17" id="l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></td> |
|
388 | 389 | </tr> |
|
389 | 390 | <tr class="parity1"> |
|
390 | 391 | <td class="annotate"> |
|
391 | 392 | <a href="/annotate/853dcd4de2a6/primes.py#18" |
|
392 | 393 | title="853dcd4de2a6: a">test@0</a> |
|
393 | 394 | </td> |
|
394 | 395 | <td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mf">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></td> |
|
395 | 396 | </tr> |
|
396 | 397 | <tr class="parity0"> |
|
397 | 398 | <td class="annotate"> |
|
398 | 399 | <a href="/annotate/853dcd4de2a6/primes.py#19" |
|
399 | 400 | title="853dcd4de2a6: a">test@0</a> |
|
400 | 401 | </td> |
|
401 | 402 | <td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> |
|
402 | 403 | </tr> |
|
403 | 404 | <tr class="parity1"> |
|
404 | 405 | <td class="annotate"> |
|
405 | 406 | <a href="/annotate/853dcd4de2a6/primes.py#20" |
|
406 | 407 | title="853dcd4de2a6: a">test@0</a> |
|
407 | 408 | </td> |
|
408 | 409 | <td class="source"><a href="#l20" id="l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></td> |
|
409 | 410 | </tr> |
|
410 | 411 | <tr class="parity0"> |
|
411 | 412 | <td class="annotate"> |
|
412 | 413 | <a href="/annotate/853dcd4de2a6/primes.py#21" |
|
413 | 414 | title="853dcd4de2a6: a">test@0</a> |
|
414 | 415 | </td> |
|
415 | 416 | <td class="source"><a href="#l21" id="l21"> 21</a> </td> |
|
416 | 417 | </tr> |
|
417 | 418 | <tr class="parity1"> |
|
418 | 419 | <td class="annotate"> |
|
419 | 420 | <a href="/annotate/853dcd4de2a6/primes.py#22" |
|
420 | 421 | title="853dcd4de2a6: a">test@0</a> |
|
421 | 422 | </td> |
|
422 | 423 | <td class="source"><a href="#l22" id="l22"> 22</a> <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mf">2</span> <span class="o">==</span> <span class="mf">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></td> |
|
423 | 424 | </tr> |
|
424 | 425 | <tr class="parity0"> |
|
425 | 426 | <td class="annotate"> |
|
426 | 427 | <a href="/annotate/853dcd4de2a6/primes.py#23" |
|
427 | 428 | title="853dcd4de2a6: a">test@0</a> |
|
428 | 429 | </td> |
|
429 | 430 | <td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mf">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o"><</span> <span class="mf">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></td> |
|
430 | 431 | </tr> |
|
431 | 432 | <tr class="parity1"> |
|
432 | 433 | <td class="annotate"> |
|
433 | 434 | <a href="/annotate/853dcd4de2a6/primes.py#24" |
|
434 | 435 | title="853dcd4de2a6: a">test@0</a> |
|
435 | 436 | </td> |
|
436 | 437 | <td class="source"><a href="#l24" id="l24"> 24</a> </td> |
|
437 | 438 | </tr> |
|
438 | 439 | <tr class="parity0"> |
|
439 | 440 | <td class="annotate"> |
|
440 | 441 | <a href="/annotate/853dcd4de2a6/primes.py#25" |
|
441 | 442 | title="853dcd4de2a6: a">test@0</a> |
|
442 | 443 | </td> |
|
443 | 444 | <td class="source"><a href="#l25" id="l25"> 25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></td> |
|
444 | 445 | </tr> |
|
445 | 446 | <tr class="parity1"> |
|
446 | 447 | <td class="annotate"> |
|
447 | 448 | <a href="/annotate/853dcd4de2a6/primes.py#26" |
|
448 | 449 | title="853dcd4de2a6: a">test@0</a> |
|
449 | 450 | </td> |
|
450 | 451 | <td class="source"><a href="#l26" id="l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></td> |
|
451 | 452 | </tr> |
|
452 | 453 | <tr class="parity0"> |
|
453 | 454 | <td class="annotate"> |
|
454 | 455 | <a href="/annotate/853dcd4de2a6/primes.py#27" |
|
455 | 456 | title="853dcd4de2a6: a">test@0</a> |
|
456 | 457 | </td> |
|
457 | 458 | <td class="source"><a href="#l27" id="l27"> 27</a> <span class="kn">try</span><span class="p">:</span></td> |
|
458 | 459 | </tr> |
|
459 | 460 | <tr class="parity1"> |
|
460 | 461 | <td class="annotate"> |
|
461 | 462 | <a href="/annotate/853dcd4de2a6/primes.py#28" |
|
462 | 463 | title="853dcd4de2a6: a">test@0</a> |
|
463 | 464 | </td> |
|
464 | 465 | <td class="source"><a href="#l28" id="l28"> 28</a> <span class="n">n</span> <span class="o">=</span> <span class="nb">int</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> |
|
465 | 466 | </tr> |
|
466 | 467 | <tr class="parity0"> |
|
467 | 468 | <td class="annotate"> |
|
468 | 469 | <a href="/annotate/853dcd4de2a6/primes.py#29" |
|
469 | 470 | title="853dcd4de2a6: a">test@0</a> |
|
470 | 471 | </td> |
|
471 | 472 | <td class="source"><a href="#l29" id="l29"> 29</a> <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></td> |
|
472 | 473 | </tr> |
|
473 | 474 | <tr class="parity1"> |
|
474 | 475 | <td class="annotate"> |
|
475 | 476 | <a href="/annotate/853dcd4de2a6/primes.py#30" |
|
476 | 477 | title="853dcd4de2a6: a">test@0</a> |
|
477 | 478 | </td> |
|
478 | 479 | <td class="source"><a href="#l30" id="l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mf">10</span></td> |
|
479 | 480 | </tr> |
|
480 | 481 | <tr class="parity0"> |
|
481 | 482 | <td class="annotate"> |
|
482 | 483 | <a href="/annotate/853dcd4de2a6/primes.py#31" |
|
483 | 484 | title="853dcd4de2a6: a">test@0</a> |
|
484 | 485 | </td> |
|
485 | 486 | <td class="source"><a href="#l31" id="l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></td> |
|
486 | 487 | </tr> |
|
487 | 488 | <tr class="parity1"> |
|
488 | 489 | <td class="annotate"> |
|
489 | 490 | <a href="/annotate/853dcd4de2a6/primes.py#32" |
|
490 | 491 | title="853dcd4de2a6: a">test@0</a> |
|
491 | 492 | </td> |
|
492 | 493 | <td class="source"><a href="#l32" id="l32"> 32</a> <span class="kn">print</span> <span class="s">"The first </span><span class="si">%d</span><span class="s"> primes: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">islice</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span></td> |
|
493 | 494 | </tr> |
|
494 | 495 | </table> |
|
495 | 496 | </div> |
|
496 | 497 | </div> |
|
497 | 498 | </div> |
|
498 | 499 | |
|
499 | 500 | |
|
500 | 501 | |
|
501 | 502 | </body> |
|
502 | 503 | </html> |
|
503 | 504 | |
|
504 | 505 | |
|
505 | 506 | hgweb fileannotate, raw |
|
506 | 507 | |
|
507 | 508 | $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py?style=raw') \ |
|
508 | 509 | > | sed "s/test@//" > a |
|
509 | 510 | $ echo "200 Script output follows" > b |
|
510 | 511 | $ echo "" >> b |
|
511 | 512 | $ echo "" >> b |
|
512 | 513 | $ hg annotate "primes.py" >> b |
|
513 | 514 | $ echo "" >> b |
|
514 | 515 | $ echo "" >> b |
|
515 | 516 | $ echo "" >> b |
|
516 | 517 | $ echo "" >> b |
|
517 | 518 | $ diff -u b a |
|
518 | 519 | $ echo |
|
519 | 520 | |
|
520 | 521 | |
|
521 | 522 | hgweb filerevision, raw |
|
522 | 523 | |
|
523 | 524 | $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py?style=raw') \ |
|
524 | 525 | > > a |
|
525 | 526 | $ echo "200 Script output follows" > b |
|
526 | 527 | $ echo "" >> b |
|
527 | 528 | $ hg cat primes.py >> b |
|
528 | 529 | $ diff -u b a |
|
529 | 530 | $ echo |
|
530 | 531 | |
|
531 | 532 | |
|
532 | 533 | hgweb highlightcss friendly |
|
533 | 534 | |
|
534 | 535 | $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out |
|
535 | 536 | $ head -n 4 out |
|
536 | 537 | 200 Script output follows |
|
537 | 538 | |
|
538 | 539 | /* pygments_style = friendly */ |
|
539 | 540 | |
|
540 | 541 | $ rm out |
|
541 | 542 | |
|
542 | 543 | errors encountered |
|
543 | 544 | |
|
544 | 545 | $ cat errors.log |
|
545 | 546 | $ "$TESTDIR/killdaemons.py" |
|
546 | 547 | |
|
547 | 548 | Change the pygments style |
|
548 | 549 | |
|
549 | 550 | $ cat > .hg/hgrc <<EOF |
|
550 | 551 | > [web] |
|
551 | 552 | > pygments_style = fruity |
|
552 | 553 | > EOF |
|
553 | 554 | |
|
554 | 555 | hg serve again |
|
555 | 556 | |
|
556 | 557 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
557 | 558 | $ cat hg.pid >> $DAEMON_PIDS |
|
558 | 559 | |
|
559 | 560 | hgweb highlightcss fruity |
|
560 | 561 | |
|
561 | 562 | $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/highlightcss' > out |
|
562 | 563 | $ head -n 4 out |
|
563 | 564 | 200 Script output follows |
|
564 | 565 | |
|
565 | 566 | /* pygments_style = fruity */ |
|
566 | 567 | |
|
567 | 568 | $ rm out |
|
568 | 569 | |
|
569 | 570 | errors encountered |
|
570 | 571 | |
|
571 | 572 | $ cat errors.log |
|
572 | 573 | $ cd .. |
|
573 | 574 | $ hg init eucjp |
|
574 | 575 | $ cd eucjp |
|
575 | 576 | $ python -c 'print("\265\376")' >> eucjp.txt # Japanese kanji "Kyo" |
|
576 | 577 | $ hg ci -Ama |
|
577 | 578 | adding eucjp.txt |
|
578 | 579 | $ hgserveget () { |
|
579 | 580 | > "$TESTDIR/killdaemons.py" |
|
580 | 581 | > echo % HGENCODING="$1" hg serve |
|
581 | 582 | > HGENCODING="$1" hg serve -p $HGPORT -d -n test --pid-file=hg.pid -E errors.log |
|
582 | 583 | > cat hg.pid >> $DAEMON_PIDS |
|
583 | 584 | > |
|
584 | 585 | > echo % hgweb filerevision, html |
|
585 | 586 | > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/file/tip/$2" \ |
|
586 | 587 | > | grep '<div class="parity0 source">' |
|
587 | 588 | > echo % errors encountered |
|
588 | 589 | > cat errors.log |
|
589 | 590 | > } |
|
590 | 591 | $ hgserveget euc-jp eucjp.txt |
|
591 | 592 | % HGENCODING=euc-jp hg serve |
|
592 | 593 | % hgweb filerevision, html |
|
593 | 594 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xb5\xfe</div> (esc) |
|
594 | 595 | % errors encountered |
|
595 | 596 | $ hgserveget utf-8 eucjp.txt |
|
596 | 597 | % HGENCODING=utf-8 hg serve |
|
597 | 598 | % hgweb filerevision, html |
|
598 | 599 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xef\xbf\xbd\xef\xbf\xbd</div> (esc) |
|
599 | 600 | % errors encountered |
|
600 | 601 | $ hgserveget us-ascii eucjp.txt |
|
601 | 602 | % HGENCODING=us-ascii hg serve |
|
602 | 603 | % hgweb filerevision, html |
|
603 | 604 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> ??</div> |
|
604 | 605 | % errors encountered |
General Comments 0
You need to be logged in to leave comments.
Login now