<s> import os <EOL> import sys <EOL> from paste . deploy import loadwsgi <EOL> from spawning import spawning_controller <EOL> def config_factory ( args ) : <EOL> if '<STR_LIT>' in args : <EOL> config_url = args [ '<STR_LIT>' ] <EOL> relative_to = args [ '<STR_LIT>' ] <EOL> global_conf = args [ '<STR_LIT>' ] <EOL> else : <EOL> config_file = os . path . abspath ( args [ '<STR_LIT:args>' ] [ <NUM_LIT:0> ] ) <EOL> config_url = '<STR_LIT>' % ( os . path . basename ( config_file ) , ) <EOL> relative_to = os . path . dirname ( config_file ) <EOL> global_conf = { } <EOL> for arg in args [ '<STR_LIT:args>' ] [ <NUM_LIT:1> : ] : <EOL> key , value = arg . split ( '<STR_LIT:=>' ) <EOL> global_conf [ key ] = value <EOL> ctx = loadwsgi . loadcontext ( <EOL> loadwsgi . SERVER , <EOL> config_url , <EOL> relative_to = relative_to , <EOL> global_conf = global_conf ) <EOL> watch = args . get ( '<STR_LIT>' , None ) <EOL> if watch is None : <EOL> watch = [ ] <EOL> if ctx . global_conf [ '<STR_LIT>' ] not in watch : <EOL> watch . append ( ctx . global_conf [ '<STR_LIT>' ] ) <EOL> args [ '<STR_LIT>' ] = watch <EOL> args [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> args [ '<STR_LIT>' ] = config_url <EOL> args [ '<STR_LIT>' ] = relative_to <EOL> args [ '<STR_LIT>' ] = [ relative_to ] <EOL> args [ '<STR_LIT>' ] = ctx . global_conf <EOL> debug = ctx . global_conf . get ( '<STR_LIT>' , None ) <EOL> if debug is not None : <EOL> args [ '<STR_LIT>' ] = ( debug == '<STR_LIT:true>' ) <EOL> host = ctx . local_conf . get ( '<STR_LIT:host>' , None ) <EOL> if host is not None : <EOL> args [ '<STR_LIT:host>' ] = host <EOL> port = ctx . local_conf . get ( '<STR_LIT:port>' , None ) <EOL> if port is not None : <EOL> args [ '<STR_LIT:port>' ] = int ( port ) <EOL> num_processes = ctx . local_conf . get ( '<STR_LIT>' , None ) <EOL> if num_processes is not None : <EOL> args [ '<STR_LIT>' ] = int ( num_processes ) <EOL> threadpool_workers = ctx . local_conf . get ( '<STR_LIT>' , None ) <EOL> if threadpool_workers is not None : <EOL> args [ '<STR_LIT>' ] = int ( threadpool_workers ) <EOL> return args <EOL> def app_factory ( config ) : <EOL> return loadwsgi . loadapp ( <EOL> config [ '<STR_LIT>' ] , <EOL> relative_to = config [ '<STR_LIT>' ] , <EOL> global_conf = config [ '<STR_LIT>' ] ) <EOL> def server_factory ( global_conf , host , port , * args , ** kw ) : <EOL> config_url = '<STR_LIT>' + os . path . split ( global_conf [ '<STR_LIT>' ] ) [ <NUM_LIT:1> ] <EOL> relative_to = global_conf [ '<STR_LIT>' ] <EOL> def run ( app ) : <EOL> args = spawning_controller . DEFAULTS . copy ( ) <EOL> args . update ( <EOL> { '<STR_LIT>' : config_url , '<STR_LIT>' : relative_to , '<STR_LIT>' : global_conf } ) <EOL> spawning_controller . run_controller ( <EOL> '<STR_LIT>' , args ) <EOL> return run </s>
