Details

Applies to
MoinMoin/request.py
Purpose
Allows non UTF-8 content
Description

Allows MoinMoin to generate non UTF-8 content, by adding a per-request content_charset attribute (which default to config.charset, i.e. to UTF-8). This is usefull for writing formatters that generate binary files, like image or probably PDF. In such a formatter, just add e.g. request.content_charset = 'iso-8859-1' to encode the fomatted page in ISO-LATIN-1 instead of UTF-8

Patch

   1 diff -ru /home/jiba/téléchargements/moin-1.5.1/MoinMoin/request.py ./MoinMoin/request.py
   2 --- /home/jiba/téléchargements/moin-1.5.1/MoinMoin/request.py   2006-01-21 21:02:08.000000000 +0100
   3 +++ ./MoinMoin/request.py       2006-02-04 12:57:47.000000000 +0100
   4 @@ -77,7 +77,9 @@
   5      def __init__(self, properties={}):
   6          # Decode values collected by sub classes
   7          self.path_info = self.decodePagename(self.path_info)
   8 -
   9 +        
  10 +        self.content_charset = config.charset
  11 +        
  12          self.failed = 0
  13          self._available_actions = None
  14          self._known_actions = None
  15 @@ -670,7 +672,7 @@
  16              try:
  17                  if isinstance(d, unicode):
  18                      # if we are REALLY sure, we can use "strict"
  19 -                    d = d.encode(config.charset, 'replace') 
  20 +                    d = d.encode(self.content_charset, 'replace') 
  21                  wd.append(d)
  22              except UnicodeError:
  23                  print >>sys.stderr, "Unicode error on: %s" % repr(d)
  24 @@ -1389,7 +1391,7 @@
  25              self.write("%s\r\n" % header)
  26  
  27          if not have_ct:
  28 -            self.write("Content-type: text/html;charset=%s\r\n" % config.charset)
  29 +            self.write("Content-type: text/html;charset=%s\r\n" % self.content_charset)
  30  
  31          self.write('\r\n')
  32  
  33 @@ -1523,7 +1525,7 @@
  34              self.__setHttpHeader(header)
  35  
  36          if not have_ct:
  37 -            self.__setHttpHeader("Content-type: text/html;charset=%s" % config.charset)
  38 +            self.__setHttpHeader("Content-type: text/html;charset=%s" % self.content_charset)
  39  
  40      def http_redirect(self, url):
  41          """ Redirect to a fully qualified, or server-rooted URL 
  42 @@ -1758,7 +1760,7 @@
  43              self.write("%s\r\n" % header)
  44  
  45          if not have_ct:
  46 -            self.write("Content-type: text/html;charset=%s\r\n" % config.charset)
  47 +            self.write("Content-type: text/html;charset=%s\r\n" % self.content_charset)
  48  
  49          self.write('\r\n')
  50  
  51 @@ -1939,7 +1941,7 @@
  52              self.setHttpHeader(header)
  53          # if we don't had an content-type header, set text/html
  54          if self._have_ct == 0:
  55 -            self.mpyreq.content_type = "text/html;charset=%s" % config.charset
  56 +            self.mpyreq.content_type = "text/html;charset=%s" % self.content_charset
  57          # if we don't had a status header, set 200
  58          if self._have_status == 0:
  59              self.mpyreq.status = 200
  60 @@ -2021,7 +2023,7 @@
  61              self.write("%s\r\n" % header)
  62  
  63          if not have_ct:
  64 -            self.write("Content-type: text/html;charset=%s\r\n" % config.charset)
  65 +            self.write("Content-type: text/html;charset=%s\r\n" % self.content_charset)
  66  
  67          self.write('\r\n')
  68  
  69 @@ -2092,7 +2094,7 @@
  70              self.setHttpHeader(header)
  71          
  72          if not self.hasContentType:
  73 -            self.headers.insert(0, ('Content-Type', 'text/html;charset=%s' % config.charset))
  74 +            self.headers.insert(0, ('Content-Type', 'text/html;charset=%s' % self.content_charset))
  75      
  76      def flush(self):
  77          pass

support_different_charset.patch

Discussion

Please give a concrete full code example where you use that.

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/SupportDifferentCharset (last edited 2007-10-29 19:08:10 by localhost)