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