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