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