Esempio n. 1
0
 def translate(self, lang, encoding = None, do_Q=False):
     if lang == 'en':
         return self.data
     res = self.get(lang)
     if isinstance(res, unicode):
         if encoding is None:
             import registry
             try:
                 encoding = registry.team(lang).charset
             except KeyError:
                 encoding = 'utf-8'
             if encoding is None:
                 encoding = 'iso-8859-1'
         try:
             res = res.encode(encoding)
         except (KeyError, UnicodeError):
             encoding="utf-8"
             res = res.encode('utf-8')
     if do_Q and encoding:
         # Do quoted printable encoding.
         from email.Charset import Charset
         charset = Charset(encoding)
         lines = res.split('\n')
         for i in range(len(lines)):
             l = lines[i]
             try:
                 l.decode("us-ascii")
             except UnicodeError:
                 pass
             else:
                 continue
             f,b = l.split(": ",1) # RFC822 field and body
             lines[i] = f+": "+charset.header_encode(b)
         res = "\n".join(lines)
     return res
Esempio n. 2
0
def produce_team_page(postats, name, output=None):
    TeamPage(postats, registry.team(name), output)