Author: dmeyer
Date: Sat Oct 20 05:29:39 2007
New Revision: 2879

Log:
support default paramater for item.get

Modified:
   trunk/beacon/src/item.py
   trunk/beacon/src/media.py

Modified: trunk/beacon/src/item.py
==============================================================================
--- trunk/beacon/src/item.py    (original)
+++ trunk/beacon/src/item.py    Sat Oct 20 05:29:39 2007
@@ -86,7 +86,7 @@
     # Public API
     # -------------------------------------------------------------------------
 
-    def get(self, key):
+    def get(self, key, default=None):
         """
         Interface to kaa.beacon. Return the value of a given attribute. If
         the attribute is not in the db, return None. If the key starts with
@@ -94,7 +94,7 @@
         the db. Loosing the item object will remove that attribute.
         """
         if key.startswith('tmp:'):
-            return self._beacon_tmpdata.get(key[4:])
+            return self._beacon_tmpdata.get(key[4:], default)
 
         if key == 'parent':
             return self._beacon_parent
@@ -105,7 +105,7 @@
         if key == 'read_only':
             # FIXME: this is not correct, a directory can also be
             # read only on a rw filesystem.
-            return self._beacon_media.get('volume.read_only')
+            return self._beacon_media.get('volume.read_only', default)
 
         if key in ('image', 'thumbnail'):
             image = self._beacon_data.get('image')
@@ -115,7 +115,7 @@
                     # up to date. Well, we have to live with that for now.
                     image = self._beacon_parent.get('image')
                 if not image:
-                    return None
+                    return default
             if key == 'image':
                 return image
 
@@ -132,7 +132,10 @@
             self._beacon_data['title'] = t
             return t
 
-        return self._beacon_data.get(key)
+        result = self._beacon_data.get(key, default)
+        if result is None:
+            return default
+        return result
 
 
     def __getitem__(self, key):

Modified: trunk/beacon/src/media.py
==============================================================================
--- trunk/beacon/src/media.py   (original)
+++ trunk/beacon/src/media.py   Sat Oct 20 05:29:39 2007
@@ -115,11 +115,11 @@
             self.label = self.id
 
 
-    def get(self, key):
+    def get(self, key, default=None):
         """
         Get value.
         """
-        return self.prop.get(key)
+        return self.prop.get(key, default)
 
 
     def __getitem__(self, key):

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to