From c4eb909ecd881993eb2739e5a742778f49a96f4e Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 7 Apr 2008 20:39:15 -0800 Subject: [PATCH] fix some typos... fix getattr by checking the set attributes... [git-p4: depot-paths = "//depot/": change = 1150] --- DIDLLite.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/DIDLLite.py b/DIDLLite.py index e52012c..7aae18d 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -13,23 +13,23 @@ class Resource(object): """An object representing a resource.""" validattrs = { - 'protocolinfo' 'protocolInfo', - 'importuri' 'importUri', - 'size' 'size', - 'duration' 'duration', - 'prtection' 'protection, - 'bitrate' 'bitrate', + 'protocolinfo': 'protocolInfo', + 'importuri': 'importUri', + 'size': 'size', + 'duration': 'duration', + 'protection': 'protection', + 'bitrate': 'bitrate', 'bitspersample': 'bitsPerSample', 'samplefrequency': 'sampleFrequence', 'nraudiochannels': 'nrAudioChannels', - 'resolution' 'resolution', - 'colordepth' 'colorDepth', - 'tspec' 'tspec', - 'alloweduse' 'allowedUse', + 'resolution': 'resolution', + 'colordepth': 'colorDepth', + 'tspec': 'tspec', + 'alloweduse': 'allowedUse', 'validitystart': 'validityStart', - 'validityend' 'validityEnd', + 'validityend': 'validityEnd', 'remainingtime': 'remainingTime', - 'usageinfo' 'usageInfo', + 'usageinfo': 'usageInfo', 'rightsinfouri': 'rightsInfoURI', 'contentinfouri': 'contentInfoURI', 'recordquality': 'recordQuality', @@ -44,16 +44,23 @@ class Resource(object): self.protocolInfo = protocolInfo + def __getattr__(self, key): + try: + return self.attrs[key.lower()] + except KeyError: + raise AttributeError, key + def __setattr__(self, key, value): - key = key.tolower() - self.attrs[self.validattrs[key]] = value + key = key.lower() + assert key in self.validattrs + self.attrs[key] = value def toElement(self): root = Element('res') root.text = self.data for i in self.attrs: - root.attrib[i] = str(self.attrs[i]) + root.attrib[self.validattrs[i]] = str(self.attrs[i]) return root