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