From 5bb02a8fbbebc1e9f0ff6ad543c46afe4ce4b143 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 13 Nov 2012 17:02:32 +0100 Subject: [PATCH] Update xdg-menu to work with latest pyxdg (#874633) --- xdg-menu | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/xdg-menu b/xdg-menu index aefc6a4..8eef84e 100644 --- a/xdg-menu +++ b/xdg-menu @@ -53,7 +53,9 @@ def icon_attr(entry): return '' def escape_utf8(s): - return escape(s.encode('utf-8', 'xmlcharrefreplace')) + if isinstance(s, unicode): + s = s.encode('utf-8', 'xmlcharrefreplace') + return escape(s) def entry_name(entry): return escape_utf8(entry.getName()) @@ -67,14 +69,15 @@ def walk_menu(entry): map(walk_menu, entry.getEntries()) print '' elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True: - print ' ' % \ - (entry_name(entry.DesktopEntry).replace('"', ''), + name = entry_name(entry.DesktopEntry) + print ' ' % (name.replace('"', ''), escape_utf8(icon_attr(entry.DesktopEntry))) - command = re.sub(' -caption "%c"| -caption %c', ' -caption "%s"' % entry_name(entry.DesktopEntry), entry.DesktopEntry.getExec()) + command = re.sub(' -caption "%c"| -caption %c', + ' -caption "%s"' % name, + escape_utf8(entry.DesktopEntry.getExec())) command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command) if entry.DesktopEntry.getTerminal(): - command = 'xterm -title "%s" -e %s' % \ - (entry_name(entry.DesktopEntry), command) + command = 'xterm -title "%s" -e %s' % (name, command) print ' ' + \ '%s' % command print ' '