[Tutor] world's shortest wiki

Kirk Bailey idiot1 at netzero.net
Sat Mar 6 20:16:43 EST 2004


just 11 lines, python obsfercation par excellance...
Courtesy of Mr. Sean B Palmer, at http://infomesh.net/2003/wypy
Here is the code, ALL the code:


#!/usr/bin/python
import re,os,cgi;d,h=os.listdir('.'),'<a href=wy?';p,e,g,s=tuple(map(cgi.parse(
).get,'pegs'));f=lambda s:reduce(lambda s,(r,q):re.sub('(?m)'+r,q,s),(('\r','')
,('([A-Z][a-z]+){2,}',lambda m:('%s'+h+'e=%s>?</a>',h+'g=%s>%s</a>')[m.group(0)
in d]%((m.group(0),)*2)),('^{{$','<ul>'),('^# ','<li>'),('^}}$','</ul>'),('(ht\
tp:[^<>"\s]+)',h[:-3]+r'\1>\1</a>'),('\n\n','<p>')),s);o,g=lambda y:(y in d and
cgi.escape(open(y).read()))or'',(g or p and[open(p[0].strip('./'),'w').write(s[
0])or p[0]]or[0])[0];print'Content-Type:text/html\n\n'+(s and', '.join([f(n)for
n in d if s[0]in o(n)])or'')+(e and'<form action=wy?p=%s method=POST><textarea\
  name=s rows=8 cols=50>%s</textarea><input type=submit></form>'%(e[0],o(e[0]))
or'')+(g and'<h1>%ss=%s>%s</a>,%se=%s>edit</a></h1>'%(h,g,g,h,g)+f(o(g))or'')

I never said it was well annotated, merely 11 lines long...

-- 


Respectfully,
              Kirk D Bailey
              Pinellas county Florida USA

   think   http://www.tinylist.org/ - $FREE$ software for liberty
+-------+ http://www.pinellasintergroupsociety.org/ - In Her Service
|  BOX  | http://www.listville.net/ - $FREE$ list hosting services
+-------+ http://www.howlermonkey.net/ - $FREE$ email service
   kniht   http://www.sacredelectron.org/ - My personal SCREED pit

          (C)2004 Kirk D Bailey, all rights reserved- but ask!








More information about the Tutor mailing list