# HG changeset patch # User Benoit Boissinot # Date 1242594443 -7200 # Node ID ea1981f65b3a6ec20cceafc956b57eb305ee58a1 # Parent 1a96f1d9599b96cfa220606b9a758a6032b29cea# Parent 338412820a57ddf786dc091abbd0452bfb5c9f99 merge with crew diff -r 1a96f1d9599b -r ea1981f65b3a templates/coal/map --- a/templates/coal/map Sun May 17 22:51:17 2009 +0200 +++ b/templates/coal/map Sun May 17 23:07:23 2009 +0200 @@ -52,7 +52,8 @@ fileannotate = ../paper/fileannotate.tmpl filediff = ../paper/filediff.tmpl filelog = ../paper/filelog.tmpl -fileline = '
{linenumber} {line|escape}
' +fileline = ' +
{linenumber} {line|escape}
' filelogentry = ../paper/filelogentry.tmpl annotateline = ' diff -r 1a96f1d9599b -r ea1981f65b3a templates/gitweb/map --- a/templates/gitweb/map Sun May 17 22:51:17 2009 +0200 +++ b/templates/gitweb/map Sun May 17 23:07:23 2009 +0200 @@ -70,7 +70,12 @@ fileannotate = fileannotate.tmpl filediff = filediff.tmpl filelog = filelog.tmpl -fileline = '
{linenumber} {line|escape}
' +fileline = ' +
+
+      {linenumber} {line|escape}
+    
+
' annotateline = ' diff -r 1a96f1d9599b -r ea1981f65b3a templates/monoblue/map --- a/templates/monoblue/map Sun May 17 22:51:17 2009 +0200 +++ b/templates/monoblue/map Sun May 17 23:07:23 2009 +0200 @@ -61,7 +61,12 @@ fileannotate = fileannotate.tmpl filediff = filediff.tmpl filelog = filelog.tmpl -fileline = '
{linenumber} {line|escape}
' +fileline = ' +
+
+      {linenumber} {line|escape}
+    
+
' annotateline = ' diff -r 1a96f1d9599b -r ea1981f65b3a templates/paper/map --- a/templates/paper/map Sun May 17 22:51:17 2009 +0200 +++ b/templates/paper/map Sun May 17 23:07:23 2009 +0200 @@ -52,7 +52,8 @@ fileannotate = fileannotate.tmpl filediff = filediff.tmpl filelog = filelog.tmpl -fileline = '
{linenumber} {line|escape}
' +fileline = ' +
{linenumber} {line|escape}
' filelogentry = filelogentry.tmpl annotateline = ' diff -r 1a96f1d9599b -r ea1981f65b3a tests/test-hgweb-commands.out --- a/tests/test-hgweb-commands.out Sun May 17 22:51:17 2009 +0200 +++ b/tests/test-hgweb-commands.out Sun May 17 23:07:23 2009 +0200 @@ -435,6 +435,7 @@
line source
+
1 foo
diff -r 1a96f1d9599b -r ea1981f65b3a tests/test-highlight --- a/tests/test-highlight Sun May 17 22:51:17 2009 +0200 +++ b/tests/test-highlight Sun May 17 23:07:23 2009 +0200 @@ -11,7 +11,41 @@ hg init test cd test -cp $TESTDIR/get-with-headers.py ./ +# create random Python file to exercise Pygments +cat < primes.py +#!/usr/bin/env python + +"""Fun with generators. Corresponding Haskell implementation: + +primes = 2 : sieve [3, 5..] + where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] +""" + +from itertools import dropwhile, ifilter, islice, count, chain + +def primes(): + """Generate all primes.""" + def sieve(ns): + p = ns.next() + # It is important to yield *here* in order to stop the + # infinite recursion. + yield p + ns = ifilter(lambda n: n % p != 0, ns) + for n in sieve(ns): + yield n + + odds = ifilter(lambda i: i % 2 == 1, count()) + return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) + +if __name__ == "__main__": + import sys + try: + n = int(sys.argv[1]) + except (ValueError, IndexError): + n = 10 + p = primes() + print "The first %d primes: %s" % (n, list(islice(p, n))) +EOF # check for UnicodeDecodeError with iso-8859-1 file contents python -c 'fp = open("isolatin.txt", "w"); fp.write("h\xFCbsch\n"); fp.close();' @@ -23,7 +57,7 @@ cat hg.pid >> $DAEMON_PIDS echo % hgweb filerevision, html -("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py') \ +("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py') \ | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mf\"/class=\"mi\"/g" echo % hgweb filerevision, html @@ -31,17 +65,17 @@ | sed "s/class=\"k\"/class=\"kn\"/g" echo % hgweb fileannotate, html -("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py') \ +("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py') \ | sed "s/class=\"k\"/class=\"kn\"/g" | sed "s/class=\"mi\"/class=\"mf\"/g" echo % hgweb fileannotate, raw -("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/get-with-headers.py?style=raw') \ +("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/annotate/tip/primes.py?style=raw') \ | sed "s/test@//" > a echo "200 Script output follows" > b echo "" >> b echo "" >> b -hg annotate "get-with-headers.py" >> b +hg annotate "primes.py" >> b echo "" >> b echo "" >> b echo "" >> b @@ -51,12 +85,12 @@ echo echo % hgweb filerevision, raw -("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/get-with-headers.py?style=raw') \ +("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/primes.py?style=raw') \ > a echo "200 Script output follows" > b echo "" >> b -hg cat get-with-headers.py >> b +hg cat primes.py >> b diff -u b a diff -r 1a96f1d9599b -r ea1981f65b3a tests/test-highlight.out --- a/tests/test-highlight.out Sun May 17 22:51:17 2009 +0200 +++ b/tests/test-highlight.out Sun May 17 23:07:23 2009 +0200 @@ -1,5 +1,5 @@ -adding get-with-headers.py adding isolatin.txt +adding primes.py % hg serve % hgweb filerevision, html 200 Script output follows @@ -12,7 +12,7 @@ -test: 93b701795893 get-with-headers.py +test: 3e1445510fe7 primes.py @@ -23,27 +23,27 @@ mercurial

test

-

view get-with-headers.py @ 0:93b701795893

+

view primes.py @ 0:3e1445510fe7

@@ -98,7 +130,7 @@ -test: 93b701795893 isolatin.txt +test: 3e1445510fe7 isolatin.txt @@ -109,27 +141,27 @@ mercurial

test

-

view isolatin.txt @ 0:93b701795893

+

view isolatin.txt @ 0:3e1445510fe7

@@ -162,6 +194,7 @@
line source
+
1 h?bsch
@@ -184,7 +217,7 @@ -test: get-with-headers.py annotate +test: primes.py annotate @@ -195,28 +228,28 @@ mercurial

test

-

annotate get-with-headers.py @ 0:93b701795893

+

annotate primes.py @ 0:3e1445510fe7

@@ -258,213 +291,227 @@ -test@0 +test@0 1 #!/usr/bin/env python -test@0 +test@0 2 -test@0 +test@0 - 3 """This does HTTP GET requests given a host:port and path and returns + 3 """Fun with generators. Corresponding Haskell implementation: -test@0 +test@0 - 4 a subset of the headers plus the body of the result.""" + 4 -test@0 +test@0 - 5 + 5 primes = 2 : sieve [3, 5..] -test@0 +test@0 - 6 import httplib, sys, re + 6 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0] -test@0 +test@0 - 7 + 7 """ -test@0 +test@0 - 8 try: + 8 -test@0 +test@0 - 9 import msvcrt, os + 9 from itertools import dropwhile, ifilter, islice, count, chain -test@0 +test@0 - 10 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) + 10 -test@0 +test@0 - 11 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) + 11 def primes(): -test@0 +test@0 - 12 except ImportError: + 12 """Generate all primes.""" -test@0 +test@0 - 13 pass + 13 def sieve(ns): -test@0 +test@0 - 14 + 14 p = ns.next() -test@0 +test@0 - 15 headers = [h.lower() for h in sys.argv[3:]] + 15 # It is important to yield *here* in order to stop the -test@0 +test@0 - 16 conn = httplib.HTTPConnection(sys.argv[1]) + 16 # infinite recursion. -test@0 +test@0 - 17 conn.request("GET", sys.argv[2]) + 17 yield p -test@0 +test@0 - 18 response = conn.getresponse() + 18 ns = ifilter(lambda n: n % p != 0, ns) -test@0 +test@0 - 19 print response.status, response.reason + 19 for n in sieve(ns): -test@0 +test@0 - 20 for h in headers: + 20 yield n -test@0 +test@0 - 21 if response.getheader(h, None) is not None: + 21 -test@0 +test@0 - 22 print "%s: %s" % (h, response.getheader(h)) + 22 odds = ifilter(lambda i: i % 2 == 1, count()) -test@0 +test@0 - 23 print + 23 return chain([2], sieve(dropwhile(lambda n: n < 3, odds))) -test@0 +test@0 - 24 data = response.read() + 24 -test@0 +test@0 - 25 data = re.sub('\d+ years', 'many years', data) + 25 if __name__ == "__main__": -test@0 +test@0 - 26 sys.stdout.write(data) + 26 import sys -test@0 +test@0 - 27 + 27 try: -test@0 +test@0 - 28 if 200 <= response.status <= 299: + 28 n = int(sys.argv[1]) -test@0 +test@0 - 29 sys.exit(0) + 29 except (ValueError, IndexError): -test@0 +test@0 - 30 sys.exit(1) + 30 n = 10 + + + +test@0 + + 31 p = primes() + + + +test@0 + + 32 print "The first %d primes: %s" % (n, list(islice(p, n)))