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