From dacf82263d40a6ee1e24e99bf3fb3fdf12345638 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 1 Mar 2008 02:06:52 -0800 Subject: [PATCH] add a magic resource list that prevents duplicate mime-types from being added... probably should add more matching, but this is good for now... [git-p4: depot-paths = "//depot/": change = 1130] --- DIDLLite.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/DIDLLite.py b/DIDLLite.py index 2917e1c..eba33e1 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -32,6 +32,21 @@ class Resource: return root +class ResourceList(list): + '''Special class to not overwrite mimetypes that already exist.''' + def __init__(self, *args, **kwargs): + self._mt = {} + list.__init__(self, *args, **kwargs) + + def append(self, k): + assert isinstance(k, Resource) + mt = k.protocolInfo.split(':')[2] + if self._mt.has_key(mt): + return + + list.append(self, k) + self._mt[mt] = k + class Object(object): """The root class of the entire content directory class heirachy."""