diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py
index ab8f2ba1d8a007e774823376f2be2f421568d229..26d611b2b8a654269cc753144e010161ad94fb6d 100644
--- a/src/gtkgui_helpers.py
+++ b/src/gtkgui_helpers.py
@@ -20,9 +20,17 @@
 ## GNU General Public License for more details.
 ##
 
-import cgi
+import xml.sax.saxutils
 
 def escape_for_pango_markup(string):
-	# escapes chars for pango markup not to break
-	if string is not None:
-		return cgi.escape(string)
+	# escapes < > & \ "
+	# for pango markup not to break
+	if string is None:
+		return
+	if gtk.pygtk_version >= (2, 8, 0) and gtk.gtk_version >= (2, 8, 0):
+		escaped_str = gobject.markup_escape_text(string)
+	else:
+		escaped_str =xml.sax.saxutils.escape(string, {'\\': '&apos;',
+			'"': '&quot;'})
+	
+	return escaped_str