]> oss.titaniummirror.com Git - oss-web.git/commitdiff
read_*, webber: fix loading of files with "Umlaut" characters
authorHolger Schurig <hs4233@mail.mn-solutions.de>
Thu, 25 Jun 2009 21:44:58 +0000 (23:44 +0200)
committerHolger Schurig <hs4233@mail.mn-solutions.de>
Thu, 25 Jun 2009 21:44:58 +0000 (23:44 +0200)
You cannot do some f.readline() actions and then read the rest via f.read(),
at least not not if the files aren't pure ASCII.

plugins/read_html.py
plugins/read_markdown.py
plugins/read_rst.py
webber.py

index 0ad6a8bc8cfeaee5d79d845ef75f3c7939d367b5..94ad6406e41821f9f86ea366db5cf3ea11faaacd 100644 (file)
@@ -7,8 +7,7 @@ def read(params):
        file = params.file
        if file.rel_path.endswith(".html"):
                file.render = "html"
-               f = file.read_keywords()
-               return f.read()
+               file.read()
 
 
 @set_hook("htmlize")
index 65f8c061489ec01356367473aa43c1189cc3da8f..06ed2adcaeafa92db18d91cfe241158a335ba67e 100644 (file)
@@ -1580,8 +1580,7 @@ def read(params):
        file = params.file
        if file.rel_path.endswith(".md"):
                file.render = "html"
-               f = file.read_keywords()
-               return f.read()
+               file.read()
 
 
 _markdown = None
index e8e3a36523862604eb4129fe9fcfe60e1fd9dd4d..a9968ac4b2def57772ed81f337fdfb0452e7da23 100644 (file)
@@ -9,9 +9,7 @@ def read(params):
        file = params.file
        if file.rel_path.endswith(".rst"):
                file.render = "html"
-               f = file.read_keywords()
-               return f.read()
-
+               file.read()
 
 
 class WebHTMLTranslator(html4css1.HTMLTranslator):
index db3ea7e3af444fdf20d1e5baef8a7d6a677bdb68..194ce5cf3e93e4667f7f79245842948a19d2d6e4 100644 (file)
--- a/webber.py
+++ b/webber.py
@@ -1,5 +1,5 @@
 # -*- coding: iso-8859-1 -*-
-import sys, os, optparse, fnmatch, stat, re, time, types
+import sys, os, optparse, fnmatch, stat, re, time, codecs
 from config import Holder
 
 
@@ -69,36 +69,45 @@ class File(Holder):
                #print self.keys()
 
        reKeywords = re.compile(r'(\S+)\s*:\s*(.*)')
-       #reIsoDate = re.compile(r'(\d\d\d\d)-(\d\d)-(\d\d)')
-
-       def read_keywords(self, terminate_line=""):
-               """Opens the file and reads "key: value" pairs on the top of it. Returns
-               the open file handle for further processing by some plugins/read_*.py code."""
-               f = open(self.path)
-               while True:
-                       s = f.readline().strip()
-                       if s==terminate_line:
-                               break
-                       m = self.reKeywords.match(s)
-                       if not m:
-                               warning("%s: wrong 'key: value' line '%s'" % (self.rel_path, s))
-                               break
-                       key = m.group(1).lower()
-                       val = m.group(2)
-
-                       if key == "mtime":
-                               val = iso_to_time(val)
-
-                       if key == "ctime":
-                               val = iso_to_time(val)
-
-                       if key == "title":
-                               if not self.has_key("linktitle"):
-                                       self["linktitle"] = val
-
-                       #print self.rel_path, key, val
-                       self[key] = val
-               return f
+
+       def read(self, terminate_line=""):
+               f = codecs.open(self.path, "r", self.input_encoding)
+
+               # Read keywords
+               read_keywords = True
+               txt = []
+               for s in f.readlines():
+                       if read_keywords:
+                               s = s.strip()
+                               #print "kwd:", s
+                               if s==terminate_line:
+                                       read_keywords = False
+                                       continue
+
+                               m = self.reKeywords.match(s)
+                               if not m:
+                                       warning("%s: wrong 'key: value' line '%s'" % (self.rel_path, s))
+                                       break
+                               key = m.group(1).lower()
+                               val = m.group(2)
+
+                               if key == "mtime":
+                                       val = iso_to_time(val)
+
+                               if key == "ctime":
+                                       val = iso_to_time(val)
+
+                               if key == "title":
+                                       if not self.has_key("linktitle"):
+                                               self["linktitle"] = val
+
+                               #print self.rel_path, key, val
+                               self[key] = val
+
+                               continue
+                       #print "txt:", s.rstrip().encode("iso-8859-1")
+                       txt.append(s)
+               self.contents = "".join(txt)
 
 
 _get_file_for_cache = {}
@@ -567,7 +576,7 @@ def run_macros(file, contents):
                        kw["file"] = file
                        f = macros[name]
                        s = f(kw)
-                       if type(s) == types.UnicodeType:
+                       if isinstance(s, unicode):
                                s = s.encode("utf-8")
                        return s
                else: