Esempio n. 1
0
 def update_params(self, d):
     accept_language = parse_http_accept_header(            
         request.headers.get("Accept-Language")
     ) or ['']
     accept_charset = parse_http_accept_header(
         request.headers.get("Accept-Charset")
     ) or ['']
     base_dir = config.get("static_filter.dir", 
                           path="/tg_widgets/%s" % self.mod)
     def find_link():
         for name_pattern in self.name:
             for lang in accept_language:
                 for charset in accept_charset:
                     params = dict()
                     params["lang"] = lang
                     params["charset"] = charset
                     params["gettext_lang"] = lang_in_gettext_format(lang)
                     params["gettext_charset"] = charset.upper()
                     params["custom_lang"] = self.custom_lang(lang)
                     params["custom_charset"] = self.custom_charset(charset)
                     name = name_pattern % params
                     if os.path.exists(base_dir + '/' + name):
                         link = "/%stg_widgets/%s/%s" % (startup.webpath,
                                                         self.mod,
                                                         name)
                         return link
     d["link"] = find_link()
Esempio n. 2
0
def get_accept_languages(accept):
    """Returns a list of languages, by order of preference, based on an
    HTTP Accept-Language string.See W3C RFC 2616
    (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) for specification.
    """
    langs = parse_http_accept_header(accept)
    for index, lang in enumerate(langs):
        langs[index] = lang_in_gettext_format(lang)
    return langs
Esempio n. 3
0
def get_accept_languages(accept):
    """Returns a list of languages, by order of preference, based on an
    HTTP Accept-Language string.See W3C RFC 2616
    (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) for specification.
    """
    langs = parse_http_accept_header(accept)
    for index, lang in enumerate(langs):
        langs[index] = lang_in_gettext_format(lang)
    return langs
Esempio n. 4
0
    def update_params(self, d):
        languages = parse_http_accept_header(
            request.headers.get("Accept-Language")) or []
        language = d.get('language')
        if language and language != '*':
            languages.insert(0, language)
        languages = map(norm_tag, languages)
        default_language = norm_tag(self.default_language)
        languages.append(default_language)
        charsets = parse_http_accept_header(
            request.headers.get("Accept-Charset")) or []
        charsets = map(norm_charset, charsets)
        default_charset = norm_charset(self.default_charset)
        charset = norm_charset(config.get("kid.encoding"))
        if charset and charset != default_charset:
            charsets.append(charset)
        charsets.append(default_charset)
        path = "/tg_widgets/%s" % self.mod
        base_dir = config.get("static_filter.dir", path=path)
        base_name = "calendar/lang/calendar-"

        def find_link():
            params = dict()
            for lang in languages:
                if not lang or lang == '*':
                    lang = default_language
                base_lang = base_name + lang.replace('-', '_')
                for charset in charsets:
                    if not charset or charset == '*':
                        charset = default_charset
                    file_name = base_lang
                    if charset != default_charset:
                        file_name += '-' + charset.replace('-', '_')
                    file_name += '.js'
                    if os.path.exists(os.path.join(base_dir, file_name)):
                        path = "/%stg_widgets/%s" % (startup.webpath, self.mod)
                        link = "%s/%s" % (path, file_name)
                        return (link, language, charset)
                    if charset == default_charset:
                        break

        d["link"], d['language'], d['charset'] = find_link()
Esempio n. 5
0
 def update_params(self, d):
     languages = parse_http_accept_header(
         request.headers.get("Accept-Language")) or []
     language = d.get('language')
     if language and language != '*':
         languages.insert(0, language)
     languages = map(norm_tag, languages)
     default_language = norm_tag(self.default_language)
     languages.append(default_language)
     charsets = parse_http_accept_header(
         request.headers.get("Accept-Charset")) or []
     charsets = map(norm_charset, charsets)
     default_charset = norm_charset(self.default_charset)
     charset = norm_charset(config.get("kid.encoding"))
     if charset and charset != default_charset:
         charsets.append(charset)
     charsets.append(default_charset)
     path = "/tg_widgets/%s" % self.mod
     base_dir = config.get("static_filter.dir", path=path)
     base_name = "calendar/lang/calendar-"
     def find_link():
         params = dict()
         for lang in languages:
             if not lang or lang == '*':
                 lang = default_language
             base_lang = base_name + lang.replace('-', '_')
             for charset in charsets:
                 if not charset or charset == '*':
                     charset = default_charset
                 file_name = base_lang
                 if charset != default_charset:
                     file_name += '-' + charset.replace('-', '_')
                 file_name += '.js'
                 if os.path.exists(os.path.join(base_dir, file_name)):
                     path = "/%stg_widgets/%s" % (startup.webpath, self.mod)
                     link = "%s/%s" % (path, file_name)
                     return (link, language, charset)
                 if charset == default_charset:
                     break
     d["link"], d['language'], d['charset'] = find_link()