def locateChild(self, req, segs): name = segs[0] self.logicpath = '.'.join([self.logicpath,name]) self.viewpath = '.'.join([self.viewpath,name]) if name == '' and len(segs) == 1: return self, server.StopTraversal elif name not in self.view: try: self.view[name] = {'__val__':import_tmpl(self.viewpath)} self.view = self.view[name] try: if type(self.logic) is not type([]): self.logic[name] = {'__val__':import_mod(self.logicpath)} self.logic = self.logic[name] except: self.logic = [self.logic] except: return self, server.StopTraversal else: self.view = self.view[name] try: if type(self.logic) is not type([]): self.logic = self.logic[name] except: self.logic = self.logic return self, segs[1:]
def __init__(self, logic_mod, path, mode = 'http'): self.logic_mod = logic_mod self.path = path self.mode = mode if '__val__' not in view_tree: logic_tree['__val__'] = import_mod('.'.join([self.logic_mod,'index'])) view_tree['__val__'] = import_tmpl('index')
def locateChild(self, req, segs): if site_tree.get(req.host, None) is None: site_tree[req.host] = self.siteResource.filter(host__is = req.host).fetchone() settings = SiteSettings(site_tree[req.host], site_tree[self.defaultHost]) req.settings = settings for binding in middleware_bindings: binding(req) try: [self.mode, name] = segs[0].split('-') except: name = segs[0] if name == '' and len(segs) == 1: return self, server.StopTraversal if os.path.isfile(os.path.join(self.path, name)): return PervursHTTPStatic(self, os.path.join(self.path, name)), server.StopTraversal elif os.path.exists(os.path.join(self.path, name)): return PervursHTTPStatic(self, os.path.join(self.path, name)), segs[1:] else: logicpath = '.'.join([self.logic_mod,name]) if name not in view_tree: try: try: logic_tree[name] = {'__val__':import_mod(logicpath)} except: pass view_tree[name] = {'__val__':import_tmpl(name)} except: return self, server.StopTraversal return PervursHTTPView(self, name, view_tree[name], logicpath, logic_tree[name], self.mode), segs[1:]