Show More
@@ -1,1020 +1,1021 | |||
|
1 | 1 | #require pygments serve |
|
2 | 2 | |
|
3 | 3 | $ cat <<EOF >> $HGRCPATH |
|
4 | 4 | > [extensions] |
|
5 | 5 | > highlight = |
|
6 | 6 | > [web] |
|
7 | 7 | > pygments_style = friendly |
|
8 | 8 | > highlightfiles = **.py and size('<100KB') |
|
9 | 9 | > EOF |
|
10 | 10 | $ hg init test |
|
11 | 11 | $ cd test |
|
12 | 12 | |
|
13 | 13 | $ filterhtml () { |
|
14 | 14 | > sed -e "s/class=\"k\"/class=\"kn\"/g" \ |
|
15 | 15 | > -e "s/class=\"mf\"/class=\"mi\"/g" \ |
|
16 | > -e "s/class=\"vm\"/class=\"n\"/g" \ | |
|
16 | 17 | > -e "s/class=\"\([cs]\)[h12]\"/class=\"\1\"/g" |
|
17 | 18 | > } |
|
18 | 19 | |
|
19 | 20 | create random Python file to exercise Pygments |
|
20 | 21 | |
|
21 | 22 | $ cat <<EOF > primes.py |
|
22 | 23 | > #!/usr/bin/env python |
|
23 | 24 | > |
|
24 | 25 | > """Fun with generators. Corresponding Haskell implementation: |
|
25 | 26 | > |
|
26 | 27 | > primes = 2 : sieve [3, 5..] |
|
27 | 28 | > where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] |
|
28 | 29 | > """ |
|
29 | 30 | > |
|
30 | 31 | > from itertools import dropwhile, ifilter, islice, count, chain |
|
31 | 32 | > |
|
32 | 33 | > def primes(): |
|
33 | 34 | > """Generate all primes.""" |
|
34 | 35 | > def sieve(ns): |
|
35 | 36 | > p = ns.next() |
|
36 | 37 | > # It is important to yield *here* in order to stop the |
|
37 | 38 | > # infinite recursion. |
|
38 | 39 | > yield p |
|
39 | 40 | > ns = ifilter(lambda n: n % p != 0, ns) |
|
40 | 41 | > for n in sieve(ns): |
|
41 | 42 | > yield n |
|
42 | 43 | > |
|
43 | 44 | > odds = ifilter(lambda i: i % 2 == 1, count()) |
|
44 | 45 | > return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) |
|
45 | 46 | > |
|
46 | 47 | > if __name__ == "__main__": |
|
47 | 48 | > import sys |
|
48 | 49 | > try: |
|
49 | 50 | > n = int(sys.argv[1]) |
|
50 | 51 | > except (ValueError, IndexError): |
|
51 | 52 | > n = 10 |
|
52 | 53 | > p = primes() |
|
53 | 54 | > print "The first %d primes: %s" % (n, list(islice(p, n))) |
|
54 | 55 | > EOF |
|
55 | 56 | $ echo >> primes.py # to test html markup with an empty line just before EOF |
|
56 | 57 | $ hg ci -Ama |
|
57 | 58 | adding primes.py |
|
58 | 59 | |
|
59 | 60 | hg serve |
|
60 | 61 | |
|
61 | 62 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
62 | 63 | $ cat hg.pid >> $DAEMON_PIDS |
|
63 | 64 | |
|
64 | 65 | hgweb filerevision, html |
|
65 | 66 | |
|
66 | 67 | $ (get-with-headers.py localhost:$HGPORT 'file/tip/primes.py') | filterhtml |
|
67 | 68 | 200 Script output follows |
|
68 | 69 | |
|
69 | 70 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
70 | 71 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
71 | 72 | <head> |
|
72 | 73 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
73 | 74 | <meta name="robots" content="index, nofollow" /> |
|
74 | 75 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
75 | 76 | <script type="text/javascript" src="/static/mercurial.js"></script> |
|
76 | 77 | |
|
77 | 78 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
78 | 79 | <title>test: 06824edf55d0 primes.py</title> |
|
79 | 80 | </head> |
|
80 | 81 | <body> |
|
81 | 82 | |
|
82 | 83 | <div class="container"> |
|
83 | 84 | <div class="menu"> |
|
84 | 85 | <div class="logo"> |
|
85 | 86 | <a href="https://mercurial-scm.org/"> |
|
86 | 87 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
87 | 88 | </div> |
|
88 | 89 | <ul> |
|
89 | 90 | <li><a href="/shortlog/tip">log</a></li> |
|
90 | 91 | <li><a href="/graph/tip">graph</a></li> |
|
91 | 92 | <li><a href="/tags">tags</a></li> |
|
92 | 93 | <li><a href="/bookmarks">bookmarks</a></li> |
|
93 | 94 | <li><a href="/branches">branches</a></li> |
|
94 | 95 | </ul> |
|
95 | 96 | <ul> |
|
96 | 97 | <li><a href="/rev/tip">changeset</a></li> |
|
97 | 98 | <li><a href="/file/tip/">browse</a></li> |
|
98 | 99 | </ul> |
|
99 | 100 | <ul> |
|
100 | 101 | <li class="active">file</li> |
|
101 | 102 | <li><a href="/file/tip/primes.py">latest</a></li> |
|
102 | 103 | <li><a href="/diff/tip/primes.py">diff</a></li> |
|
103 | 104 | <li><a href="/comparison/tip/primes.py">comparison</a></li> |
|
104 | 105 | <li><a href="/annotate/tip/primes.py">annotate</a></li> |
|
105 | 106 | <li><a href="/log/tip/primes.py">file log</a></li> |
|
106 | 107 | <li><a href="/raw-file/tip/primes.py">raw</a></li> |
|
107 | 108 | </ul> |
|
108 | 109 | <ul> |
|
109 | 110 | <li><a href="/help">help</a></li> |
|
110 | 111 | </ul> |
|
111 | 112 | </div> |
|
112 | 113 | |
|
113 | 114 | <div class="main"> |
|
114 | 115 | <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2> |
|
115 | 116 | <h3> |
|
116 | 117 | view primes.py @ 0:<a href="/rev/06824edf55d0">06824edf55d0</a> |
|
117 | 118 | <span class="tag">tip</span> |
|
118 | 119 | </h3> |
|
119 | 120 | |
|
120 | 121 | <form class="search" action="/log"> |
|
121 | 122 | |
|
122 | 123 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
123 | 124 | <div id="hint">Find changesets by keywords (author, files, the commit message), revision |
|
124 | 125 | number or hash, or <a href="/help/revsets">revset expression</a>.</div> |
|
125 | 126 | </form> |
|
126 | 127 | |
|
127 | 128 | <div class="description">a</div> |
|
128 | 129 | |
|
129 | 130 | <table id="changesetEntry"> |
|
130 | 131 | <tr> |
|
131 | 132 | <th class="author">author</th> |
|
132 | 133 | <td class="author">test</td> |
|
133 | 134 | </tr> |
|
134 | 135 | <tr> |
|
135 | 136 | <th class="date">date</th> |
|
136 | 137 | <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td> |
|
137 | 138 | </tr> |
|
138 | 139 | <tr> |
|
139 | 140 | <th class="author">parents</th> |
|
140 | 141 | <td class="author"></td> |
|
141 | 142 | </tr> |
|
142 | 143 | <tr> |
|
143 | 144 | <th class="author">children</th> |
|
144 | 145 | <td class="author"></td> |
|
145 | 146 | </tr> |
|
146 | 147 | </table> |
|
147 | 148 | |
|
148 | 149 | <div class="overflow"> |
|
149 | 150 | <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div> |
|
150 | 151 | <div class="sourcefirst"> line source</div> |
|
151 | 152 | <pre class="sourcelines stripes4 wrap bottomline"> |
|
152 | 153 | <span id="l1"><span class="c">#!/usr/bin/env python</span></span><a href="#l1"></a> |
|
153 | 154 | <span id="l2"></span><a href="#l2"></a> |
|
154 | 155 | <span id="l3"><span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></span><a href="#l3"></a> |
|
155 | 156 | <span id="l4"></span><a href="#l4"></a> |
|
156 | 157 | <span id="l5"><span class="sd">primes = 2 : sieve [3, 5..]</span></span><a href="#l5"></a> |
|
157 | 158 | <span id="l6"><span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></span><a href="#l6"></a> |
|
158 | 159 | <span id="l7"><span class="sd">"""</span></span><a href="#l7"></a> |
|
159 | 160 | <span id="l8"></span><a href="#l8"></a> |
|
160 | 161 | <span id="l9"><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></span><a href="#l9"></a> |
|
161 | 162 | <span id="l10"></span><a href="#l10"></a> |
|
162 | 163 | <span id="l11"><span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></span><a href="#l11"></a> |
|
163 | 164 | <span id="l12"> <span class="sd">"""Generate all primes."""</span></span><a href="#l12"></a> |
|
164 | 165 | <span id="l13"> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></span><a href="#l13"></a> |
|
165 | 166 | <span id="l14"> <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></span><a href="#l14"></a> |
|
166 | 167 | <span id="l15"> <span class="c"># It is important to yield *here* in order to stop the</span></span><a href="#l15"></a> |
|
167 | 168 | <span id="l16"> <span class="c"># infinite recursion.</span></span><a href="#l16"></a> |
|
168 | 169 | <span id="l17"> <span class="kn">yield</span> <span class="n">p</span></span><a href="#l17"></a> |
|
169 | 170 | <span id="l18"> <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></span><a href="#l18"></a> |
|
170 | 171 | <span id="l19"> <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></span><a href="#l19"></a> |
|
171 | 172 | <span id="l20"> <span class="kn">yield</span> <span class="n">n</span></span><a href="#l20"></a> |
|
172 | 173 | <span id="l21"></span><a href="#l21"></a> |
|
173 | 174 | <span id="l22"> <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></span><a href="#l22"></a> |
|
174 | 175 | <span id="l23"> <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></span><a href="#l23"></a> |
|
175 | 176 | <span id="l24"></span><a href="#l24"></a> |
|
176 | 177 | <span id="l25"><span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></span><a href="#l25"></a> |
|
177 | 178 | <span id="l26"> <span class="kn">import</span> <span class="nn">sys</span></span><a href="#l26"></a> |
|
178 | 179 | <span id="l27"> <span class="kn">try</span><span class="p">:</span></span><a href="#l27"></a> |
|
179 | 180 | <span id="l28"> <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></span><a href="#l28"></a> |
|
180 | 181 | <span id="l29"> <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></span><a href="#l29"></a> |
|
181 | 182 | <span id="l30"> <span class="n">n</span> <span class="o">=</span> <span class="mi">10</span></span><a href="#l30"></a> |
|
182 | 183 | <span id="l31"> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></span><a href="#l31"></a> |
|
183 | 184 | <span id="l32"> <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></span><a href="#l32"></a> |
|
184 | 185 | <span id="l33"></span><a href="#l33"></a></pre> |
|
185 | 186 | </div> |
|
186 | 187 | </div> |
|
187 | 188 | </div> |
|
188 | 189 | |
|
189 | 190 | |
|
190 | 191 | |
|
191 | 192 | </body> |
|
192 | 193 | </html> |
|
193 | 194 | |
|
194 | 195 | |
|
195 | 196 | hgweb fileannotate, html |
|
196 | 197 | |
|
197 | 198 | $ (get-with-headers.py localhost:$HGPORT 'annotate/tip/primes.py') | filterhtml |
|
198 | 199 | 200 Script output follows |
|
199 | 200 | |
|
200 | 201 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
|
201 | 202 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"> |
|
202 | 203 | <head> |
|
203 | 204 | <link rel="icon" href="/static/hgicon.png" type="image/png" /> |
|
204 | 205 | <meta name="robots" content="index, nofollow" /> |
|
205 | 206 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
206 | 207 | <script type="text/javascript" src="/static/mercurial.js"></script> |
|
207 | 208 | |
|
208 | 209 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
209 | 210 | <title>test: primes.py annotate</title> |
|
210 | 211 | </head> |
|
211 | 212 | <body> |
|
212 | 213 | |
|
213 | 214 | <div class="container"> |
|
214 | 215 | <div class="menu"> |
|
215 | 216 | <div class="logo"> |
|
216 | 217 | <a href="https://mercurial-scm.org/"> |
|
217 | 218 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
218 | 219 | </div> |
|
219 | 220 | <ul> |
|
220 | 221 | <li><a href="/shortlog/tip">log</a></li> |
|
221 | 222 | <li><a href="/graph/tip">graph</a></li> |
|
222 | 223 | <li><a href="/tags">tags</a></li> |
|
223 | 224 | <li><a href="/bookmarks">bookmarks</a></li> |
|
224 | 225 | <li><a href="/branches">branches</a></li> |
|
225 | 226 | </ul> |
|
226 | 227 | |
|
227 | 228 | <ul> |
|
228 | 229 | <li><a href="/rev/tip">changeset</a></li> |
|
229 | 230 | <li><a href="/file/tip/">browse</a></li> |
|
230 | 231 | </ul> |
|
231 | 232 | <ul> |
|
232 | 233 | <li><a href="/file/tip/primes.py">file</a></li> |
|
233 | 234 | <li><a href="/file/tip/primes.py">latest</a></li> |
|
234 | 235 | <li><a href="/diff/tip/primes.py">diff</a></li> |
|
235 | 236 | <li><a href="/comparison/tip/primes.py">comparison</a></li> |
|
236 | 237 | <li class="active">annotate</li> |
|
237 | 238 | <li><a href="/log/tip/primes.py">file log</a></li> |
|
238 | 239 | <li><a href="/raw-file/tip/primes.py">raw</a></li> |
|
239 | 240 | </ul> |
|
240 | 241 | <ul> |
|
241 | 242 | <li><a href="/help">help</a></li> |
|
242 | 243 | </ul> |
|
243 | 244 | </div> |
|
244 | 245 | |
|
245 | 246 | <div class="main"> |
|
246 | 247 | <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2> |
|
247 | 248 | <h3> |
|
248 | 249 | annotate primes.py @ 0:<a href="/rev/06824edf55d0">06824edf55d0</a> |
|
249 | 250 | <span class="tag">tip</span> |
|
250 | 251 | </h3> |
|
251 | 252 | |
|
252 | 253 | <form class="search" action="/log"> |
|
253 | 254 | |
|
254 | 255 | <p><input name="rev" id="search1" type="text" size="30" /></p> |
|
255 | 256 | <div id="hint">Find changesets by keywords (author, files, the commit message), revision |
|
256 | 257 | number or hash, or <a href="/help/revsets">revset expression</a>.</div> |
|
257 | 258 | </form> |
|
258 | 259 | |
|
259 | 260 | <div class="description">a</div> |
|
260 | 261 | |
|
261 | 262 | <table id="changesetEntry"> |
|
262 | 263 | <tr> |
|
263 | 264 | <th class="author">author</th> |
|
264 | 265 | <td class="author">test</td> |
|
265 | 266 | </tr> |
|
266 | 267 | <tr> |
|
267 | 268 | <th class="date">date</th> |
|
268 | 269 | <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td> |
|
269 | 270 | </tr> |
|
270 | 271 | <tr> |
|
271 | 272 | <th class="author">parents</th> |
|
272 | 273 | <td class="author"></td> |
|
273 | 274 | </tr> |
|
274 | 275 | <tr> |
|
275 | 276 | <th class="author">children</th> |
|
276 | 277 | <td class="author"></td> |
|
277 | 278 | </tr> |
|
278 | 279 | </table> |
|
279 | 280 | |
|
280 | 281 | <div class="overflow"> |
|
281 | 282 | <table class="bigtable"> |
|
282 | 283 | <thead> |
|
283 | 284 | <tr> |
|
284 | 285 | <th class="annotate">rev</th> |
|
285 | 286 | <th class="line"> line source</th> |
|
286 | 287 | </tr> |
|
287 | 288 | </thead> |
|
288 | 289 | <tbody class="stripes2"> |
|
289 | 290 | |
|
290 | 291 | <tr id="l1" class="thisrev"> |
|
291 | 292 | <td class="annotate parity0"> |
|
292 | 293 | <a href="/annotate/06824edf55d0/primes.py#l1"> |
|
293 | 294 | 0 |
|
294 | 295 | </a> |
|
295 | 296 | <div class="annotate-info"> |
|
296 | 297 | <div> |
|
297 | 298 | <a href="/annotate/06824edf55d0/primes.py#l1"> |
|
298 | 299 | 06824edf55d0</a> |
|
299 | 300 | a |
|
300 | 301 | </div> |
|
301 | 302 | <div><em>test</em></div> |
|
302 | 303 | <div>parents: </div> |
|
303 | 304 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
304 | 305 | <a href="/rev/06824edf55d0">changeset</a> |
|
305 | 306 | </div> |
|
306 | 307 | </td> |
|
307 | 308 | <td class="source"><a href="#l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> |
|
308 | 309 | </tr> |
|
309 | 310 | <tr id="l2" class="thisrev"> |
|
310 | 311 | <td class="annotate parity0"> |
|
311 | 312 | |
|
312 | 313 | <div class="annotate-info"> |
|
313 | 314 | <div> |
|
314 | 315 | <a href="/annotate/06824edf55d0/primes.py#l2"> |
|
315 | 316 | 06824edf55d0</a> |
|
316 | 317 | a |
|
317 | 318 | </div> |
|
318 | 319 | <div><em>test</em></div> |
|
319 | 320 | <div>parents: </div> |
|
320 | 321 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
321 | 322 | <a href="/rev/06824edf55d0">changeset</a> |
|
322 | 323 | </div> |
|
323 | 324 | </td> |
|
324 | 325 | <td class="source"><a href="#l2"> 2</a> </td> |
|
325 | 326 | </tr> |
|
326 | 327 | <tr id="l3" class="thisrev"> |
|
327 | 328 | <td class="annotate parity0"> |
|
328 | 329 | |
|
329 | 330 | <div class="annotate-info"> |
|
330 | 331 | <div> |
|
331 | 332 | <a href="/annotate/06824edf55d0/primes.py#l3"> |
|
332 | 333 | 06824edf55d0</a> |
|
333 | 334 | a |
|
334 | 335 | </div> |
|
335 | 336 | <div><em>test</em></div> |
|
336 | 337 | <div>parents: </div> |
|
337 | 338 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
338 | 339 | <a href="/rev/06824edf55d0">changeset</a> |
|
339 | 340 | </div> |
|
340 | 341 | </td> |
|
341 | 342 | <td class="source"><a href="#l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></td> |
|
342 | 343 | </tr> |
|
343 | 344 | <tr id="l4" class="thisrev"> |
|
344 | 345 | <td class="annotate parity0"> |
|
345 | 346 | |
|
346 | 347 | <div class="annotate-info"> |
|
347 | 348 | <div> |
|
348 | 349 | <a href="/annotate/06824edf55d0/primes.py#l4"> |
|
349 | 350 | 06824edf55d0</a> |
|
350 | 351 | a |
|
351 | 352 | </div> |
|
352 | 353 | <div><em>test</em></div> |
|
353 | 354 | <div>parents: </div> |
|
354 | 355 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
355 | 356 | <a href="/rev/06824edf55d0">changeset</a> |
|
356 | 357 | </div> |
|
357 | 358 | </td> |
|
358 | 359 | <td class="source"><a href="#l4"> 4</a> </td> |
|
359 | 360 | </tr> |
|
360 | 361 | <tr id="l5" class="thisrev"> |
|
361 | 362 | <td class="annotate parity0"> |
|
362 | 363 | |
|
363 | 364 | <div class="annotate-info"> |
|
364 | 365 | <div> |
|
365 | 366 | <a href="/annotate/06824edf55d0/primes.py#l5"> |
|
366 | 367 | 06824edf55d0</a> |
|
367 | 368 | a |
|
368 | 369 | </div> |
|
369 | 370 | <div><em>test</em></div> |
|
370 | 371 | <div>parents: </div> |
|
371 | 372 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
372 | 373 | <a href="/rev/06824edf55d0">changeset</a> |
|
373 | 374 | </div> |
|
374 | 375 | </td> |
|
375 | 376 | <td class="source"><a href="#l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></td> |
|
376 | 377 | </tr> |
|
377 | 378 | <tr id="l6" class="thisrev"> |
|
378 | 379 | <td class="annotate parity0"> |
|
379 | 380 | |
|
380 | 381 | <div class="annotate-info"> |
|
381 | 382 | <div> |
|
382 | 383 | <a href="/annotate/06824edf55d0/primes.py#l6"> |
|
383 | 384 | 06824edf55d0</a> |
|
384 | 385 | a |
|
385 | 386 | </div> |
|
386 | 387 | <div><em>test</em></div> |
|
387 | 388 | <div>parents: </div> |
|
388 | 389 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
389 | 390 | <a href="/rev/06824edf55d0">changeset</a> |
|
390 | 391 | </div> |
|
391 | 392 | </td> |
|
392 | 393 | <td class="source"><a href="#l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></td> |
|
393 | 394 | </tr> |
|
394 | 395 | <tr id="l7" class="thisrev"> |
|
395 | 396 | <td class="annotate parity0"> |
|
396 | 397 | |
|
397 | 398 | <div class="annotate-info"> |
|
398 | 399 | <div> |
|
399 | 400 | <a href="/annotate/06824edf55d0/primes.py#l7"> |
|
400 | 401 | 06824edf55d0</a> |
|
401 | 402 | a |
|
402 | 403 | </div> |
|
403 | 404 | <div><em>test</em></div> |
|
404 | 405 | <div>parents: </div> |
|
405 | 406 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
406 | 407 | <a href="/rev/06824edf55d0">changeset</a> |
|
407 | 408 | </div> |
|
408 | 409 | </td> |
|
409 | 410 | <td class="source"><a href="#l7"> 7</a> <span class="sd">"""</span></td> |
|
410 | 411 | </tr> |
|
411 | 412 | <tr id="l8" class="thisrev"> |
|
412 | 413 | <td class="annotate parity0"> |
|
413 | 414 | |
|
414 | 415 | <div class="annotate-info"> |
|
415 | 416 | <div> |
|
416 | 417 | <a href="/annotate/06824edf55d0/primes.py#l8"> |
|
417 | 418 | 06824edf55d0</a> |
|
418 | 419 | a |
|
419 | 420 | </div> |
|
420 | 421 | <div><em>test</em></div> |
|
421 | 422 | <div>parents: </div> |
|
422 | 423 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
423 | 424 | <a href="/rev/06824edf55d0">changeset</a> |
|
424 | 425 | </div> |
|
425 | 426 | </td> |
|
426 | 427 | <td class="source"><a href="#l8"> 8</a> </td> |
|
427 | 428 | </tr> |
|
428 | 429 | <tr id="l9" class="thisrev"> |
|
429 | 430 | <td class="annotate parity0"> |
|
430 | 431 | |
|
431 | 432 | <div class="annotate-info"> |
|
432 | 433 | <div> |
|
433 | 434 | <a href="/annotate/06824edf55d0/primes.py#l9"> |
|
434 | 435 | 06824edf55d0</a> |
|
435 | 436 | a |
|
436 | 437 | </div> |
|
437 | 438 | <div><em>test</em></div> |
|
438 | 439 | <div>parents: </div> |
|
439 | 440 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
440 | 441 | <a href="/rev/06824edf55d0">changeset</a> |
|
441 | 442 | </div> |
|
442 | 443 | </td> |
|
443 | 444 | <td class="source"><a href="#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> |
|
444 | 445 | </tr> |
|
445 | 446 | <tr id="l10" class="thisrev"> |
|
446 | 447 | <td class="annotate parity0"> |
|
447 | 448 | |
|
448 | 449 | <div class="annotate-info"> |
|
449 | 450 | <div> |
|
450 | 451 | <a href="/annotate/06824edf55d0/primes.py#l10"> |
|
451 | 452 | 06824edf55d0</a> |
|
452 | 453 | a |
|
453 | 454 | </div> |
|
454 | 455 | <div><em>test</em></div> |
|
455 | 456 | <div>parents: </div> |
|
456 | 457 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
457 | 458 | <a href="/rev/06824edf55d0">changeset</a> |
|
458 | 459 | </div> |
|
459 | 460 | </td> |
|
460 | 461 | <td class="source"><a href="#l10"> 10</a> </td> |
|
461 | 462 | </tr> |
|
462 | 463 | <tr id="l11" class="thisrev"> |
|
463 | 464 | <td class="annotate parity0"> |
|
464 | 465 | |
|
465 | 466 | <div class="annotate-info"> |
|
466 | 467 | <div> |
|
467 | 468 | <a href="/annotate/06824edf55d0/primes.py#l11"> |
|
468 | 469 | 06824edf55d0</a> |
|
469 | 470 | a |
|
470 | 471 | </div> |
|
471 | 472 | <div><em>test</em></div> |
|
472 | 473 | <div>parents: </div> |
|
473 | 474 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
474 | 475 | <a href="/rev/06824edf55d0">changeset</a> |
|
475 | 476 | </div> |
|
476 | 477 | </td> |
|
477 | 478 | <td class="source"><a href="#l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></td> |
|
478 | 479 | </tr> |
|
479 | 480 | <tr id="l12" class="thisrev"> |
|
480 | 481 | <td class="annotate parity0"> |
|
481 | 482 | |
|
482 | 483 | <div class="annotate-info"> |
|
483 | 484 | <div> |
|
484 | 485 | <a href="/annotate/06824edf55d0/primes.py#l12"> |
|
485 | 486 | 06824edf55d0</a> |
|
486 | 487 | a |
|
487 | 488 | </div> |
|
488 | 489 | <div><em>test</em></div> |
|
489 | 490 | <div>parents: </div> |
|
490 | 491 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
491 | 492 | <a href="/rev/06824edf55d0">changeset</a> |
|
492 | 493 | </div> |
|
493 | 494 | </td> |
|
494 | 495 | <td class="source"><a href="#l12"> 12</a> <span class="sd">"""Generate all primes."""</span></td> |
|
495 | 496 | </tr> |
|
496 | 497 | <tr id="l13" class="thisrev"> |
|
497 | 498 | <td class="annotate parity0"> |
|
498 | 499 | |
|
499 | 500 | <div class="annotate-info"> |
|
500 | 501 | <div> |
|
501 | 502 | <a href="/annotate/06824edf55d0/primes.py#l13"> |
|
502 | 503 | 06824edf55d0</a> |
|
503 | 504 | a |
|
504 | 505 | </div> |
|
505 | 506 | <div><em>test</em></div> |
|
506 | 507 | <div>parents: </div> |
|
507 | 508 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
508 | 509 | <a href="/rev/06824edf55d0">changeset</a> |
|
509 | 510 | </div> |
|
510 | 511 | </td> |
|
511 | 512 | <td class="source"><a href="#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> |
|
512 | 513 | </tr> |
|
513 | 514 | <tr id="l14" class="thisrev"> |
|
514 | 515 | <td class="annotate parity0"> |
|
515 | 516 | |
|
516 | 517 | <div class="annotate-info"> |
|
517 | 518 | <div> |
|
518 | 519 | <a href="/annotate/06824edf55d0/primes.py#l14"> |
|
519 | 520 | 06824edf55d0</a> |
|
520 | 521 | a |
|
521 | 522 | </div> |
|
522 | 523 | <div><em>test</em></div> |
|
523 | 524 | <div>parents: </div> |
|
524 | 525 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
525 | 526 | <a href="/rev/06824edf55d0">changeset</a> |
|
526 | 527 | </div> |
|
527 | 528 | </td> |
|
528 | 529 | <td class="source"><a href="#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> |
|
529 | 530 | </tr> |
|
530 | 531 | <tr id="l15" class="thisrev"> |
|
531 | 532 | <td class="annotate parity0"> |
|
532 | 533 | |
|
533 | 534 | <div class="annotate-info"> |
|
534 | 535 | <div> |
|
535 | 536 | <a href="/annotate/06824edf55d0/primes.py#l15"> |
|
536 | 537 | 06824edf55d0</a> |
|
537 | 538 | a |
|
538 | 539 | </div> |
|
539 | 540 | <div><em>test</em></div> |
|
540 | 541 | <div>parents: </div> |
|
541 | 542 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
542 | 543 | <a href="/rev/06824edf55d0">changeset</a> |
|
543 | 544 | </div> |
|
544 | 545 | </td> |
|
545 | 546 | <td class="source"><a href="#l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></td> |
|
546 | 547 | </tr> |
|
547 | 548 | <tr id="l16" class="thisrev"> |
|
548 | 549 | <td class="annotate parity0"> |
|
549 | 550 | |
|
550 | 551 | <div class="annotate-info"> |
|
551 | 552 | <div> |
|
552 | 553 | <a href="/annotate/06824edf55d0/primes.py#l16"> |
|
553 | 554 | 06824edf55d0</a> |
|
554 | 555 | a |
|
555 | 556 | </div> |
|
556 | 557 | <div><em>test</em></div> |
|
557 | 558 | <div>parents: </div> |
|
558 | 559 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
559 | 560 | <a href="/rev/06824edf55d0">changeset</a> |
|
560 | 561 | </div> |
|
561 | 562 | </td> |
|
562 | 563 | <td class="source"><a href="#l16"> 16</a> <span class="c"># infinite recursion.</span></td> |
|
563 | 564 | </tr> |
|
564 | 565 | <tr id="l17" class="thisrev"> |
|
565 | 566 | <td class="annotate parity0"> |
|
566 | 567 | |
|
567 | 568 | <div class="annotate-info"> |
|
568 | 569 | <div> |
|
569 | 570 | <a href="/annotate/06824edf55d0/primes.py#l17"> |
|
570 | 571 | 06824edf55d0</a> |
|
571 | 572 | a |
|
572 | 573 | </div> |
|
573 | 574 | <div><em>test</em></div> |
|
574 | 575 | <div>parents: </div> |
|
575 | 576 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
576 | 577 | <a href="/rev/06824edf55d0">changeset</a> |
|
577 | 578 | </div> |
|
578 | 579 | </td> |
|
579 | 580 | <td class="source"><a href="#l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></td> |
|
580 | 581 | </tr> |
|
581 | 582 | <tr id="l18" class="thisrev"> |
|
582 | 583 | <td class="annotate parity0"> |
|
583 | 584 | |
|
584 | 585 | <div class="annotate-info"> |
|
585 | 586 | <div> |
|
586 | 587 | <a href="/annotate/06824edf55d0/primes.py#l18"> |
|
587 | 588 | 06824edf55d0</a> |
|
588 | 589 | a |
|
589 | 590 | </div> |
|
590 | 591 | <div><em>test</em></div> |
|
591 | 592 | <div>parents: </div> |
|
592 | 593 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
593 | 594 | <a href="/rev/06824edf55d0">changeset</a> |
|
594 | 595 | </div> |
|
595 | 596 | </td> |
|
596 | 597 | <td class="source"><a href="#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></td> |
|
597 | 598 | </tr> |
|
598 | 599 | <tr id="l19" class="thisrev"> |
|
599 | 600 | <td class="annotate parity0"> |
|
600 | 601 | |
|
601 | 602 | <div class="annotate-info"> |
|
602 | 603 | <div> |
|
603 | 604 | <a href="/annotate/06824edf55d0/primes.py#l19"> |
|
604 | 605 | 06824edf55d0</a> |
|
605 | 606 | a |
|
606 | 607 | </div> |
|
607 | 608 | <div><em>test</em></div> |
|
608 | 609 | <div>parents: </div> |
|
609 | 610 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
610 | 611 | <a href="/rev/06824edf55d0">changeset</a> |
|
611 | 612 | </div> |
|
612 | 613 | </td> |
|
613 | 614 | <td class="source"><a href="#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> |
|
614 | 615 | </tr> |
|
615 | 616 | <tr id="l20" class="thisrev"> |
|
616 | 617 | <td class="annotate parity0"> |
|
617 | 618 | |
|
618 | 619 | <div class="annotate-info"> |
|
619 | 620 | <div> |
|
620 | 621 | <a href="/annotate/06824edf55d0/primes.py#l20"> |
|
621 | 622 | 06824edf55d0</a> |
|
622 | 623 | a |
|
623 | 624 | </div> |
|
624 | 625 | <div><em>test</em></div> |
|
625 | 626 | <div>parents: </div> |
|
626 | 627 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
627 | 628 | <a href="/rev/06824edf55d0">changeset</a> |
|
628 | 629 | </div> |
|
629 | 630 | </td> |
|
630 | 631 | <td class="source"><a href="#l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></td> |
|
631 | 632 | </tr> |
|
632 | 633 | <tr id="l21" class="thisrev"> |
|
633 | 634 | <td class="annotate parity0"> |
|
634 | 635 | |
|
635 | 636 | <div class="annotate-info"> |
|
636 | 637 | <div> |
|
637 | 638 | <a href="/annotate/06824edf55d0/primes.py#l21"> |
|
638 | 639 | 06824edf55d0</a> |
|
639 | 640 | a |
|
640 | 641 | </div> |
|
641 | 642 | <div><em>test</em></div> |
|
642 | 643 | <div>parents: </div> |
|
643 | 644 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
644 | 645 | <a href="/rev/06824edf55d0">changeset</a> |
|
645 | 646 | </div> |
|
646 | 647 | </td> |
|
647 | 648 | <td class="source"><a href="#l21"> 21</a> </td> |
|
648 | 649 | </tr> |
|
649 | 650 | <tr id="l22" class="thisrev"> |
|
650 | 651 | <td class="annotate parity0"> |
|
651 | 652 | |
|
652 | 653 | <div class="annotate-info"> |
|
653 | 654 | <div> |
|
654 | 655 | <a href="/annotate/06824edf55d0/primes.py#l22"> |
|
655 | 656 | 06824edf55d0</a> |
|
656 | 657 | a |
|
657 | 658 | </div> |
|
658 | 659 | <div><em>test</em></div> |
|
659 | 660 | <div>parents: </div> |
|
660 | 661 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
661 | 662 | <a href="/rev/06824edf55d0">changeset</a> |
|
662 | 663 | </div> |
|
663 | 664 | </td> |
|
664 | 665 | <td class="source"><a href="#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></td> |
|
665 | 666 | </tr> |
|
666 | 667 | <tr id="l23" class="thisrev"> |
|
667 | 668 | <td class="annotate parity0"> |
|
668 | 669 | |
|
669 | 670 | <div class="annotate-info"> |
|
670 | 671 | <div> |
|
671 | 672 | <a href="/annotate/06824edf55d0/primes.py#l23"> |
|
672 | 673 | 06824edf55d0</a> |
|
673 | 674 | a |
|
674 | 675 | </div> |
|
675 | 676 | <div><em>test</em></div> |
|
676 | 677 | <div>parents: </div> |
|
677 | 678 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
678 | 679 | <a href="/rev/06824edf55d0">changeset</a> |
|
679 | 680 | </div> |
|
680 | 681 | </td> |
|
681 | 682 | <td class="source"><a href="#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></td> |
|
682 | 683 | </tr> |
|
683 | 684 | <tr id="l24" class="thisrev"> |
|
684 | 685 | <td class="annotate parity0"> |
|
685 | 686 | |
|
686 | 687 | <div class="annotate-info"> |
|
687 | 688 | <div> |
|
688 | 689 | <a href="/annotate/06824edf55d0/primes.py#l24"> |
|
689 | 690 | 06824edf55d0</a> |
|
690 | 691 | a |
|
691 | 692 | </div> |
|
692 | 693 | <div><em>test</em></div> |
|
693 | 694 | <div>parents: </div> |
|
694 | 695 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
695 | 696 | <a href="/rev/06824edf55d0">changeset</a> |
|
696 | 697 | </div> |
|
697 | 698 | </td> |
|
698 | 699 | <td class="source"><a href="#l24"> 24</a> </td> |
|
699 | 700 | </tr> |
|
700 | 701 | <tr id="l25" class="thisrev"> |
|
701 | 702 | <td class="annotate parity0"> |
|
702 | 703 | |
|
703 | 704 | <div class="annotate-info"> |
|
704 | 705 | <div> |
|
705 | 706 | <a href="/annotate/06824edf55d0/primes.py#l25"> |
|
706 | 707 | 06824edf55d0</a> |
|
707 | 708 | a |
|
708 | 709 | </div> |
|
709 | 710 | <div><em>test</em></div> |
|
710 | 711 | <div>parents: </div> |
|
711 | 712 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
712 | 713 | <a href="/rev/06824edf55d0">changeset</a> |
|
713 | 714 | </div> |
|
714 | 715 | </td> |
|
715 | 716 | <td class="source"><a href="#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> |
|
716 | 717 | </tr> |
|
717 | 718 | <tr id="l26" class="thisrev"> |
|
718 | 719 | <td class="annotate parity0"> |
|
719 | 720 | |
|
720 | 721 | <div class="annotate-info"> |
|
721 | 722 | <div> |
|
722 | 723 | <a href="/annotate/06824edf55d0/primes.py#l26"> |
|
723 | 724 | 06824edf55d0</a> |
|
724 | 725 | a |
|
725 | 726 | </div> |
|
726 | 727 | <div><em>test</em></div> |
|
727 | 728 | <div>parents: </div> |
|
728 | 729 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
729 | 730 | <a href="/rev/06824edf55d0">changeset</a> |
|
730 | 731 | </div> |
|
731 | 732 | </td> |
|
732 | 733 | <td class="source"><a href="#l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></td> |
|
733 | 734 | </tr> |
|
734 | 735 | <tr id="l27" class="thisrev"> |
|
735 | 736 | <td class="annotate parity0"> |
|
736 | 737 | |
|
737 | 738 | <div class="annotate-info"> |
|
738 | 739 | <div> |
|
739 | 740 | <a href="/annotate/06824edf55d0/primes.py#l27"> |
|
740 | 741 | 06824edf55d0</a> |
|
741 | 742 | a |
|
742 | 743 | </div> |
|
743 | 744 | <div><em>test</em></div> |
|
744 | 745 | <div>parents: </div> |
|
745 | 746 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
746 | 747 | <a href="/rev/06824edf55d0">changeset</a> |
|
747 | 748 | </div> |
|
748 | 749 | </td> |
|
749 | 750 | <td class="source"><a href="#l27"> 27</a> <span class="kn">try</span><span class="p">:</span></td> |
|
750 | 751 | </tr> |
|
751 | 752 | <tr id="l28" class="thisrev"> |
|
752 | 753 | <td class="annotate parity0"> |
|
753 | 754 | |
|
754 | 755 | <div class="annotate-info"> |
|
755 | 756 | <div> |
|
756 | 757 | <a href="/annotate/06824edf55d0/primes.py#l28"> |
|
757 | 758 | 06824edf55d0</a> |
|
758 | 759 | a |
|
759 | 760 | </div> |
|
760 | 761 | <div><em>test</em></div> |
|
761 | 762 | <div>parents: </div> |
|
762 | 763 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
763 | 764 | <a href="/rev/06824edf55d0">changeset</a> |
|
764 | 765 | </div> |
|
765 | 766 | </td> |
|
766 | 767 | <td class="source"><a href="#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></td> |
|
767 | 768 | </tr> |
|
768 | 769 | <tr id="l29" class="thisrev"> |
|
769 | 770 | <td class="annotate parity0"> |
|
770 | 771 | |
|
771 | 772 | <div class="annotate-info"> |
|
772 | 773 | <div> |
|
773 | 774 | <a href="/annotate/06824edf55d0/primes.py#l29"> |
|
774 | 775 | 06824edf55d0</a> |
|
775 | 776 | a |
|
776 | 777 | </div> |
|
777 | 778 | <div><em>test</em></div> |
|
778 | 779 | <div>parents: </div> |
|
779 | 780 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
780 | 781 | <a href="/rev/06824edf55d0">changeset</a> |
|
781 | 782 | </div> |
|
782 | 783 | </td> |
|
783 | 784 | <td class="source"><a href="#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> |
|
784 | 785 | </tr> |
|
785 | 786 | <tr id="l30" class="thisrev"> |
|
786 | 787 | <td class="annotate parity0"> |
|
787 | 788 | |
|
788 | 789 | <div class="annotate-info"> |
|
789 | 790 | <div> |
|
790 | 791 | <a href="/annotate/06824edf55d0/primes.py#l30"> |
|
791 | 792 | 06824edf55d0</a> |
|
792 | 793 | a |
|
793 | 794 | </div> |
|
794 | 795 | <div><em>test</em></div> |
|
795 | 796 | <div>parents: </div> |
|
796 | 797 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
797 | 798 | <a href="/rev/06824edf55d0">changeset</a> |
|
798 | 799 | </div> |
|
799 | 800 | </td> |
|
800 | 801 | <td class="source"><a href="#l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mi">10</span></td> |
|
801 | 802 | </tr> |
|
802 | 803 | <tr id="l31" class="thisrev"> |
|
803 | 804 | <td class="annotate parity0"> |
|
804 | 805 | |
|
805 | 806 | <div class="annotate-info"> |
|
806 | 807 | <div> |
|
807 | 808 | <a href="/annotate/06824edf55d0/primes.py#l31"> |
|
808 | 809 | 06824edf55d0</a> |
|
809 | 810 | a |
|
810 | 811 | </div> |
|
811 | 812 | <div><em>test</em></div> |
|
812 | 813 | <div>parents: </div> |
|
813 | 814 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
814 | 815 | <a href="/rev/06824edf55d0">changeset</a> |
|
815 | 816 | </div> |
|
816 | 817 | </td> |
|
817 | 818 | <td class="source"><a href="#l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></td> |
|
818 | 819 | </tr> |
|
819 | 820 | <tr id="l32" class="thisrev"> |
|
820 | 821 | <td class="annotate parity0"> |
|
821 | 822 | |
|
822 | 823 | <div class="annotate-info"> |
|
823 | 824 | <div> |
|
824 | 825 | <a href="/annotate/06824edf55d0/primes.py#l32"> |
|
825 | 826 | 06824edf55d0</a> |
|
826 | 827 | a |
|
827 | 828 | </div> |
|
828 | 829 | <div><em>test</em></div> |
|
829 | 830 | <div>parents: </div> |
|
830 | 831 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
831 | 832 | <a href="/rev/06824edf55d0">changeset</a> |
|
832 | 833 | </div> |
|
833 | 834 | </td> |
|
834 | 835 | <td class="source"><a href="#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> |
|
835 | 836 | </tr> |
|
836 | 837 | <tr id="l33" class="thisrev"> |
|
837 | 838 | <td class="annotate parity0"> |
|
838 | 839 | |
|
839 | 840 | <div class="annotate-info"> |
|
840 | 841 | <div> |
|
841 | 842 | <a href="/annotate/06824edf55d0/primes.py#l33"> |
|
842 | 843 | 06824edf55d0</a> |
|
843 | 844 | a |
|
844 | 845 | </div> |
|
845 | 846 | <div><em>test</em></div> |
|
846 | 847 | <div>parents: </div> |
|
847 | 848 | <a href="/diff/06824edf55d0/primes.py">diff</a> |
|
848 | 849 | <a href="/rev/06824edf55d0">changeset</a> |
|
849 | 850 | </div> |
|
850 | 851 | </td> |
|
851 | 852 | <td class="source"><a href="#l33"> 33</a> </td> |
|
852 | 853 | </tr> |
|
853 | 854 | </tbody> |
|
854 | 855 | </table> |
|
855 | 856 | </div> |
|
856 | 857 | </div> |
|
857 | 858 | </div> |
|
858 | 859 | |
|
859 | 860 | |
|
860 | 861 | |
|
861 | 862 | </body> |
|
862 | 863 | </html> |
|
863 | 864 | |
|
864 | 865 | |
|
865 | 866 | hgweb fileannotate, raw |
|
866 | 867 | |
|
867 | 868 | $ (get-with-headers.py localhost:$HGPORT 'annotate/tip/primes.py?style=raw') \ |
|
868 | 869 | > | sed "s/test@//" > a |
|
869 | 870 | $ echo "200 Script output follows" > b |
|
870 | 871 | $ echo "" >> b |
|
871 | 872 | $ echo "" >> b |
|
872 | 873 | $ hg annotate "primes.py" >> b |
|
873 | 874 | $ echo "" >> b |
|
874 | 875 | $ echo "" >> b |
|
875 | 876 | $ echo "" >> b |
|
876 | 877 | $ echo "" >> b |
|
877 | 878 | $ cmp b a || diff -u b a |
|
878 | 879 | |
|
879 | 880 | hgweb filerevision, raw |
|
880 | 881 | |
|
881 | 882 | $ (get-with-headers.py localhost:$HGPORT 'file/tip/primes.py?style=raw') \ |
|
882 | 883 | > > a |
|
883 | 884 | $ echo "200 Script output follows" > b |
|
884 | 885 | $ echo "" >> b |
|
885 | 886 | $ hg cat primes.py >> b |
|
886 | 887 | $ cmp b a || diff -u b a |
|
887 | 888 | |
|
888 | 889 | hgweb highlightcss friendly |
|
889 | 890 | |
|
890 | 891 | $ get-with-headers.py localhost:$HGPORT 'highlightcss' > out |
|
891 | 892 | $ head -n 4 out |
|
892 | 893 | 200 Script output follows |
|
893 | 894 | |
|
894 | 895 | /* pygments_style = friendly */ |
|
895 | 896 | |
|
896 | 897 | $ rm out |
|
897 | 898 | |
|
898 | 899 | errors encountered |
|
899 | 900 | |
|
900 | 901 | $ cat errors.log |
|
901 | 902 | $ killdaemons.py |
|
902 | 903 | |
|
903 | 904 | Change the pygments style |
|
904 | 905 | |
|
905 | 906 | $ cat > .hg/hgrc <<EOF |
|
906 | 907 | > [web] |
|
907 | 908 | > pygments_style = fruity |
|
908 | 909 | > EOF |
|
909 | 910 | |
|
910 | 911 | hg serve again |
|
911 | 912 | |
|
912 | 913 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
913 | 914 | $ cat hg.pid >> $DAEMON_PIDS |
|
914 | 915 | |
|
915 | 916 | hgweb highlightcss fruity |
|
916 | 917 | |
|
917 | 918 | $ get-with-headers.py localhost:$HGPORT 'highlightcss' > out |
|
918 | 919 | $ head -n 4 out |
|
919 | 920 | 200 Script output follows |
|
920 | 921 | |
|
921 | 922 | /* pygments_style = fruity */ |
|
922 | 923 | |
|
923 | 924 | $ rm out |
|
924 | 925 | |
|
925 | 926 | errors encountered |
|
926 | 927 | |
|
927 | 928 | $ cat errors.log |
|
928 | 929 | $ killdaemons.py |
|
929 | 930 | |
|
930 | 931 | only highlight C source files |
|
931 | 932 | |
|
932 | 933 | $ cat > .hg/hgrc <<EOF |
|
933 | 934 | > [web] |
|
934 | 935 | > highlightfiles = **.c |
|
935 | 936 | > EOF |
|
936 | 937 | |
|
937 | 938 | hg serve again |
|
938 | 939 | |
|
939 | 940 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid -A access.log -E errors.log |
|
940 | 941 | $ cat hg.pid >> $DAEMON_PIDS |
|
941 | 942 | |
|
942 | 943 | test that fileset in highlightfiles works and primes.py is not highlighted |
|
943 | 944 | |
|
944 | 945 | $ get-with-headers.py localhost:$HGPORT 'file/tip/primes.py' | grep 'id="l11"' |
|
945 | 946 | <span id="l11">def primes():</span><a href="#l11"></a> |
|
946 | 947 | |
|
947 | 948 | errors encountered |
|
948 | 949 | |
|
949 | 950 | $ cat errors.log |
|
950 | 951 | $ cd .. |
|
951 | 952 | $ hg init eucjp |
|
952 | 953 | $ cd eucjp |
|
953 | 954 | $ $PYTHON -c 'print("\265\376")' >> eucjp.txt # Japanese kanji "Kyo" |
|
954 | 955 | $ hg ci -Ama |
|
955 | 956 | adding eucjp.txt |
|
956 | 957 | $ hgserveget () { |
|
957 | 958 | > killdaemons.py |
|
958 | 959 | > echo % HGENCODING="$1" hg serve |
|
959 | 960 | > HGENCODING="$1" hg serve -p $HGPORT -d -n test --pid-file=hg.pid -E errors.log |
|
960 | 961 | > cat hg.pid >> $DAEMON_PIDS |
|
961 | 962 | > |
|
962 | 963 | > echo % hgweb filerevision, html |
|
963 | 964 | > get-with-headers.py localhost:$HGPORT "file/tip/$2" \ |
|
964 | 965 | > | grep '<div class="parity0 source">' |
|
965 | 966 | > echo % errors encountered |
|
966 | 967 | > cat errors.log |
|
967 | 968 | > } |
|
968 | 969 | $ hgserveget euc-jp eucjp.txt |
|
969 | 970 | % HGENCODING=euc-jp hg serve |
|
970 | 971 | % hgweb filerevision, html |
|
971 | 972 | % errors encountered |
|
972 | 973 | $ hgserveget utf-8 eucjp.txt |
|
973 | 974 | % HGENCODING=utf-8 hg serve |
|
974 | 975 | % hgweb filerevision, html |
|
975 | 976 | % errors encountered |
|
976 | 977 | $ hgserveget us-ascii eucjp.txt |
|
977 | 978 | % HGENCODING=us-ascii hg serve |
|
978 | 979 | % hgweb filerevision, html |
|
979 | 980 | % errors encountered |
|
980 | 981 | |
|
981 | 982 | We attempt to highlight unknown files by default |
|
982 | 983 | |
|
983 | 984 | $ killdaemons.py |
|
984 | 985 | |
|
985 | 986 | $ cat > .hg/hgrc << EOF |
|
986 | 987 | > [web] |
|
987 | 988 | > highlightfiles = ** |
|
988 | 989 | > EOF |
|
989 | 990 | |
|
990 | 991 | $ cat > unknownfile << EOF |
|
991 | 992 | > #!/usr/bin/python |
|
992 | 993 | > def foo(): |
|
993 | 994 | > pass |
|
994 | 995 | > EOF |
|
995 | 996 | |
|
996 | 997 | $ hg add unknownfile |
|
997 | 998 | $ hg commit -m unknown unknownfile |
|
998 | 999 | |
|
999 | 1000 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid |
|
1000 | 1001 | $ cat hg.pid >> $DAEMON_PIDS |
|
1001 | 1002 | |
|
1002 | 1003 | $ get-with-headers.py localhost:$HGPORT 'file/tip/unknownfile' | grep l2 |
|
1003 | 1004 | <span id="l2"><span class="k">def</span> <span class="nf">foo</span><span class="p">():</span></span><a href="#l2"></a> |
|
1004 | 1005 | |
|
1005 | 1006 | We can prevent Pygments from falling back to a non filename-based |
|
1006 | 1007 | detection mode |
|
1007 | 1008 | |
|
1008 | 1009 | $ cat > .hg/hgrc << EOF |
|
1009 | 1010 | > [web] |
|
1010 | 1011 | > highlightfiles = ** |
|
1011 | 1012 | > highlightonlymatchfilename = true |
|
1012 | 1013 | > EOF |
|
1013 | 1014 | |
|
1014 | 1015 | $ killdaemons.py |
|
1015 | 1016 | $ hg serve -p $HGPORT -d -n test --pid-file=hg.pid |
|
1016 | 1017 | $ cat hg.pid >> $DAEMON_PIDS |
|
1017 | 1018 | $ get-with-headers.py localhost:$HGPORT 'file/tip/unknownfile' | grep l2 |
|
1018 | 1019 | <span id="l2">def foo():</span><a href="#l2"></a> |
|
1019 | 1020 | |
|
1020 | 1021 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now