<s> """<STR_LIT>""" <EOL> import os <EOL> import urllib <EOL> import stat <EOL> from nevow import inevow <EOL> from nevow import rend <EOL> from nevow import loaders <EOL> from nevow import tags <EOL> def formatFileSize ( size ) : <EOL> if size < <NUM_LIT> : <EOL> return '<STR_LIT>' % size <EOL> elif size < ( <NUM_LIT> ** <NUM_LIT:2> ) : <EOL> return '<STR_LIT>' % ( size / <NUM_LIT> ) <EOL> elif size < ( <NUM_LIT> ** <NUM_LIT:3> ) : <EOL> return '<STR_LIT>' % ( size / ( <NUM_LIT> ** <NUM_LIT:2> ) ) <EOL> else : <EOL> return '<STR_LIT>' % ( size / ( <NUM_LIT> ** <NUM_LIT:3> ) ) <EOL> class DirectoryLister ( rend . Page ) : <EOL> def __init__ ( self , pathname , dirs = None , <EOL> contentTypes = { } , <EOL> contentEncodings = { } , <EOL> defaultType = '<STR_LIT>' ) : <EOL> self . contentTypes = contentTypes <EOL> self . contentEncodings = contentEncodings <EOL> self . defaultType = defaultType <EOL> self . dirs = dirs <EOL> self . path = pathname <EOL> rend . Page . __init__ ( self ) <EOL> def data_listing ( self , context , data ) : <EOL> from nevow . static import getTypeAndEncoding <EOL> if self . dirs is None : <EOL> directory = os . listdir ( self . path ) <EOL> directory . sort ( ) <EOL> else : <EOL> directory = self . dirs <EOL> files = [ ] ; dirs = [ ] <EOL> for path in directory : <EOL> url = urllib . quote ( path , '<STR_LIT:/>' ) <EOL> if os . path . isdir ( os . path . join ( self . path , path ) ) : <EOL> url = url + '<STR_LIT:/>' <EOL> dirs . append ( { <EOL> '<STR_LIT>' : url , <EOL> '<STR_LIT>' : path + "<STR_LIT:/>" , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> else : <EOL> mimetype , encoding = getTypeAndEncoding ( <EOL> path , <EOL> self . contentTypes , self . contentEncodings , self . defaultType ) <EOL> try : <EOL> filesize = os . stat ( os . path . join ( self . path , path ) ) [ stat . ST_SIZE ] <EOL> except OSError , x : <EOL> if x . errno != <NUM_LIT:2> and x . errno != <NUM_LIT> : <EOL> raise x <EOL> else : <EOL> files . append ( { <EOL> '<STR_LIT>' : url , <EOL> '<STR_LIT>' : path , <EOL> '<STR_LIT:type>' : '<STR_LIT>' % mimetype , <EOL> '<STR_LIT>' : formatFileSize ( filesize ) , <EOL> '<STR_LIT>' : ( encoding and '<STR_LIT>' % encoding or '<STR_LIT>' ) } ) <EOL> return dirs + files <EOL> def data_header ( self , context , data ) : <EOL> request = context . locate ( inevow . IRequest ) <EOL> return "<STR_LIT>" % urllib . unquote ( request . uri ) <EOL> def render_tableLink ( self , context , data ) : <EOL> return tags . a ( href = data [ '<STR_LIT>' ] ) [ data [ '<STR_LIT>' ] ] <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . path <EOL> __str__ = __repr__ <EOL> docFactory = loaders . stan ( tags . html [ <EOL> tags . head [ <EOL> tags . title ( data = tags . directive ( '<STR_LIT>' ) ) [ str ] , <EOL> tags . style [ '''<STR_LIT>''' ] <EOL> ] , <EOL> tags . body [ tags . div ( _class = '<STR_LIT>' ) [ <EOL> tags . h1 ( data = tags . directive ( '<STR_LIT>' ) ) [ str ] , <EOL> tags . table ( render = rend . sequence , data = tags . directive ( '<STR_LIT>' ) ) [ <EOL> tags . tr ( pattern = "<STR_LIT>" ) [ <EOL> tags . th [ "<STR_LIT>" ] , <EOL> tags . th [ "<STR_LIT>" ] , <EOL> tags . th [ "<STR_LIT>" ] , <EOL> tags . th [ "<STR_LIT>" ] , <EOL> ] , <EOL> tags . tr ( _class = "<STR_LIT>" , pattern = "<STR_LIT>" ) [ <EOL> tags . td [ tags . a ( render = tags . directive ( "<STR_LIT>" ) ) ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT>" ) ) [ str ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT:type>" ) ) [ str ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT>" ) ) [ str ] , <EOL> ] , <EOL> tags . tr ( _class = "<STR_LIT>" , pattern = "<STR_LIT>" ) [ <EOL> tags . td [ tags . a ( render = tags . directive ( "<STR_LIT>" ) ) ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT>" ) ) [ str ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT:type>" ) ) [ str ] , <EOL> tags . td ( data = tags . directive ( "<STR_LIT>" ) ) [ str ] , <EOL> ] <EOL> ] <EOL> ] ] <EOL> ] ) </s>
