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