def _fix_path(path): if type(path) is not str: raise TypeError, 'unexpected %s' % repr(path) path = normalize_path(path) if not path or path[0] != '/': raise ValueError, 'unexpected %s' % repr(path) return path if path[-1] == '/' else path + '/'
def get_template(self, web_path): web_path = normalize_path(web_path) # 1. Find local root web_roots = ui_registry.keys() web_roots.sort(reverse=True) for web_root in web_roots: if web_path.startswith(web_root): break else: raise ValueError, 'unexpected %s' % repr(web_path) # 2. Get the local path local_root = ui_registry[web_root] local_path = local_root + web_path[len(web_root):] # 3. Get the handler handler = ro_database.get_handler(local_path, soft=True) if handler: return handler # 4. Not an exact match: trigger language negotiation folder_path, name = local_path.rsplit('/', 1) name = name + '.' n = len(name) languages = [] for x in lfs.get_names(folder_path): if x[:n] == name: language = x[n:] if has_language(language): languages.append(language) if not languages: return None # 4.1 Get the best variant accept = self.accept_language language = accept.select_language(languages) # 4.2 By default use whatever variant # (XXX we need a way to define the default) if language is None: language = languages[0] local_path = '%s.%s' % (local_path, language) return ro_database.get_handler(local_path)
def get_template(self, web_path): warning = None web_path_object = Path(normalize_path(web_path)) skin_name = web_path_object[1] try: skin = skin_registry[skin_name] except KeyError: warning = 'WARNING: web_path {} is obsolete use /ui/ikaaro/' warning = warning.format(web_path) web_path = web_path.replace('/ui/', '/ui/ikaaro/') skin = skin_registry['ikaaro'] # 1) Try with envionment skin skin_key = skin.get_environment_key(self.server) web_path = web_path.replace(skin.base_path, '') template = self.get_template_from_skin_key(skin_key, web_path, warning) if template: return template # 2) Try with standard skin return self.get_template_from_skin_key(skin.key, web_path, warning)
def test_dot(self): """'.' -> ''""" self.assertEqual(normalize_path('.'), '')
def test4(self): """'/../a/b/c' -> 'a/b/c'""" self.assertEqual(normalize_path('/../a/b/c'), '/a/b/c')
def test3(self): """'a/b/c/../d' -> 'a/b/d'""" self.assertEqual(normalize_path('a/b/c/../d'), 'a/b/d')
def test2(self): """'a/./b/c' -> 'a/b/c'""" self.assertEqual(normalize_path('a/./b/c'), 'a/b/c')
def test1(self): """'a//b/c' -> 'a/b/c'""" self.assertEqual(normalize_path('a//b/c'), 'a/b/c')