[kupfer] rhythmbox: Force certain keys to be unicode
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] rhythmbox: Force certain keys to be unicode
- Date: Sat, 23 Jan 2010 12:18:31 +0000 (UTC)
commit 140cf8b283cad917c1617f8360d215b2fa8cab75
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Jan 22 02:29:05 2010 +0100
rhythmbox: Force certain keys to be unicode
Since these keys have to be unicode later anyway (as leaf names), we
force them to be unicode already early, so that the unicode objects
are always the same ones.
kupfer/plugin/rhythmbox_support.py | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/plugin/rhythmbox_support.py b/kupfer/plugin/rhythmbox_support.py
index 44690c4..0b993ce 100644
--- a/kupfer/plugin/rhythmbox_support.py
+++ b/kupfer/plugin/rhythmbox_support.py
@@ -3,6 +3,14 @@ import os
import xml.etree.cElementTree as ElementTree
NEEDED_KEYS= set(("title", "artist", "album", "track-number", "location", ))
+UNICODE_KEYS = set(("title", "artist", "album"))
+
+def _tounicode(bstr):
+ # the XML parser returns `str' only when it's ascii, but we want
+ # unicode objects all the time
+ if isinstance(bstr, unicode):
+ return bstr
+ return bstr.decode("ascii")
def _lookup_string(string, strmap):
"""Look up @string in the string map,
@@ -36,8 +44,12 @@ def get_rhythmbox_songs(dbfile, typ="song", keys=NEEDED_KEYS):
info = {}
for child in entry.getchildren():
if child.tag in keys:
+ if child.tag in UNICODE_KEYS:
+ childtext = _tounicode(child.text)
+ else:
+ childtext = child.text
tag = _lookup_string(child.tag, strmap)
- text = _lookup_string(child.text, strmap)
+ text = _lookup_string(childtext, strmap)
info[tag] = text
lSongs.append(info)
entry.clear()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]