<s> @ auth . requires_login ( ) <EOL> def index ( ) : <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT:url>' , requires = IS_URL ( ) , default = '<STR_LIT>' ) ) <EOL> if form . process ( ) . accepted : <EOL> redirect ( URL ( '<STR_LIT>' , vars = dict ( url = form . vars . url ) ) ) <EOL> clones = db ( db . cms_clone ) . select ( ) <EOL> return locals ( ) <EOL> @ auth . requires_login ( ) <EOL> def delete ( ) : <EOL> db ( db . cms_clone . id == request . args ( <NUM_LIT:0> ) ) ( db . cms_clone . created_by == auth . user . id ) . delete ( ) <EOL> redirect ( URL ( '<STR_LIT:index>' ) ) <EOL> @ auth . requires_login ( ) <EOL> def edit ( ) : <EOL> return locals ( ) <EOL> @ auth . requires_login ( ) <EOL> def edit_clone ( ) : <EOL> session . _unlock ( response ) <EOL> import urllib , re <EOL> if request . args ( <NUM_LIT:0> ) == '<STR_LIT>' : <EOL> return request . vars . value or '<STR_LIT>' <EOL> elif request . args ( <NUM_LIT:0> ) == '<STR_LIT:store>' : <EOL> session . new_html = session . html . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] + '<STR_LIT>' + request . vars . html + '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> url = request . vars . url <EOL> try : <EOL> html = urllib . urlopen ( url ) . read ( ) <EOL> except IOError : <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( '<STR_LIT:index>' ) ) <EOL> url . rstrip ( '<STR_LIT:/>' ) <EOL> session . url = url <EOL> a , b = url . split ( '<STR_LIT>' ) <EOL> items = b . split ( '<STR_LIT:/>' ) <EOL> base = a + '<STR_LIT>' + items [ <NUM_LIT:0> ] + '<STR_LIT:/>' <EOL> if len ( items ) > <NUM_LIT:2> : <EOL> full = base + '<STR_LIT:/>' . join ( items [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) + '<STR_LIT:/>' <EOL> else : <EOL> full = base <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT:\n>' , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + base , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + full , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + base , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + full , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + base , html ) <EOL> html = re . sub ( '<STR_LIT>' , '<STR_LIT>' + full , html ) <EOL> session . new_html = session . html = html <EOL> inject = '<STR_LIT>' % URL ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> html = html . replace ( '<STR_LIT>' , inject + '<STR_LIT>' ) <EOL> return html <EOL> @ auth . requires_login ( ) <EOL> def clone ( ) : <EOL> id = db . cms_clone . insert ( url = session . url , html = session . new_html ) <EOL> redirect ( URL ( '<STR_LIT>' , args = id ) ) <EOL> def page ( ) : <EOL> if request . args ( <NUM_LIT:0> ) == '<STR_LIT>' : redirect ( URL ( '<STR_LIT:index>' ) ) <EOL> html = db . cms_clone ( request . args ( <NUM_LIT:0> ) ) . html <EOL> inject = '<STR_LIT>' <EOL> html = html . replace ( '<STR_LIT>' , inject + '<STR_LIT>' ) <EOL> return html <EOL> def user ( ) : <EOL> return dict ( form = auth ( ) ) <EOL> @ auth . requires_login ( ) <EOL> def folder ( ) : <EOL> folder = db . cms_folder ( request . args ( <NUM_LIT:0> ) , created_by = auth . user . id ) <EOL> if not folder : <EOL> if db ( db . cms_folder ) . isempty ( ) : <EOL> db . cms_folder . insert ( name = '<STR_LIT:root>' , parent_folder = <NUM_LIT:0> , created_by = auth . user . id ) <EOL> folder = db . cms_folder ( parent_folder = <NUM_LIT:0> , created_by = auth . user . id ) <EOL> folder . path , f = [ folder . name ] , folder . parent_folder <EOL> while f : folder . path , f = [ A ( f . name , _href = URL ( '<STR_LIT>' , args = f ) ) ] + folder . path , f . parent_folder <EOL> files = db ( db . cms_file . folder == folder . id ) . select ( orderby = db . cms_file . name ) <EOL> folders = db ( db . cms_folder . parent_folder == folder . id ) . select ( orderby = db . cms_folder . name ) <EOL> return locals ( ) <EOL> @ auth . requires_login ( ) <EOL> def edit_file ( ) : <EOL> folder = db . cms_folder ( request . args ( <NUM_LIT:0> ) , created_by = auth . user . id ) <EOL> db . cms_file . folder . default = folder . id <EOL> db . cms_file . name . requires = IS_NOT_IN_DB ( <EOL> db ( db . cms_file . folder == folder . id ) , '<STR_LIT>' ) <EOL> file = db . cms_file ( request . args ( <NUM_LIT:1> ) , created_by = auth . user . id ) <EOL> form = SQLFORM ( db . cms_file , file , deletable = True ) . process ( next = URL ( '<STR_LIT>' , args = folder . id ) ) <EOL> return locals ( ) <EOL> @ auth . requires_login ( ) <EOL> def edit_folder ( ) : <EOL> folder = db . cms_folder ( request . args ( <NUM_LIT:0> ) , created_by = auth . user . id ) <EOL> db . cms_folder . parent_folder . default = folder . id <EOL> db . cms_folder . name . requires = IS_NOT_IN_DB ( <EOL> db ( db . cms_folder . parent_folder == folder . id ) , '<STR_LIT>' ) <EOL> ofolder = db . cms_folder ( request . args ( <NUM_LIT:1> ) , created_by = auth . user . id ) <EOL> form = SQLFORM ( db . cms_folder , ofolder , deletable = True ) . process ( next = URL ( '<STR_LIT>' , args = folder . id ) ) <EOL> return locals ( ) <EOL> def doc ( ) : <EOL> import re <EOL> import contenttype <EOL> items = re . compile ( '<STR_LIT>' ) . match ( request . args ( <NUM_LIT:0> ) or '<STR_LIT>' ) <EOL> if not items : <EOL> raise HTTP ( <NUM_LIT> ) <EOL> ( id , ext ) = ( items . group ( '<STR_LIT:id>' ) , items . group ( '<STR_LIT>' ) ) <EOL> name = db . cms_file ( id ) . file <EOL> ( filename , stream ) = db . cms_file . file . retrieve ( name ) <EOL> print filename <EOL> file = db . cms_file ( id ) <EOL> response . headers [ '<STR_LIT:Content-Type>' ] = contenttype . contenttype ( name ) <EOL> response . headers [ '<STR_LIT>' ] = "<STR_LIT>" % filename <EOL> return response . stream ( stream , request = request ) </s>
