lib/tree_parse.py
changeset 21 b05979822dee
parent 17 b538e1f7011c
--- a/lib/tree_parse.py	Sat Feb 07 03:35:37 2009 +0200
+++ b/lib/tree_parse.py	Sat Feb 07 04:37:28 2009 +0200
@@ -12,7 +12,7 @@
 
     pass
 
-def _read_lines (path, stop_tokens='') :
+def _read_lines (path, stop_tokens, charset) :
     """
         Reads lines from the given path, ignoring empty lines, and yielding (line_number, indent, line) tuples, where 
         line_number is the line number, indent counts the amount of leading whitespace, and line is the actual line
@@ -23,6 +23,9 @@
     """
 
     for line_number, line in enumerate(open(path, 'rb')) :
+        # decode to unicode
+        line = line.decode(charset)
+
         indent = 0
 
         # count indent
@@ -52,7 +55,7 @@
         # yield
         yield line_number + 1, indent, line
 
-def parse (path, stop_tokens='') :
+def parse (path, stop_tokens='', charset='utf8') :
     """
         Reads and parses the file at the given path, returning a list of (line_number, line, children) tuples.
     """
@@ -67,7 +70,7 @@
     prev = None
     
     # read lines
-    for line_number, indent, line in _read_lines(path, stop_tokens) :
+    for line_number, indent, line in _read_lines(path, stop_tokens, charset) :
         # create item
         item = (line_number, line, [])