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