Show More
@@ -11,7 +11,41 b' EOF' | |||||
11 |
|
11 | |||
12 | hg init test |
|
12 | hg init test | |
13 | cd test |
|
13 | cd test | |
14 | cp $TESTDIR/get-with-headers.py ./ |
|
14 | # create random Python file to exercise Pygments | |
|
15 | cat <<EOF > primes.py | |||
|
16 | #!/usr/bin/env python | |||
|
17 | ||||
|
18 | """Fun with generators. Corresponding Haskell implementation: | |||
|
19 | ||||
|
20 | primes = 2 : sieve [3, 5..] | |||
|
21 | where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] | |||
|
22 | """ | |||
|
23 | ||||
|
24 | from itertools import dropwhile, ifilter, islice, count, chain | |||
|
25 | ||||
|
26 | def primes(): | |||
|
27 | """Generate all primes.""" | |||
|
28 | def sieve(ns): | |||
|
29 | p = ns.next() | |||
|
30 | # It is important to yield *here* in order to stop the | |||
|
31 | # infinite recursion. | |||
|
32 | yield p | |||
|
33 | ns = ifilter(lambda n: n % p != 0, ns) | |||
|
34 | for n in sieve(ns): | |||
|
35 | yield n | |||
|
36 | ||||
|
37 | odds = ifilter(lambda i: i % 2 == 1, count()) | |||
|
38 | return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) | |||
|
39 | ||||
|
40 | if __name__ == "__main__": | |||
|
41 | import sys | |||
|
42 | try: | |||
|
43 | n = int(sys.argv[1]) | |||
|
44 | except (ValueError, IndexError): | |||
|
45 | n = 10 | |||
|
46 | p = primes() | |||
|
47 | print "The first %d primes: %s" % (n, list(islice(p, n))) | |||
|
48 | EOF | |||
15 |
|
49 | |||
16 | # check for UnicodeDecodeError with iso-8859-1 file contents |
|
50 | # check for UnicodeDecodeError with iso-8859-1 file contents | |
17 | python -c 'fp = open("isolatin.txt", "w"); fp.write("h\xFCbsch\n"); fp.close();' |
|
51 | python -c 'fp = open("isolatin.txt", "w"); fp.write("h\xFCbsch\n"); fp.close();' | |
@@ -23,7 +57,7 b' hg serve -p $HGPORT -d -n test --pid-fil' | |||||
23 | cat hg.pid >> $DAEMON_PIDS |
|
57 | cat hg.pid >> $DAEMON_PIDS | |
24 |
|
58 | |||
25 | echo % hgweb filerevision, html |
|
59 | echo % hgweb filerevision, html | |
26 |
("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/ |
|
60 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py') \ | |
27 | | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mf\"/class=\"mi\"/g" |
|
61 | | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mf\"/class=\"mi\"/g" | |
28 |
|
62 | |||
29 | echo % hgweb filerevision, html |
|
63 | echo % hgweb filerevision, html | |
@@ -31,17 +65,17 b' echo % hgweb filerevision, html' | |||||
31 | | sed "s/class=\"k\"/class=\"kn\"/g" |
|
65 | | sed "s/class=\"k\"/class=\"kn\"/g" | |
32 |
|
66 | |||
33 | echo % hgweb fileannotate, html |
|
67 | echo % hgweb fileannotate, html | |
34 |
("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/ |
|
68 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py') \ | |
35 | | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mi\"/class=\"mf\"/g" |
|
69 | | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mi\"/class=\"mf\"/g" | |
36 |
|
70 | |||
37 | echo % hgweb fileannotate, raw |
|
71 | echo % hgweb fileannotate, raw | |
38 |
("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/ |
|
72 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py?style=raw') \ | |
39 | | sed "s/test@//" > a |
|
73 | | sed "s/test@//" > a | |
40 |
|
74 | |||
41 | echo "200 Script output follows" > b |
|
75 | echo "200 Script output follows" > b | |
42 | echo "" >> b |
|
76 | echo "" >> b | |
43 | echo "" >> b |
|
77 | echo "" >> b | |
44 |
hg annotate " |
|
78 | hg annotate "primes.py" >> b | |
45 | echo "" >> b |
|
79 | echo "" >> b | |
46 | echo "" >> b |
|
80 | echo "" >> b | |
47 | echo "" >> b |
|
81 | echo "" >> b | |
@@ -51,12 +85,12 b' diff -u b a' | |||||
51 |
|
85 | |||
52 | echo |
|
86 | echo | |
53 | echo % hgweb filerevision, raw |
|
87 | echo % hgweb filerevision, raw | |
54 |
("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/ |
|
88 | ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py?style=raw') \ | |
55 | > a |
|
89 | > a | |
56 |
|
90 | |||
57 | echo "200 Script output follows" > b |
|
91 | echo "200 Script output follows" > b | |
58 | echo "" >> b |
|
92 | echo "" >> b | |
59 |
hg cat |
|
93 | hg cat primes.py >> b | |
60 |
|
94 | |||
61 | diff -u b a |
|
95 | diff -u b a | |
62 |
|
96 |
@@ -1,5 +1,5 b'' | |||||
1 | adding get-with-headers.py |
|
|||
2 | adding isolatin.txt |
|
1 | adding isolatin.txt | |
|
2 | adding primes.py | |||
3 | % hg serve |
|
3 | % hg serve | |
4 | % hgweb filerevision, html |
|
4 | % hgweb filerevision, html | |
5 | 200 Script output follows |
|
5 | 200 Script output follows | |
@@ -12,7 +12,7 b' 200 Script output follows' | |||||
12 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
12 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
13 |
|
13 | |||
14 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
14 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> | |
15 |
<title>test: |
|
15 | <title>test: 3e1445510fe7 primes.py</title> | |
16 | </head> |
|
16 | </head> | |
17 | <body> |
|
17 | <body> | |
18 |
|
18 | |||
@@ -23,27 +23,27 b' 200 Script output follows' | |||||
23 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
23 | <img src="/static/hglogo.png" alt="mercurial" /></a> | |
24 | </div> |
|
24 | </div> | |
25 | <ul> |
|
25 | <ul> | |
26 |
<li><a href="/shortlog/ |
|
26 | <li><a href="/shortlog/3e1445510fe7">log</a></li> | |
27 |
<li><a href="/graph/ |
|
27 | <li><a href="/graph/3e1445510fe7">graph</a></li> | |
28 | <li><a href="/tags">tags</a></li> |
|
28 | <li><a href="/tags">tags</a></li> | |
29 | <li><a href="/branches">branches</a></li> |
|
29 | <li><a href="/branches">branches</a></li> | |
30 | </ul> |
|
30 | </ul> | |
31 | <ul> |
|
31 | <ul> | |
32 |
<li><a href="/rev/ |
|
32 | <li><a href="/rev/3e1445510fe7">changeset</a></li> | |
33 |
<li><a href="/file/ |
|
33 | <li><a href="/file/3e1445510fe7/">browse</a></li> | |
34 | </ul> |
|
34 | </ul> | |
35 | <ul> |
|
35 | <ul> | |
36 | <li class="active">file</li> |
|
36 | <li class="active">file</li> | |
37 |
<li><a href="/diff/ |
|
37 | <li><a href="/diff/3e1445510fe7/primes.py">diff</a></li> | |
38 |
<li><a href="/annotate/ |
|
38 | <li><a href="/annotate/3e1445510fe7/primes.py">annotate</a></li> | |
39 |
<li><a href="/log/ |
|
39 | <li><a href="/log/3e1445510fe7/primes.py">file log</a></li> | |
40 |
<li><a href="/raw-file/ |
|
40 | <li><a href="/raw-file/3e1445510fe7/primes.py">raw</a></li> | |
41 | </ul> |
|
41 | </ul> | |
42 | </div> |
|
42 | </div> | |
43 |
|
43 | |||
44 | <div class="main"> |
|
44 | <div class="main"> | |
45 | <h2><a href="/">test</a></h2> |
|
45 | <h2><a href="/">test</a></h2> | |
46 | <h3>view get-with-headers.py @ 0:93b701795893</h3> |
|
46 | <h3>view primes.py @ 0:3e1445510fe7</h3> | |
47 |
|
47 | |||
48 | <form class="search" action="/log"> |
|
48 | <form class="search" action="/log"> | |
49 |
|
49 | |||
@@ -76,7 +76,7 b' files, or words in the commit message</d' | |||||
76 |
|
76 | |||
77 | <div class="overflow"> |
|
77 | <div class="overflow"> | |
78 | <div class="sourcefirst"> line source</div> |
|
78 | <div class="sourcefirst"> line source</div> | |
79 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></div><div class="parity1 source"><a href="#l2" id="l2"> 2</a> </div><div class="parity0 source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""This does HTTP GET requests given a host:port and path and returns</span></div><div class="parity1 source"><a href="#l4" id="l4"> 4</a> <span class="sd">a subset of the headers plus the body of the result."""</span></div><div class="parity0 source"><a href="#l5" id="l5"> 5</a> </div><div class="parity1 source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></div><div class="parity0 source"><a href="#l7" id="l7"> 7</a> </div><div class="parity1 source"><a href="#l8" id="l8"> 8</a> <span class="kn">try</span><span class="p">:</span></div><div class="parity0 source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></div><div class="parity1 source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity0 source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></div><div class="parity1 source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></div><div class="parity0 source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></div><div class="parity1 source"><a href="#l14" id="l14"> 14</a> </div><div class="parity0 source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">3</span><span class="p">:]]</span></div><div class="parity1 source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></div><div class="parity0 source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</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">2</span><span class="p">])</span></div><div class="parity1 source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></div><div class="parity0 source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></div><div class="parity1 source"><a href="#l20" id="l20"> 20</a> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span></div><div class="parity0 source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></div><div class="parity1 source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></div><div class="parity0 source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></div><div class="parity1 source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></div><div class="parity0 source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">'\d+ years'</span><span class="p">,</span> <span class="s">'many years'</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></div><div class="parity1 source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></div><div class="parity0 source"><a href="#l27" id="l27"> 27</a> </div><div class="parity1 source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mi">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mi">299</span><span class="p">:</span></div><div class="parity0 source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div><div class="parity1 source"><a href="#l30" id="l30"> 30</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></div> |
|
79 | <div class="parity0 source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></div><div class="parity1 source"><a href="#l2" id="l2"> 2</a> </div><div class="parity0 source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></div><div class="parity1 source"><a href="#l4" id="l4"> 4</a> </div><div class="parity0 source"><a href="#l5" id="l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></div><div class="parity1 source"><a href="#l6" id="l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></div><div class="parity0 source"><a href="#l7" id="l7"> 7</a> <span class="sd">"""</span></div><div class="parity1 source"><a href="#l8" id="l8"> 8</a> </div><div class="parity0 source"><a href="#l9" id="l9"> 9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></div><div class="parity1 source"><a href="#l10" id="l10"> 10</a> </div><div class="parity0 source"><a href="#l11" id="l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></div><div class="parity1 source"><a href="#l12" id="l12"> 12</a> <span class="sd">"""Generate all primes."""</span></div><div class="parity0 source"><a href="#l13" id="l13"> 13</a> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></div><div class="parity1 source"><a href="#l14" id="l14"> 14</a> <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></div><div class="parity0 source"><a href="#l15" id="l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></div><div class="parity1 source"><a href="#l16" id="l16"> 16</a> <span class="c"># infinite recursion.</span></div><div class="parity0 source"><a href="#l17" id="l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></div><div class="parity1 source"><a href="#l18" id="l18"> 18</a> <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></div><div class="parity0 source"><a href="#l19" id="l19"> 19</a> <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></div><div class="parity1 source"><a href="#l20" id="l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></div><div class="parity0 source"><a href="#l21" id="l21"> 21</a> </div><div class="parity1 source"><a href="#l22" id="l22"> 22</a> <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></div><div class="parity0 source"><a href="#l23" id="l23"> 23</a> <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mi">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o"><</span> <span class="mi">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></div><div class="parity1 source"><a href="#l24" id="l24"> 24</a> </div><div class="parity0 source"><a href="#l25" id="l25"> 25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></div><div class="parity1 source"><a href="#l26" id="l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></div><div class="parity0 source"><a href="#l27" id="l27"> 27</a> <span class="kn">try</span><span class="p">:</span></div><div class="parity1 source"><a href="#l28" id="l28"> 28</a> <span class="n">n</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></div><div class="parity0 source"><a href="#l29" id="l29"> 29</a> <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></div><div class="parity1 source"><a href="#l30" id="l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mi">10</span></div><div class="parity0 source"><a href="#l31" id="l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></div><div class="parity1 source"><a href="#l32" id="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></div> | |
80 | <div class="sourcelast"></div> |
|
80 | <div class="sourcelast"></div> | |
81 | </div> |
|
81 | </div> | |
82 | </div> |
|
82 | </div> | |
@@ -98,7 +98,7 b' 200 Script output follows' | |||||
98 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
98 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
99 |
|
99 | |||
100 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
100 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> | |
101 |
<title>test: |
|
101 | <title>test: 3e1445510fe7 isolatin.txt</title> | |
102 | </head> |
|
102 | </head> | |
103 | <body> |
|
103 | <body> | |
104 |
|
104 | |||
@@ -109,27 +109,27 b' 200 Script output follows' | |||||
109 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
109 | <img src="/static/hglogo.png" alt="mercurial" /></a> | |
110 | </div> |
|
110 | </div> | |
111 | <ul> |
|
111 | <ul> | |
112 |
<li><a href="/shortlog/ |
|
112 | <li><a href="/shortlog/3e1445510fe7">log</a></li> | |
113 |
<li><a href="/graph/ |
|
113 | <li><a href="/graph/3e1445510fe7">graph</a></li> | |
114 | <li><a href="/tags">tags</a></li> |
|
114 | <li><a href="/tags">tags</a></li> | |
115 | <li><a href="/branches">branches</a></li> |
|
115 | <li><a href="/branches">branches</a></li> | |
116 | </ul> |
|
116 | </ul> | |
117 | <ul> |
|
117 | <ul> | |
118 |
<li><a href="/rev/ |
|
118 | <li><a href="/rev/3e1445510fe7">changeset</a></li> | |
119 |
<li><a href="/file/ |
|
119 | <li><a href="/file/3e1445510fe7/">browse</a></li> | |
120 | </ul> |
|
120 | </ul> | |
121 | <ul> |
|
121 | <ul> | |
122 | <li class="active">file</li> |
|
122 | <li class="active">file</li> | |
123 |
<li><a href="/diff/ |
|
123 | <li><a href="/diff/3e1445510fe7/isolatin.txt">diff</a></li> | |
124 |
<li><a href="/annotate/ |
|
124 | <li><a href="/annotate/3e1445510fe7/isolatin.txt">annotate</a></li> | |
125 |
<li><a href="/log/ |
|
125 | <li><a href="/log/3e1445510fe7/isolatin.txt">file log</a></li> | |
126 |
<li><a href="/raw-file/ |
|
126 | <li><a href="/raw-file/3e1445510fe7/isolatin.txt">raw</a></li> | |
127 | </ul> |
|
127 | </ul> | |
128 | </div> |
|
128 | </div> | |
129 |
|
129 | |||
130 | <div class="main"> |
|
130 | <div class="main"> | |
131 | <h2><a href="/">test</a></h2> |
|
131 | <h2><a href="/">test</a></h2> | |
132 |
<h3>view isolatin.txt @ 0: |
|
132 | <h3>view isolatin.txt @ 0:3e1445510fe7</h3> | |
133 |
|
133 | |||
134 | <form class="search" action="/log"> |
|
134 | <form class="search" action="/log"> | |
135 |
|
135 | |||
@@ -184,7 +184,7 b' 200 Script output follows' | |||||
184 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> |
|
184 | <link rel="stylesheet" href="/static/style-paper.css" type="text/css" /> | |
185 |
|
185 | |||
186 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> |
|
186 | <link rel="stylesheet" href="/highlightcss" type="text/css" /> | |
187 |
<title>test: |
|
187 | <title>test: primes.py annotate</title> | |
188 | </head> |
|
188 | </head> | |
189 | <body> |
|
189 | <body> | |
190 |
|
190 | |||
@@ -195,28 +195,28 b' 200 Script output follows' | |||||
195 | <img src="/static/hglogo.png" alt="mercurial" /></a> |
|
195 | <img src="/static/hglogo.png" alt="mercurial" /></a> | |
196 | </div> |
|
196 | </div> | |
197 | <ul> |
|
197 | <ul> | |
198 |
<li><a href="/shortlog/ |
|
198 | <li><a href="/shortlog/3e1445510fe7">log</a></li> | |
199 |
<li><a href="/graph/ |
|
199 | <li><a href="/graph/3e1445510fe7">graph</a></li> | |
200 | <li><a href="/tags">tags</a></li> |
|
200 | <li><a href="/tags">tags</a></li> | |
201 | <li><a href="/branches">branches</a></li> |
|
201 | <li><a href="/branches">branches</a></li> | |
202 | </ul> |
|
202 | </ul> | |
203 |
|
203 | |||
204 | <ul> |
|
204 | <ul> | |
205 |
<li><a href="/rev/ |
|
205 | <li><a href="/rev/3e1445510fe7">changeset</a></li> | |
206 |
<li><a href="/file/ |
|
206 | <li><a href="/file/3e1445510fe7/">browse</a></li> | |
207 | </ul> |
|
207 | </ul> | |
208 | <ul> |
|
208 | <ul> | |
209 |
<li><a href="/file/ |
|
209 | <li><a href="/file/3e1445510fe7/primes.py">file</a></li> | |
210 |
<li><a href="/diff/ |
|
210 | <li><a href="/diff/3e1445510fe7/primes.py">diff</a></li> | |
211 | <li class="active">annotate</li> |
|
211 | <li class="active">annotate</li> | |
212 |
<li><a href="/log/ |
|
212 | <li><a href="/log/3e1445510fe7/primes.py">file log</a></li> | |
213 |
<li><a href="/raw-annotate/ |
|
213 | <li><a href="/raw-annotate/3e1445510fe7/primes.py">raw</a></li> | |
214 | </ul> |
|
214 | </ul> | |
215 | </div> |
|
215 | </div> | |
216 |
|
216 | |||
217 | <div class="main"> |
|
217 | <div class="main"> | |
218 | <h2><a href="/">test</a></h2> |
|
218 | <h2><a href="/">test</a></h2> | |
219 |
<h3>annotate |
|
219 | <h3>annotate primes.py @ 0:3e1445510fe7</h3> | |
220 |
|
220 | |||
221 | <form class="search" action="/log"> |
|
221 | <form class="search" action="/log"> | |
222 |
|
222 | |||
@@ -258,213 +258,227 b' files, or words in the commit message</d' | |||||
258 |
|
258 | |||
259 | <tr class="parity0"> |
|
259 | <tr class="parity0"> | |
260 | <td class="annotate"> |
|
260 | <td class="annotate"> | |
261 |
<a href="/annotate/ |
|
261 | <a href="/annotate/3e1445510fe7/primes.py#1" | |
262 |
title=" |
|
262 | title="3e1445510fe7: a">test@0</a> | |
263 | </td> |
|
263 | </td> | |
264 | <td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> |
|
264 | <td class="source"><a href="#l1" id="l1"> 1</a> <span class="c">#!/usr/bin/env python</span></td> | |
265 | </tr> |
|
265 | </tr> | |
266 | <tr class="parity1"> |
|
266 | <tr class="parity1"> | |
267 | <td class="annotate"> |
|
267 | <td class="annotate"> | |
268 |
<a href="/annotate/ |
|
268 | <a href="/annotate/3e1445510fe7/primes.py#2" | |
269 |
title=" |
|
269 | title="3e1445510fe7: a">test@0</a> | |
270 | </td> |
|
270 | </td> | |
271 | <td class="source"><a href="#l2" id="l2"> 2</a> </td> |
|
271 | <td class="source"><a href="#l2" id="l2"> 2</a> </td> | |
272 | </tr> |
|
272 | </tr> | |
273 | <tr class="parity0"> |
|
273 | <tr class="parity0"> | |
274 | <td class="annotate"> |
|
274 | <td class="annotate"> | |
275 |
<a href="/annotate/ |
|
275 | <a href="/annotate/3e1445510fe7/primes.py#3" | |
276 |
title=" |
|
276 | title="3e1445510fe7: a">test@0</a> | |
277 | </td> |
|
277 | </td> | |
278 |
<td class="source"><a href="#l3" id="l3"> 3</a> <span class="sd">""" |
|
278 | <td class="source"><a href="#l3" id="l3"> 3</a> <span class="sd">"""Fun with generators. Corresponding Haskell implementation:</span></td> | |
279 | </tr> |
|
279 | </tr> | |
280 | <tr class="parity1"> |
|
280 | <tr class="parity1"> | |
281 | <td class="annotate"> |
|
281 | <td class="annotate"> | |
282 |
<a href="/annotate/ |
|
282 | <a href="/annotate/3e1445510fe7/primes.py#4" | |
283 |
title=" |
|
283 | title="3e1445510fe7: a">test@0</a> | |
284 | </td> |
|
284 | </td> | |
285 | <td class="source"><a href="#l4" id="l4"> 4</a> <span class="sd">a subset of the headers plus the body of the result."""</span></td> |
|
285 | <td class="source"><a href="#l4" id="l4"> 4</a> </td> | |
286 | </tr> |
|
286 | </tr> | |
287 | <tr class="parity0"> |
|
287 | <tr class="parity0"> | |
288 | <td class="annotate"> |
|
288 | <td class="annotate"> | |
289 |
<a href="/annotate/ |
|
289 | <a href="/annotate/3e1445510fe7/primes.py#5" | |
290 |
title=" |
|
290 | title="3e1445510fe7: a">test@0</a> | |
291 | </td> |
|
291 | </td> | |
292 | <td class="source"><a href="#l5" id="l5"> 5</a> </td> |
|
292 | <td class="source"><a href="#l5" id="l5"> 5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></td> | |
293 | </tr> |
|
293 | </tr> | |
294 | <tr class="parity1"> |
|
294 | <tr class="parity1"> | |
295 | <td class="annotate"> |
|
295 | <td class="annotate"> | |
296 |
<a href="/annotate/ |
|
296 | <a href="/annotate/3e1445510fe7/primes.py#6" | |
297 |
title=" |
|
297 | title="3e1445510fe7: a">test@0</a> | |
298 | </td> |
|
298 | </td> | |
299 | <td class="source"><a href="#l6" id="l6"> 6</a> <span class="kn">import</span> <span class="nn">httplib</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span></td> |
|
299 | <td class="source"><a href="#l6" id="l6"> 6</a> <span class="sd"> where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]</span></td> | |
300 | </tr> |
|
300 | </tr> | |
301 | <tr class="parity0"> |
|
301 | <tr class="parity0"> | |
302 | <td class="annotate"> |
|
302 | <td class="annotate"> | |
303 |
<a href="/annotate/ |
|
303 | <a href="/annotate/3e1445510fe7/primes.py#7" | |
304 |
title=" |
|
304 | title="3e1445510fe7: a">test@0</a> | |
305 | </td> |
|
305 | </td> | |
306 | <td class="source"><a href="#l7" id="l7"> 7</a> </td> |
|
306 | <td class="source"><a href="#l7" id="l7"> 7</a> <span class="sd">"""</span></td> | |
307 | </tr> |
|
307 | </tr> | |
308 | <tr class="parity1"> |
|
308 | <tr class="parity1"> | |
309 | <td class="annotate"> |
|
309 | <td class="annotate"> | |
310 |
<a href="/annotate/ |
|
310 | <a href="/annotate/3e1445510fe7/primes.py#8" | |
311 |
title=" |
|
311 | title="3e1445510fe7: a">test@0</a> | |
312 | </td> |
|
312 | </td> | |
313 |
<td class="source"><a href="#l8" id="l8"> 8</a> < |
|
313 | <td class="source"><a href="#l8" id="l8"> 8</a> </td> | |
314 | </tr> |
|
314 | </tr> | |
315 | <tr class="parity0"> |
|
315 | <tr class="parity0"> | |
316 | <td class="annotate"> |
|
316 | <td class="annotate"> | |
317 |
<a href="/annotate/ |
|
317 | <a href="/annotate/3e1445510fe7/primes.py#9" | |
318 |
title=" |
|
318 | title="3e1445510fe7: a">test@0</a> | |
319 | </td> |
|
319 | </td> | |
320 | <td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">import</span> <span class="nn">msvcrt</span><span class="o">,</span> <span class="nn">os</span></td> |
|
320 | <td class="source"><a href="#l9" id="l9"> 9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></td> | |
321 | </tr> |
|
321 | </tr> | |
322 | <tr class="parity1"> |
|
322 | <tr class="parity1"> | |
323 | <td class="annotate"> |
|
323 | <td class="annotate"> | |
324 |
<a href="/annotate/ |
|
324 | <a href="/annotate/3e1445510fe7/primes.py#10" | |
325 |
title=" |
|
325 | title="3e1445510fe7: a">test@0</a> | |
326 | </td> |
|
326 | </td> | |
327 | <td class="source"><a href="#l10" id="l10"> 10</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td> |
|
327 | <td class="source"><a href="#l10" id="l10"> 10</a> </td> | |
328 | </tr> |
|
328 | </tr> | |
329 | <tr class="parity0"> |
|
329 | <tr class="parity0"> | |
330 | <td class="annotate"> |
|
330 | <td class="annotate"> | |
331 |
<a href="/annotate/ |
|
331 | <a href="/annotate/3e1445510fe7/primes.py#11" | |
332 |
title=" |
|
332 | title="3e1445510fe7: a">test@0</a> | |
333 | </td> |
|
333 | </td> | |
334 | <td class="source"><a href="#l11" id="l11"> 11</a> <span class="n">msvcrt</span><span class="o">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">os</span><span class="o">.</span><span class="n">O_BINARY</span><span class="p">)</span></td> |
|
334 | <td class="source"><a href="#l11" id="l11"> 11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></td> | |
335 | </tr> |
|
335 | </tr> | |
336 | <tr class="parity1"> |
|
336 | <tr class="parity1"> | |
337 | <td class="annotate"> |
|
337 | <td class="annotate"> | |
338 |
<a href="/annotate/ |
|
338 | <a href="/annotate/3e1445510fe7/primes.py#12" | |
339 |
title=" |
|
339 | title="3e1445510fe7: a">test@0</a> | |
340 | </td> |
|
340 | </td> | |
341 | <td class="source"><a href="#l12" id="l12"> 12</a> <span class="kn">except</span> <span class="ne">ImportError</span><span class="p">:</span></td> |
|
341 | <td class="source"><a href="#l12" id="l12"> 12</a> <span class="sd">"""Generate all primes."""</span></td> | |
342 | </tr> |
|
342 | </tr> | |
343 | <tr class="parity0"> |
|
343 | <tr class="parity0"> | |
344 | <td class="annotate"> |
|
344 | <td class="annotate"> | |
345 |
<a href="/annotate/ |
|
345 | <a href="/annotate/3e1445510fe7/primes.py#13" | |
346 |
title=" |
|
346 | title="3e1445510fe7: a">test@0</a> | |
347 | </td> |
|
347 | </td> | |
348 | <td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">pass</span></td> |
|
348 | <td class="source"><a href="#l13" id="l13"> 13</a> <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> | |
349 | </tr> |
|
349 | </tr> | |
350 | <tr class="parity1"> |
|
350 | <tr class="parity1"> | |
351 | <td class="annotate"> |
|
351 | <td class="annotate"> | |
352 |
<a href="/annotate/ |
|
352 | <a href="/annotate/3e1445510fe7/primes.py#14" | |
353 |
title=" |
|
353 | title="3e1445510fe7: a">test@0</a> | |
354 | </td> |
|
354 | </td> | |
355 | <td class="source"><a href="#l14" id="l14"> 14</a> </td> |
|
355 | <td class="source"><a href="#l14" id="l14"> 14</a> <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></td> | |
356 | </tr> |
|
356 | </tr> | |
357 | <tr class="parity0"> |
|
357 | <tr class="parity0"> | |
358 | <td class="annotate"> |
|
358 | <td class="annotate"> | |
359 |
<a href="/annotate/ |
|
359 | <a href="/annotate/3e1445510fe7/primes.py#15" | |
360 |
title=" |
|
360 | title="3e1445510fe7: a">test@0</a> | |
361 | </td> |
|
361 | </td> | |
362 | <td class="source"><a href="#l15" id="l15"> 15</a> <span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="n">h</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="kn">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">3</span><span class="p">:]]</span></td> |
|
362 | <td class="source"><a href="#l15" id="l15"> 15</a> <span class="c"># It is important to yield *here* in order to stop the</span></td> | |
363 | </tr> |
|
363 | </tr> | |
364 | <tr class="parity1"> |
|
364 | <tr class="parity1"> | |
365 | <td class="annotate"> |
|
365 | <td class="annotate"> | |
366 |
<a href="/annotate/ |
|
366 | <a href="/annotate/3e1445510fe7/primes.py#16" | |
367 |
title=" |
|
367 | title="3e1445510fe7: a">test@0</a> | |
368 | </td> |
|
368 | </td> | |
369 | <td class="source"><a href="#l16" id="l16"> 16</a> <span class="n">conn</span> <span class="o">=</span> <span class="n">httplib</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></td> |
|
369 | <td class="source"><a href="#l16" id="l16"> 16</a> <span class="c"># infinite recursion.</span></td> | |
370 | </tr> |
|
370 | </tr> | |
371 | <tr class="parity0"> |
|
371 | <tr class="parity0"> | |
372 | <td class="annotate"> |
|
372 | <td class="annotate"> | |
373 |
<a href="/annotate/ |
|
373 | <a href="/annotate/3e1445510fe7/primes.py#17" | |
374 |
title=" |
|
374 | title="3e1445510fe7: a">test@0</a> | |
375 | </td> |
|
375 | </td> | |
376 | <td class="source"><a href="#l17" id="l17"> 17</a> <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"GET"</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span></td> |
|
376 | <td class="source"><a href="#l17" id="l17"> 17</a> <span class="kn">yield</span> <span class="n">p</span></td> | |
377 | </tr> |
|
377 | </tr> | |
378 | <tr class="parity1"> |
|
378 | <tr class="parity1"> | |
379 | <td class="annotate"> |
|
379 | <td class="annotate"> | |
380 |
<a href="/annotate/ |
|
380 | <a href="/annotate/3e1445510fe7/primes.py#18" | |
381 |
title=" |
|
381 | title="3e1445510fe7: a">test@0</a> | |
382 | </td> |
|
382 | </td> | |
383 | <td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">response</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span></td> |
|
383 | <td class="source"><a href="#l18" id="l18"> 18</a> <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mf">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></td> | |
384 | </tr> |
|
384 | </tr> | |
385 | <tr class="parity0"> |
|
385 | <tr class="parity0"> | |
386 | <td class="annotate"> |
|
386 | <td class="annotate"> | |
387 |
<a href="/annotate/ |
|
387 | <a href="/annotate/3e1445510fe7/primes.py#19" | |
388 |
title=" |
|
388 | title="3e1445510fe7: a">test@0</a> | |
389 | </td> |
|
389 | </td> | |
390 | <td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">print</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">reason</span></td> |
|
390 | <td class="source"><a href="#l19" id="l19"> 19</a> <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td> | |
391 | </tr> |
|
391 | </tr> | |
392 | <tr class="parity1"> |
|
392 | <tr class="parity1"> | |
393 | <td class="annotate"> |
|
393 | <td class="annotate"> | |
394 |
<a href="/annotate/ |
|
394 | <a href="/annotate/3e1445510fe7/primes.py#20" | |
395 |
title=" |
|
395 | title="3e1445510fe7: a">test@0</a> | |
396 | </td> |
|
396 | </td> | |
397 |
<td class="source"><a href="#l20" id="l20"> 20</a> |
|
397 | <td class="source"><a href="#l20" id="l20"> 20</a> <span class="kn">yield</span> <span class="n">n</span></td> | |
398 | </tr> |
|
398 | </tr> | |
399 | <tr class="parity0"> |
|
399 | <tr class="parity0"> | |
400 | <td class="annotate"> |
|
400 | <td class="annotate"> | |
401 |
<a href="/annotate/ |
|
401 | <a href="/annotate/3e1445510fe7/primes.py#21" | |
402 |
title=" |
|
402 | title="3e1445510fe7: a">test@0</a> | |
403 | </td> |
|
403 | </td> | |
404 | <td class="source"><a href="#l21" id="l21"> 21</a> <span class="kn">if</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span></td> |
|
404 | <td class="source"><a href="#l21" id="l21"> 21</a> </td> | |
405 | </tr> |
|
405 | </tr> | |
406 | <tr class="parity1"> |
|
406 | <tr class="parity1"> | |
407 | <td class="annotate"> |
|
407 | <td class="annotate"> | |
408 |
<a href="/annotate/ |
|
408 | <a href="/annotate/3e1445510fe7/primes.py#22" | |
409 |
title=" |
|
409 | title="3e1445510fe7: a">test@0</a> | |
410 | </td> |
|
410 | </td> | |
411 | <td class="source"><a href="#l22" id="l22"> 22</a> <span class="kn">print</span> <span class="s">"</span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">h</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">getheader</span><span class="p">(</span><span class="n">h</span><span class="p">))</span></td> |
|
411 | <td class="source"><a href="#l22" id="l22"> 22</a> <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mf">2</span> <span class="o">==</span> <span class="mf">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></td> | |
412 | </tr> |
|
412 | </tr> | |
413 | <tr class="parity0"> |
|
413 | <tr class="parity0"> | |
414 | <td class="annotate"> |
|
414 | <td class="annotate"> | |
415 |
<a href="/annotate/ |
|
415 | <a href="/annotate/3e1445510fe7/primes.py#23" | |
416 |
title=" |
|
416 | title="3e1445510fe7: a">test@0</a> | |
417 | </td> |
|
417 | </td> | |
418 | <td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">print</span></td> |
|
418 | <td class="source"><a href="#l23" id="l23"> 23</a> <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mf">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o"><</span> <span class="mf">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></td> | |
419 | </tr> |
|
419 | </tr> | |
420 | <tr class="parity1"> |
|
420 | <tr class="parity1"> | |
421 | <td class="annotate"> |
|
421 | <td class="annotate"> | |
422 |
<a href="/annotate/ |
|
422 | <a href="/annotate/3e1445510fe7/primes.py#24" | |
423 |
title=" |
|
423 | title="3e1445510fe7: a">test@0</a> | |
424 | </td> |
|
424 | </td> | |
425 | <td class="source"><a href="#l24" id="l24"> 24</a> <span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">read</span><span class="p">()</span></td> |
|
425 | <td class="source"><a href="#l24" id="l24"> 24</a> </td> | |
426 | </tr> |
|
426 | </tr> | |
427 | <tr class="parity0"> |
|
427 | <tr class="parity0"> | |
428 | <td class="annotate"> |
|
428 | <td class="annotate"> | |
429 |
<a href="/annotate/ |
|
429 | <a href="/annotate/3e1445510fe7/primes.py#25" | |
430 |
title=" |
|
430 | title="3e1445510fe7: a">test@0</a> | |
431 | </td> |
|
431 | </td> | |
432 | <td class="source"><a href="#l25" id="l25"> 25</a> <span class="n">data</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s">'\d+ years'</span><span class="p">,</span> <span class="s">'many years'</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span></td> |
|
432 | <td class="source"><a href="#l25" id="l25"> 25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span></td> | |
433 | </tr> |
|
433 | </tr> | |
434 | <tr class="parity1"> |
|
434 | <tr class="parity1"> | |
435 | <td class="annotate"> |
|
435 | <td class="annotate"> | |
436 |
<a href="/annotate/ |
|
436 | <a href="/annotate/3e1445510fe7/primes.py#26" | |
437 |
title=" |
|
437 | title="3e1445510fe7: a">test@0</a> | |
438 | </td> |
|
438 | </td> | |
439 | <td class="source"><a href="#l26" id="l26"> 26</a> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span></td> |
|
439 | <td class="source"><a href="#l26" id="l26"> 26</a> <span class="kn">import</span> <span class="nn">sys</span></td> | |
440 | </tr> |
|
440 | </tr> | |
441 | <tr class="parity0"> |
|
441 | <tr class="parity0"> | |
442 | <td class="annotate"> |
|
442 | <td class="annotate"> | |
443 |
<a href="/annotate/ |
|
443 | <a href="/annotate/3e1445510fe7/primes.py#27" | |
444 |
title=" |
|
444 | title="3e1445510fe7: a">test@0</a> | |
445 | </td> |
|
445 | </td> | |
446 | <td class="source"><a href="#l27" id="l27"> 27</a> </td> |
|
446 | <td class="source"><a href="#l27" id="l27"> 27</a> <span class="kn">try</span><span class="p">:</span></td> | |
447 | </tr> |
|
447 | </tr> | |
448 | <tr class="parity1"> |
|
448 | <tr class="parity1"> | |
449 | <td class="annotate"> |
|
449 | <td class="annotate"> | |
450 |
<a href="/annotate/ |
|
450 | <a href="/annotate/3e1445510fe7/primes.py#28" | |
451 |
title=" |
|
451 | title="3e1445510fe7: a">test@0</a> | |
452 | </td> |
|
452 | </td> | |
453 | <td class="source"><a href="#l28" id="l28"> 28</a> <span class="kn">if</span> <span class="mf">200</span> <span class="o"><=</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span> <span class="o"><=</span> <span class="mf">299</span><span class="p">:</span></td> |
|
453 | <td class="source"><a href="#l28" id="l28"> 28</a> <span class="n">n</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">])</span></td> | |
454 | </tr> |
|
454 | </tr> | |
455 | <tr class="parity0"> |
|
455 | <tr class="parity0"> | |
456 | <td class="annotate"> |
|
456 | <td class="annotate"> | |
457 |
<a href="/annotate/ |
|
457 | <a href="/annotate/3e1445510fe7/primes.py#29" | |
458 |
title=" |
|
458 | title="3e1445510fe7: a">test@0</a> | |
459 | </td> |
|
459 | </td> | |
460 | <td class="source"><a href="#l29" id="l29"> 29</a> <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mf">0</span><span class="p">)</span></td> |
|
460 | <td class="source"><a href="#l29" id="l29"> 29</a> <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></td> | |
461 | </tr> |
|
461 | </tr> | |
462 | <tr class="parity1"> |
|
462 | <tr class="parity1"> | |
463 | <td class="annotate"> |
|
463 | <td class="annotate"> | |
464 |
<a href="/annotate/ |
|
464 | <a href="/annotate/3e1445510fe7/primes.py#30" | |
465 |
title=" |
|
465 | title="3e1445510fe7: a">test@0</a> | |
466 | </td> |
|
466 | </td> | |
467 |
<td class="source"><a href="#l30" id="l30"> 30</a> <span class="n"> |
|
467 | <td class="source"><a href="#l30" id="l30"> 30</a> <span class="n">n</span> <span class="o">=</span> <span class="mf">10</span></td> | |
|
468 | </tr> | |||
|
469 | <tr class="parity0"> | |||
|
470 | <td class="annotate"> | |||
|
471 | <a href="/annotate/3e1445510fe7/primes.py#31" | |||
|
472 | title="3e1445510fe7: a">test@0</a> | |||
|
473 | </td> | |||
|
474 | <td class="source"><a href="#l31" id="l31"> 31</a> <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></td> | |||
|
475 | </tr> | |||
|
476 | <tr class="parity1"> | |||
|
477 | <td class="annotate"> | |||
|
478 | <a href="/annotate/3e1445510fe7/primes.py#32" | |||
|
479 | title="3e1445510fe7: a">test@0</a> | |||
|
480 | </td> | |||
|
481 | <td class="source"><a href="#l32" id="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> | |||
468 | </tr> |
|
482 | </tr> | |
469 | </table> |
|
483 | </table> | |
470 | </div> |
|
484 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now