[kupfer] browser: Force unicode in escape_markup_str



commit f0bbb07a3681dfe2084ca9b69ad3d9ee9c41bce0
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Oct 25 15:47:05 2009 +0100

    browser: Force unicode in escape_markup_str
    
    We have to ensure we always really pass unicode to our markup
    functions, everywhere, and the safest way for now is to force unicode in
    escape_markup_str.

 kupfer/browser.py |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/browser.py b/kupfer/browser.py
index 80d829b..1e2bc85 100644
--- a/kupfer/browser.py
+++ b/kupfer/browser.py
@@ -22,12 +22,18 @@ _escape_table = {
 		ord(u"<"): u"&lt;",
 		ord(u">"): u"&gt;",
 	}
+
+def tounicode(ustr):
+	if isinstance(ustr, unicode):
+		return ustr
+	return ustr.decode("UTF-8", "replace")
+
 def escape_markup_str(mstr):
 	"""
 	Use a simeple homegrown replace table to replace &, <, > with
 	entities in @mstr
 	"""
-	return mstr.translate(_escape_table)
+	return tounicode(mstr).translate(_escape_table)
 
 # State Constants
 class State (object):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]