def system_dispatch(self): import logging import drydrop.app as app import datetime from drydrop.lib.utils import import_module from drydrop.app.core.appceptions import PageException # match internal route self.mapper.environ = self.request.environ controller = self.mapper.match(self.request.path) if controller == None: return False logging.debug("System: dispatching %s to %s", self.request.path, controller) # find the controller class action = controller['action'] name = controller['controller'] mod = import_module('drydrop.app.controllers.%s' % name) klass = "%sController" % name.capitalize() controller_class = mod.__dict__[klass] # add the route information as request parameters for param, value in controller.iteritems(): self.request.GET[param] = value # instantiate controller controller_instance = controller_class(self.request, self.response, self) # get controller's methods before_method = controller_instance.__getattribute__('before_action') action_method = controller_instance.__getattribute__(action) after_method = controller_instance.__getattribute__('after_action') # see http://code.google.com/p/googleappengine/issues/detail?id=732 self.response.headers['Cache-Control'] = "no-cache" expires = datetime.datetime.today() + datetime.timedelta(0, -1) self.response.headers['Expires'] = expires.strftime( '%a, %d %b %Y %H:%M:%S GMT') # call action methods try: before_result = before_method() if before_result: return action_result = action_method() if action_result: return after_result = after_method() if after_result: return except PageException: pass
def system_dispatch(self): import logging import drydrop.app as app import datetime from drydrop.lib.utils import import_module from drydrop.app.core.appceptions import PageException # match internal route self.mapper.environ = self.request.environ controller = self.mapper.match(self.request.path) if controller == None: return False logging.debug("System: dispatching %s to %s", self.request.path, controller) # find the controller class action = controller['action'] name = controller['controller'] mod = import_module('drydrop.app.controllers.%s' % name) klass = "%sController" % name.capitalize() controller_class = mod.__dict__[klass] # add the route information as request parameters for param, value in controller.iteritems(): self.request.GET[param] = value # instantiate controller controller_instance = controller_class(self.request, self.response, self) # get controller's methods before_method = controller_instance.__getattribute__('before_action') action_method = controller_instance.__getattribute__(action) after_method = controller_instance.__getattribute__('after_action') # see http://code.google.com/p/googleappengine/issues/detail?id=732 self.response.headers['Cache-Control'] = "no-cache" expires = datetime.datetime.today() + datetime.timedelta(0, -1) self.response.headers['Expires'] = expires.strftime('%a, %d %b %Y %H:%M:%S GMT') # call action methods try: before_result = before_method() if before_result: return action_result = action_method() if action_result: return after_result = after_method() if after_result: return except PageException: pass
def import_submodules(path, destination, ancestor=None): # want to import all classes from all *.py in directory pointed by path and put them into destination module # optionaly also want to take only classes which are descendants of given ancestor # # classic path is in form: /here/is/some/project/dir/and/some/path/to/__init__.py # zip path is in form: something.zip/some/path/to/__init__.py # DRY_ROOT is path to project dir, where are located all zip files (it is not possible to extract this form zip path alone) # dir_path = os.path.dirname(path) m = re.match(r'^([^/]*?\.zip)/(.*)$', dir_path) if m: # zip case (we are on appspot.com) zipname = m.group(1) subpath = m.group(2) dot_module_path = subpath.replace('/', '.') module = zipname.split('.')[0] z = zipfile.ZipFile(os.path.join(APP_ROOT, zipname), 'r') for info in z.infolist(): f = info.filename r = re.compile('^'+subpath+'/([^/]*)\.py$') x = re.match(r, f) if x: module_name = x.group(1) if not module_name.startswith('__'): module_selector = "%s.%s" % (dot_module_path, module_name) module = import_module(module_selector) cherrypick_classes_into_module(module, destination, ancestor) else: # classic case (local development box) for dirpath, dirnames, filenames in os.walk(dir_path): modules = [f.split('.')[0] for f in filenames if f.endswith('.py') and not f.startswith('__')] for module_name in modules: dot_module_path = dir_path[len(APP_ROOT)+1:].replace('/', '.') module_selector = "%s.%s" % (dot_module_path, module_name) module = import_module(module_selector) cherrypick_classes_into_module(module, destination, ancestor)