<s> """<STR_LIT>""" <EOL> import os <EOL> from twisted . web import server , static , twcgi , script , demo , distrib , wsgi <EOL> from twisted . internet import interfaces , reactor <EOL> from twisted . python import usage , reflect , threadpool <EOL> from twisted . spread import pb <EOL> from twisted . application import internet , service , strports <EOL> class Options ( usage . Options ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> optParameters = [ [ "<STR_LIT:port>" , "<STR_LIT:p>" , None , "<STR_LIT>" <EOL> "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:l>" , None , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , None , None , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:c>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:k>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ] <EOL> optFlags = [ [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( distrib . UserDirectory . userSocketName , ) + <EOL> "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:n>" , "<STR_LIT>" + <EOL> "<STR_LIT>" ] , <EOL> ] <EOL> compData = usage . Completions ( <EOL> optActions = { "<STR_LIT>" : usage . CompleteFiles ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : usage . CompleteFiles ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : usage . CompleteFiles ( "<STR_LIT>" ) } <EOL> ) <EOL> longdesc = """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> usage . Options . __init__ ( self ) <EOL> self [ '<STR_LIT>' ] = [ ] <EOL> self [ '<STR_LIT:root>' ] = None <EOL> def opt_index ( self , indexName ) : <EOL> """<STR_LIT>""" <EOL> self [ '<STR_LIT>' ] . append ( indexName ) <EOL> opt_i = opt_index <EOL> def opt_user ( self ) : <EOL> """<STR_LIT>""" <EOL> self [ '<STR_LIT:root>' ] = distrib . UserDirectory ( ) <EOL> opt_u = opt_user <EOL> def opt_path ( self , path ) : <EOL> """<STR_LIT>""" <EOL> self [ '<STR_LIT:root>' ] = static . File ( os . path . abspath ( path ) ) <EOL> self [ '<STR_LIT:root>' ] . processors = { <EOL> '<STR_LIT>' : twcgi . CGIScript , <EOL> '<STR_LIT>' : script . PythonScript , <EOL> '<STR_LIT>' : script . ResourceScript , <EOL> } <EOL> def opt_processor ( self , proc ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self [ '<STR_LIT:root>' ] , static . File ) : <EOL> raise usage . UsageError ( "<STR_LIT>" ) <EOL> ext , klass = proc . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> self [ '<STR_LIT:root>' ] . processors [ ext ] = reflect . namedClass ( klass ) <EOL> def opt_class ( self , className ) : <EOL> """<STR_LIT>""" <EOL> classObj = reflect . namedClass ( className ) <EOL> self [ '<STR_LIT:root>' ] = classObj ( ) <EOL> def opt_resource_script ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self [ '<STR_LIT:root>' ] = script . ResourceScriptWrapper ( name ) <EOL> def opt_wsgi ( self , name ) : <EOL> """<STR_LIT>""" <EOL> pool = threadpool . ThreadPool ( ) <EOL> reactor . callWhenRunning ( pool . start ) <EOL> reactor . addSystemEventTrigger ( '<STR_LIT>' , '<STR_LIT>' , pool . stop ) <EOL> try : <EOL> application = reflect . namedAny ( name ) <EOL> except ( AttributeError , ValueError ) : <EOL> raise usage . UsageError ( "<STR_LIT>" % ( name , ) ) <EOL> self [ '<STR_LIT:root>' ] = wsgi . WSGIResource ( reactor , pool , application ) <EOL> def opt_mime_type ( self , defaultType ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self [ '<STR_LIT:root>' ] , static . File ) : <EOL> raise usage . UsageError ( "<STR_LIT>" ) <EOL> self [ '<STR_LIT:root>' ] . defaultType = defaultType <EOL> opt_m = opt_mime_type <EOL> def opt_allow_ignore_ext ( self ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self [ '<STR_LIT:root>' ] , static . File ) : <EOL> raise usage . UsageError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self [ '<STR_LIT:root>' ] . ignoreExt ( '<STR_LIT:*>' ) <EOL> def opt_ignore_ext ( self , ext ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self [ '<STR_LIT:root>' ] , static . File ) : <EOL> raise usage . UsageError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self [ '<STR_LIT:root>' ] . ignoreExt ( ext ) <EOL> def postOptions ( self ) : <EOL> """<STR_LIT>""" <EOL> if self [ '<STR_LIT>' ] : <EOL> try : <EOL> from twisted . internet . ssl import DefaultOpenSSLContextFactory <EOL> except ImportError : <EOL> raise usage . UsageError ( "<STR_LIT>" ) <EOL> if self [ '<STR_LIT:port>' ] is None : <EOL> if self [ '<STR_LIT>' ] : <EOL> path = os . path . expanduser ( <EOL> os . path . join ( '<STR_LIT>' , distrib . UserDirectory . userSocketName ) ) <EOL> self [ '<STR_LIT:port>' ] = '<STR_LIT>' + path <EOL> else : <EOL> self [ '<STR_LIT:port>' ] = '<STR_LIT>' <EOL> def makePersonalServerFactory ( site ) : <EOL> """<STR_LIT>""" <EOL> return pb . PBServerFactory ( distrib . ResourcePublisher ( site ) ) <EOL> def makeService ( config ) : <EOL> s = service . MultiService ( ) <EOL> if config [ '<STR_LIT:root>' ] : <EOL> root = config [ '<STR_LIT:root>' ] <EOL> if config [ '<STR_LIT>' ] : <EOL> config [ '<STR_LIT:root>' ] . indexNames = config [ '<STR_LIT>' ] <EOL> else : <EOL> root = demo . Test ( ) <EOL> if isinstance ( root , static . File ) : <EOL> root . registry . setComponent ( interfaces . IServiceCollection , s ) <EOL> if config [ '<STR_LIT>' ] : <EOL> site = server . Site ( root , logPath = config [ '<STR_LIT>' ] ) <EOL> else : <EOL> site = server . Site ( root ) <EOL> site . displayTracebacks = not config [ "<STR_LIT>" ] <EOL> if config [ '<STR_LIT>' ] : <EOL> personal = strports . service ( <EOL> config [ '<STR_LIT:port>' ] , makePersonalServerFactory ( site ) ) <EOL> personal . setServiceParent ( s ) <EOL> else : <EOL> if config [ '<STR_LIT>' ] : <EOL> from twisted . internet . ssl import DefaultOpenSSLContextFactory <EOL> i = internet . SSLServer ( int ( config [ '<STR_LIT>' ] ) , site , <EOL> DefaultOpenSSLContextFactory ( config [ '<STR_LIT>' ] , <EOL> config [ '<STR_LIT>' ] ) ) <EOL> i . setServiceParent ( s ) <EOL> strports . service ( config [ '<STR_LIT:port>' ] , site ) . setServiceParent ( s ) <EOL> return s </s>
