<s> import os , sys ; sys . path . insert ( <NUM_LIT:0> , os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" , "<STR_LIT:..>" ) ) <EOL> from pattern . server import App , template , threadsafe <EOL> from codecs import open <EOL> app = App ( name = "<STR_LIT>" ) <EOL> @ app . route ( "<STR_LIT:/>" ) <EOL> def index ( * path , ** data ) : <EOL> page = "<STR_LIT:/>" . join ( path ) <EOL> page = page if page else "<STR_LIT>" <EOL> page = page . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:->" ) <EOL> page = page + "<STR_LIT>" <EOL> page = os . path . join ( app . path , "<STR_LIT:data>" , page ) <EOL> if "<STR_LIT>" in data and "<STR_LIT:content>" in data : <EOL> return save ( page , src = data [ "<STR_LIT:content>" ] ) <EOL> if "<STR_LIT>" in data : <EOL> return edit ( page ) <EOL> if not os . path . exists ( page ) : <EOL> return edit ( page ) <EOL> else : <EOL> return view ( page ) <EOL> wiki = """<STR_LIT>""" <EOL> def name ( page ) : <EOL> name = os . path . basename ( page ) <EOL> name = os . path . splitext ( name ) [ <NUM_LIT:0> ] <EOL> return name <EOL> def displayname ( page ) : <EOL> return name ( name ( page ) ) . replace ( "<STR_LIT:->" , "<STR_LIT:U+0020>" ) . title ( ) <EOL> def view ( page ) : <EOL> print displayname ( page ) <EOL> return template ( wiki , name = name ( page ) , content = open ( page ) . read ( ) ) <EOL> def edit ( page ) : <EOL> s = open ( page ) . read ( ) if os . path . exists ( page ) else "<STR_LIT>" <EOL> s = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' % s <EOL> return template ( wiki , name = name ( page ) , content = s ) <EOL> @ threadsafe <EOL> def save ( page , src ) : <EOL> f = open ( page , "<STR_LIT:w>" ) <EOL> f . write ( src . encode ( "<STR_LIT:utf-8>" ) ) <EOL> f . close ( ) <EOL> return view ( page ) <EOL> app . run ( "<STR_LIT:127.0.0.1>" , port = <NUM_LIT> ) </s>
