<s> import plugnplay <EOL> import os <EOL> from . . core import Plugin , log <EOL> import sys <EOL> class IAppLoader ( plugnplay . Interface ) : <EOL> """<STR_LIT>""" <EOL> def can_load ( self , app_path ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def load_app ( self , app_path , app_full_name ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def load_app ( app_path , wsgi_app_full_name ) : <EOL> if app_path : <EOL> absolute_path = os . path . abspath ( os . path . expanduser ( app_path ) ) <EOL> log . debug ( "<STR_LIT>" % absolute_path ) <EOL> sys . path . append ( absolute_path ) <EOL> if wsgi_app_full_name : <EOL> log . info ( "<STR_LIT>" % wsgi_app_full_name ) <EOL> return import_object ( wsgi_app_full_name ) <EOL> app_loaders = IAppLoader . implementors ( ) <EOL> log . debug ( "<STR_LIT>" . format ( len ( app_loaders ) , app_loaders ) ) <EOL> for loader in app_loaders : <EOL> if loader . can_load ( app_path ) : <EOL> log . info ( "<STR_LIT>" % loader . __class__ . __name__ ) <EOL> return loader . load_app ( absolute_path , wsgi_app_full_name ) <EOL> raise Exception ( "<STR_LIT>" % app_path ) <EOL> def import_object ( full_object_name ) : <EOL> '''<STR_LIT>''' <EOL> parts = full_object_name . strip ( ) . split ( '<STR_LIT:.>' ) <EOL> mod = '<STR_LIT:.>' . join ( parts [ : - <NUM_LIT:1> ] ) <EOL> obj_name = parts [ - <NUM_LIT:1> ] <EOL> imported = __import__ ( mod , fromlist = obj_name ) <EOL> return getattr ( imported , obj_name ) <EOL> class PyRoutesLoader ( Plugin ) : <EOL> implements = [ IAppLoader ] <EOL> def can_load ( self , app_path ) : <EOL> settings = os . path . join ( app_path , '<STR_LIT>' ) <EOL> return os . path . exists ( settings ) <EOL> def load_app ( self , app_path , app_full_name ) : <EOL> if app_full_name : <EOL> return import_object ( app_full_name ) <EOL> dirs = [ d for d in os . listdir ( app_path ) if os . path . isdir ( os . path . join ( app_path , d ) ) ] <EOL> app_dir = filter ( lambda d : d not in ( '<STR_LIT>' , '<STR_LIT>' ) , dirs ) <EOL> __import__ ( app_dir [ <NUM_LIT:0> ] ) <EOL> __import__ ( app_dir [ <NUM_LIT:0> ] , fromlist = '<STR_LIT>' ) <EOL> import pyroutes <EOL> return pyroutes . application <EOL> import djangoloader </s>
