python3-xmmsclient doesn't handle map objects correctly

Bug #1999291 reported by Kevin Pulo
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
xmms2 (Ubuntu)
New
Undecided
Unassigned

Bug Description

The PropDict class (which inherits from dict) assumes that the given "srcs" are a list. However, these srcs are created using map(), which in python2 returned a list, but in python3 returns a map object. This wouldn't be too bad, except unfortunately, the func in the map isn't idempotent, which means that iterating self._sources multiple times leads to bizarre results, ie. the key is found the first time, but not subsequent times. This breaks clients that happen to look up multiple keys (or keys multiple times).

Since the list of sources is always small (AFAIK), the simplest solution is to just materialise it back into being a list at init time:

--- a/propdict.py.orig
+++ b/propdict.py
@@ -8,7 +8,9 @@ except NameError:
 class PropDict(dict):
     def __init__(self, srcs):
         dict.__init__(self)
- self._sources = srcs
+ self._sources = list(srcs)
+ if len(self._sources) == 0:
+ self._sources = ['*']

     def set_source_preference(self, sources):
         """
@@ -54,6 +56,9 @@ class PropDict(dict):
     def _set_sources(self, val):
         if isinstance(val, basestring):
             raise TypeError("Need a sequence of sources")
+ val = list(val)
+ if len(val) == 0:
+ val = ['*']
         for i in val:
             if not isinstance(i, basestring):
                 raise TypeError("Sources need to be strings")

Tags: patch
Revision history for this message
Kevin Pulo (devkev) wrote :
Revision history for this message
Kevin Pulo (devkev) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "propdict.py.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.