Ejemplo n.º 1
0
    def decode(data):
        parts = data.rsplit('.', 1)
        # Case 1: name
        if len(parts) == 1:
            return data, None, None

        name, ext = parts
        # Case 2: name.encoding
        if has_encoding(ext):
            return name, ext, None

        if '.' in name:
            a, b = name.rsplit('.', 1)
            if has_extension(b) and has_language(ext):
                # Case 3: name.type.language
                return a, b, ext
        if has_extension(ext):
            # Case 4: name.type
            return name, ext, None
        elif has_language(ext):
            # Case 5: name.language
            return name, None, ext

        # Case 1: name
        return data, None, None
Ejemplo n.º 2
0
    def decode(data):
        parts = data.rsplit('.', 1)
        # Case 1: name
        if len(parts) == 1:
            return data, None, None

        name, ext = parts
        # Case 2: name.encoding
        if has_encoding(ext):
            return name, ext, None

        if '.' in name:
            a, b = name.rsplit('.', 1)
            if has_extension(b) and has_language(ext):
                # Case 3: name.type.language
                return a, b, ext
        if has_extension(ext):
            # Case 4: name.type
            return name, ext, None
        elif has_language(ext):
            # Case 5: name.language
            return name, None, ext

        # Case 1: name
        return data, None, None
Ejemplo n.º 3
0
    def get_template_from_skin_key(self, skin_key, web_path, warning):
        local_path = skin_key + web_path
        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            if warning:
                print warning
            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)
        # Print Warning
        if warning:
            print warning
        # 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)
Ejemplo n.º 4
0
    def get_template_from_skin_key(self, skin_key, web_path, warning):
        local_path = skin_key + web_path
        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            if warning:
                print warning
            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)
        # Print Warning
        if warning:
            print warning
        # 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, soft=True)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)