((lambda (x) (x x)) (lambda (x) (x x)))

Thursday, January 22, 2009

Getting the hang of Python.

So, I've been practicing a little more with Python, and kind of think I'm getting the hang of it.

But as far as the language's supposed 'readability', I offer the following counterexample...

AccessTable.py
# Usage: head -60 /var/log/apache2/access.log | python AccessTable.py
# Effect: Produces a spiffy HTML page containing the contents of your Apache access log in a table.

from fileinput import input as OO
O=[(lambda o,oo,ooo:[o]if(oo=="")else[o+oo[0],oo[1:]]if(oo[0]==ooo)else(O[0](o+oo[0],oo[1:],ooo))),(lambda o,oo:[o]if(((O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[0]and(not(O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[1]))or(o==""))else[(O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[0]]+[(O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[1]]if(not(oo[1:]))else[(O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[0]]+O[1]((O[0]("",o,oo[0])if(not(o==""or(oo==[])))else[o,""])[1],oo[1:])),""+chr(60)+"/b"+chr(62)+""+chr(60)+"/u"+chr(62)+"",(lambda o,oo:""if(oo=="")else(oo[0])if((oo[0]!=o)and(not(oo[1:])))else(oo)if(oo[0]!=o)else(O[3](o,oo[1:]))),(lambda o,oo:""if(oo=="")else(oo[0])if((not(oo[1:])))else(O[3](o,(oo)if(oo[-1]!=o)else(O[4](o,oo[:-1]))))),["IP Address","Date","Time","Method","URL","Protocol Version","Error Code","Bytes","URL 2","Client"],(lambda o:""+chr(60)+"html"+chr(62)+"\n\t"+chr(60)+"body"+chr(62)+"\n"+'\t\t'+chr(60)+'table border="1"'+chr(62)+"\n"+"\n".join(["\t\t\t"+chr(60)+"tr"+chr(62)+"\n"+line+"\t\t\t"+chr(60)+"/tr"+chr(62)+""for(line)in[''.join(o)for(o)in[["\t\t\t\t"+chr(60)+"td"+chr(62)+""+word+""+chr(60)+"/td"+chr(62)+"\n"for(word)in(line)]for(line)in(o)]]])+"\n\t\t"+chr(60)+"/table"+chr(62)+"\n"+"\t"+chr(60)+"/body"+chr(62)+"\n"+chr(60)+"/html"+chr(62)+""),""+chr(60)+"b"+chr(62)+""+chr(60)+"u"+chr(62)+"",(lambda s:[(o)for(o)in[(lambda o:O[4]("\n",O[4](":",O[4]("]",O[4]('"',O[4](" ",o))))))(o)for(o)in(O[1](s,[" ","[",":","]",'"'," "," ",'"'," "," "," "," "]))]if(o)not in[" ",'"',"","- - ["]])]
print(O[6]([[O[7]+o+O[2]for(o)in(O[5])]]+[O[8](o)for(o)in(OO())]))





Just a little something I came up with this evening. Feel free to try it out - it works with the default log format in the version of Apache installed on my (somewhat outdated) Ubuntu 6.06 webserver. If the format gets messed up in the blog, a copy is on the web at 'http://matrix.senecac.on.ca/~gjmasseau/AccessTable.py'.

2 comments:

Unknown said...

Lambda Considered Harmful?

gregorymasseau said...

One man's harmful is another man's awesome.